首页 > 解决方案 > GEB + Spock:没有方法签名

问题描述

我正在尝试用 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 但我得到了同样的错误。

有人能发现我做错了什么吗?

先感谢您。

此致

标签: groovyspockgeb

解决方案


您的规格需要类似于:

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

        and:
        page.selectLeaderBoardPeriod("monthly")

        then:
        at DashboardPage
    }
}

推荐阅读