【问题标题】:Switching use of page objects in test - Geb Groovy Spock在测试中切换页面对象的使用 - Geb Groovy Spock
【发布时间】:2017-10-23 13:00:43
【问题描述】:

我正在编写使用 Spock、Groovy 和 Geb 实现页面对象模式的 UI 功能测试。在我离开当前页面以获得结果的事件流中,我需要在我的测试中切换页面对象,但未能成功

下面的测试用例:

    def "Navigate to Second Page"() {
    when: "I navigate to second page"

    redirctButton.click()

    then: "Second Page Url should show"
    browser.getCurrentUrl() == secondpageUrl
}

def "Use method form second page"() {
    when: "Im on second page"
    SecondPage.performSearch("search")

    then: "result should show"
    SecondPage.resultBox == ""
}

【问题讨论】:

    标签: user-interface groovy spock functional-testing geb


    【解决方案1】:

    您应该为您的页面对象添加at-checking,然后您可以使用at 方法来验证您是否在预期的页面上,从而使browser.getCurrentUrl() == secondpageUrl 过时。 at-check 的另一个效果是它改变了当前页面并且还返回页面对象以进行强类型访问。如果您不关心强类型访问,您可以在第二个测试中删除 expect 块,它只是为了让您可以访问类型页面对象。

    
    @Stepwise
    class PageTest extends GebReportingSpec {
    
    def "Navigate to Second Page"() {
        when: "I navigate to second page"
        redirctButton.click()
    
        then: "Second Page Url should show"
        at SecondPage
    }
    
    def "Use method form second page"() {
        expect:
        def secondPage = at SecondPage
    
        when: "Im on second page"
        secondPage.performSearch("search")
    
        then: "result should show"
        secondPage.resultBox == ""
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多