1
我正在嘗試使用Grails編寫一個簡單的Geb/Spock測試,但我收到以下測試失敗。Geb'at null'斷言頁面
| Failure: login works correctly(...UserAuthAcceptanceSpec)
| Condition not satisfied:
at HomePage
|
null
我可以通過使用調試器使用瀏覽器按照測試可以看到,應用程序運行正常,並正在顯示正確的航向。但是,當我嘗試調用at
檢查器時,測試失敗。任何人都可以告訴我爲什麼測試中的最終斷言可能會失敗,爲什麼'at'檢查器顯示爲空?
這是我的代碼:(蓋布v0.9.0,Grails的2.2.2)
斯波克規格:
class UserAuthAcceptanceSpec extends GebReportingSpec {
def "login works correctly"() {
given: "the correct credentials"
def theCorrectUsername = "admin"
def theCorrectPassword = "password"
when: "logging in"
to LoginPage
username = theCorrectUsername
password = theCorrectPassword
submitButton.click() //([HomePage, LoginPage])
then: "the welcome page is shown"
heading =~ /(?i)Welcome.*/ // <- same as 'at' checker in HomePage
and: "the 'at' checker works"
at HomePage // <- fails
}
LoginPage:
class LoginPage extends Page {
final String path = "/login/auth"
static content = {
heading(required: false, wait:true) { $("h1").text() }
username { $("input", name:"j_username") }
password { $("input", name:"j_password") }
submitButton { $("input", id:"submit") }
}
static at = {
title =~ /Login.*/
}
}
主頁 :
class HomePage extends Page {
final String path = "/"
static content = {
heading(required: false, wait:true) { $("h1").text() }
}
static at = {
heading =~ /(?i)Welcome.*/
}
}