【问题标题】:GEB + Spock: No signature of methodGEB + Spock:没有方法签名
【发布时间】: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) 是在非静态范围内定义的。
  • 这完全有道理。非常感谢

标签: groovy spock geb


【解决方案1】:

您的规范需要类似于:

class LeaderboardSpec extends GebSpec {
    def "change LeaderBoard type value"() {
        when:
        def page = to DashboardPage

        and:
        page.selectLeaderBoardPeriod("monthly")

        then:
        at DashboardPage
    }
}

【讨论】:

  • 对 OP 的另一个提示,就像他在上一个问题中所说的 Geb 新手:to SomePage 已经执行了 at 检查,并且只有当该检查为真时,它才会返回一个页面实例.这就是 Tim 在这里使用的以及为什么他不需要在开始时进行额外检查的原因(如果 at 失败,page 将是 null)。因此,即使您不想将页面分配给变量并在稍后的测试中使用它,如此处所示,您仍然可以只使用expect: to MyPage 而不是when: to MyPage; then: at MyPage。查看Book of Geb了解更多详情。
猜你喜欢
  • 2019-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 2021-06-15
  • 2021-10-20
  • 2014-11-21
相关资源
最近更新 更多