在我的Spock功能测试中,我想测试浏览器的当前位置不是某个网址。我知道我能做到:
try {
at(PageWithUrlIDontWant)
// do something
} catch (AssertionError) {
// pass because this is the common branch
}
但是,这是使用异常来控制分支。除at
之外,还有办法检查浏览器的网址是什么吗?我尝试了page.pageUrl
和browser.pageUrl
,但它们都是空的。
答案 0 :(得分:2)
从Geb 0.7.0开始,类isAt()
上有一个新的Browser
方法。 GebSpec
proxies methodMissing调用它的Browser
实例,因此您的测试中可以使用此方法。
示例:
def "navigating to GoodPage doesn't up at BadPage"() {
when:
to GoodPage
then:
!isAt(BadPage)
}