检查Geb / Spock测试中的URL

时间:2013-03-19 22:46:07

标签: groovy spock geb

在我的Spock功能测试中,我想测试浏览器的当前位置不是某个网址。我知道我能做到:

try {
    at(PageWithUrlIDontWant)
    // do something
} catch (AssertionError) {
    // pass because this is the common branch
}

但是,这是使用异常来控制分支。除at之外,还有办法检查浏览器的网址是什么吗?我尝试了page.pageUrlbrowser.pageUrl,但它们都是空的。

1 个答案:

答案 0 :(得分:2)

从Geb 0.7.0开始,类isAt()上有一个新的Browser方法。 GebSpec proxies methodMissing调用它的Browser实例,因此您的测试中可以使用此方法。

此方法返回true / false而不是抛出异常

示例:

def "navigating to GoodPage doesn't up at BadPage"() {
    when:
    to GoodPage

    then:
    !isAt(BadPage)
}