Firefox Geb如何自动填充用户名/密码提示

Firefox Geb如何自动填充用户名/密码提示,firefox,selenium,acceptance-testing,spock,geb,Firefox,Selenium,Acceptance Testing,Spock,Geb,我使用geb和spock作为验收测试框架。一切都进行得很顺利,除了有一个问题与一对夫妇的测试,当它重定向到另一个网站,我们会提示输入用户名和密码来访问该网站。因为这是一个浏览器提示,而不是我可以提交的表单,您是否可以在网站的浏览器配置文件中自动设置此提示,或者在驱动程序中设置此提示 我正在使用firefox作为浏览器类型进行测试 编辑:这是我的build.gradle文件 apply plugin: 'eclipse' apply plugin: 'groovy' apply plugin: '

我使用geb和spock作为验收测试框架。一切都进行得很顺利,除了有一个问题与一对夫妇的测试,当它重定向到另一个网站,我们会提示输入用户名和密码来访问该网站。因为这是一个浏览器提示,而不是我可以提交的表单,您是否可以在网站的浏览器配置文件中自动设置此提示,或者在驱动程序中设置此提示

我正在使用firefox作为浏览器类型进行测试

编辑:这是我的build.gradle文件

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"] })

我不知道这是否有效,因为changlog for 2.25.0提到它还没有为任何驱动程序实现,但有一种方法可以使用WebDriver切换到警报,然后使用该方法

在您的Spock规范中,您可以尝试以下方法:

driver.switchTo().alert().authenticateUsing(new UserAndPassword('user', 'pass'))

为了解决这个问题,我在Firefox中使用了一个浏览器配置文件,并安装了一个插件,可以自动填充提示。然后在Geb验收测试中,您将其设置为自动使用具有正确配置文件的Firefox。

谢谢erdi,我将尝试一下。我发现一篇文章提到可以使用配置文件中安装的AutoAuth插件。请看:虽然我不会使用Watir(因为它是一个Ruby库),但我可能会尝试与spock安装等效的东西,因为它使用的是Selenium驱动程序。此外,我们现在只关心在单个浏览器(Firefox)中进行测试,所以这个解决方案已经足够了。我会回到这里,我们用哪个解决方案来解决这个问题。