Question

I'm using geb with spock as my acceptance test framework. Everything is going great except that there is an issue with a couple of tests where when it redirects to another website we are prompted to enter a username and password to access the site. Because this is a browser prompt rather than a form I can submit, is there any way you can set this either automatically on the browser profile for the site or set it on the driver?

I'm testing with firefox as the browser type.

Edit: here's my build.gradle file

apply plugin: 'eclipse'
apply plugin: 'groovy'
apply plugin: 'idea'

repositories {
    mavenCentral()
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.3'
}

// The drivers we want to use
ext.drivers = ["firefox"]

dependencies {
    groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.6'

    def gebVersion = "0.7.2"
    def seleniumVersion = "2.26.0"

    // If using Spock, need to depend on geb-spock
    testCompile "org.codehaus.geb:geb-spock:$gebVersion"
    testCompile "org.spockframework:spock-core:0.6-groovy-1.8"

// Drivers
    drivers.each { driver ->
        testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$seleniumVersion"
    }
}

drivers.each { driver ->
    task "${driver}Test"(type: Test) {
        testReportDir = reporting.file("$name/tests")
        testResultsDir = file("$buildDir/test-results/$name")

        systemProperty "geb.build.reportsDir", reporting.file("$name/geb")
        systemProperty "geb.env", driver
        // If you wanted to set the baseUrl in your build…
        // systemProperty "geb.build.baseUrl", "http://myapp.com"
    }
}

task test(overwrite: true, dependsOn: drivers.collect { tasks["${it}Test"] })
Was it helpful?

Solution 2

In order to fix this problem I ended up using a browser profile in Firefox and installing a plugin that would automatically fill in prompts. Then in the Geb Acceptance tests you set it up so that it automatically uses Firefox with the right profile.

OTHER TIPS

I have no idea if thit will work, as changlog for 2.25.0 mentions that it's not implemented for any driver yet, but there is a way to switch to an alert using WebDriver and then use the authenticateUsing(Credentials) method.

In your Spock specification you could try the following:

driver.switchTo().alert().authenticateUsing(new UserAndPassword('user', 'pass'))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top