2013-03-19 105 views
1

在我的Spock功能測試中,我想測試瀏覽器的當前位置不是特定的url。我知道我可以這樣做:檢查Geb/Spock測試中的網址

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

但是,這是使用異常來控制分支。除at之外,有沒有辦法檢查瀏覽器的網址?我試過page.pageUrlbrowser.pageUrl,但它們都是空的。

+0

使用ISAT似乎給了我一個WaitTimeoutException whwen它不是在頁面... – 2013-03-20 15:03:41

+0

更新評論:我相信WaitTimeoutException正在發生的事情,因爲我的一個在檢查器檢查在頁面上找不到的元素。 – 2013-03-20 17:30:27

回答

2

從Geb 0.7.0開始,類Browser上有一個新的isAt()方法。 GebSpec proxies methodMissing調用它的Browser實例,所以此方法在您的測試中可用。此方法返回true/false而不是拋出異常,應該暴露。

例子:

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

    then: 
    !isAt(BadPage) 
}