【发布时间】:2018-12-18 06:59:06
【问题描述】:
我正在尝试使用 GEB 和 Spock 编写一个简单的测试。以下是页面和规格测试:
页面
import geb.Page
class DashboardPage extends Page {
static url = "?root=dashboard"
static at = { pageTitle.text() == "Dashboard Content Area" }
static content = {
pageTitle(wait: 25) { $("div#content-view-title>h1") }
leaderBoardPeriodCombo { $("#leaderboardPeriod") }
//manualsMenu { module(ManualsMenuModule) }
}
def selectLeaderBoardPeriod(periodValue) {
leaderBoardPeriodCombo.value(periodValue)
}
}
规格测试:
import geb.spock.GebSpec
import pages.DashboardPage
class LeaderboardSpec extends GebSpec {
def "change LeaderBoard type value"() {
when: to DashboardPage
then: at DashboardPage
when: DashboardPage.selectLeaderBoardPeriod("monthly")
then: at DashboardPage
}
}
但我收到以下错误:
groovy.lang.MissingMethodException:
No signature of method: static pages.DashboardPage.selectLeaderBoardPeriod() is applicable for argument types: (java.lang.String) values: [monthly]
Possible solutions: selectLeaderBoardPeriod(java.lang.String)
at specs.LeaderboardSpec.change LeaderBoard type value(LeaderboardSpec.groovy:13)
Results :
Tests in error:
LeaderboardSpec.change LeaderBoard type value:13 MissingMethod No signature of...
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
selectLeaderBoardPeriod 的签名它有一个参数。我试图将类型明确定义为 String 但我得到了同样的错误。
谁能发现我做错了什么?
提前谢谢你。
最好的问候
【问题讨论】:
-
当您调用
DashboardPage.selectLeaderBoardPeriod("monthly")时,您希望执行一个静态方法,而def selectLeaderBoardPeriod(periodValue)是在非静态范围内定义的。 -
这完全有道理。非常感谢