【问题标题】:Geb how to auto populate username/password promptsGeb 如何自动填充用户名/密码提示
【发布时间】:2013-02-15 08:44:10
【问题描述】:

我使用带有 spock 的 geb 作为我的验收测试框架。一切都很好,除了一些测试存在问题,当它重定向到另一个网站时,我们被提示输入用户名和密码才能访问该网站。因为这是浏览器提示而不是我可以提交的表单,有什么方法可以在网站的浏览器配置文件中自动设置或在驱动程序中设置?

我正在使用 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"] })

【问题讨论】:

    标签: firefox selenium acceptance-testing spock geb


    【解决方案1】:

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

    在您的 Spock 规范中,您可以尝试以下操作:

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

    【讨论】:

    • 谢谢erdi,我试试看。我发现一篇文章提到您可以使用随配置文件安装的 AutoAuth 插件。请参阅:watirmelon.com/2012/06/27/… 虽然我不会使用 Watir(因为它是一个 Ruby 库),但我可能可以尝试与 spock 安装等效的东西,因为它使用的是 Selenium 驱动程序。此外,我们现在只关心在单个浏览器 (Firefox) 中进行测试,所以这个解决方案就足够了。我会回到这里,看看我们用来解决这个问题的解决方案。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2010-11-29
      • 2014-12-07
      • 2011-08-08
      • 2016-05-10
      • 2011-12-16
      • 2018-05-14
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      相关资源
      最近更新 更多