Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 在测试中切换页面对象的使用-Geb Groovy Spock_User Interface_Groovy_Spock_Functional Testing_Geb - Fatal编程技术网

User interface 在测试中切换页面对象的使用-Geb Groovy Spock

User interface 在测试中切换页面对象的使用-Geb Groovy Spock,user-interface,groovy,spock,functional-testing,geb,User Interface,Groovy,Spock,Functional Testing,Geb,我正在用Spock、Groovy和Geb实现页面对象模式来编写UI功能测试。在我的事件流中,我导航离开当前页面以获得结果,因此,我需要在测试中切换页面对象,但未能成功切换 测试用例如下: def "Navigate to Second Page"() { when: "I navigate to second page" redirctButton.click() then: "Second Page Url should show" browser.

我正在用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 == ""
}
您应该为页面对象添加,然后可以使用
at
方法验证您是否在预期页面上,从而使
browser.getCurrentUrl()==secondpageUrl
过时。
at
-检查的另一个效果是它更改当前页面,并返回用于强类型访问的页面对象。如果您不关心强类型访问,那么可以在第二个测试中删除
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 == ""
}
}