User interface 在测试中切换页面对象的使用-Geb Groovy Spock
我正在用Spock、Groovy和Geb实现页面对象模式来编写UI功能测试。在我的事件流中,我导航离开当前页面以获得结果,因此,我需要在测试中切换页面对象,但未能成功切换 测试用例如下: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.
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 == ""
}
}