在下面的示例中(取自
Book of Geb
,我们点击一个按钮,转到另一页。
class GoogleHomePage extends Page {
static url = "http://google.com"
static at = {
title == "Google"
}
static content = {
searchField { $("input[name=q]") }
searchButton(to: GoogleResultsPage) { $("input[value='Google Search']") }
}
}
Browser.drive(GoogleHomePage) {
searchField.value("Chuck Norris")
searchButton.click()
assert at(GoogleResultsPage)
assert resultLink(0).text() ==~ /Chuck/
}
当我们转到另一页时,如何传递状态?用户已经选择了这种语言,在下一页中,我希望页面使用这种语言。更一般的例子:
import geb.*
import grails.plugin.geb.GebSpec
class GoogleHomePage extends Page {
static url = "http://google.com"
static at = { title == "Google" }
static content = {
searchField { $("input[name=q]") }
searchButton(to: GoogleResultsPage, searchTerm:searchField.value()) { $("input[value='Google Search']") }
}
}
class GoogleResultsPage extends Page {
def searchTerm
static at = {
title == "${searchTerm} - Google Search"
}
}
class MainFunctionalSpec extends GebSpec {
def "Google search"() {
when:
to GoogleHomePage
then:
searchField.value("Chuck Norris")
searchButton.click()
assert at(GoogleResultsPage)
}
}
此代码有2个问题,我在searchbutton.click()上获取“no such property:searchfield for class:googlehomepage”来填充searchterm。即使我硬编码传递的内容,googleResultsPage.searchTerm为空,at断言也失败。有什么想法吗?