groovy - 使用 groovy 在 IntelliJ IDE 中运行 Cucumber Geb 测试时出错

标签 groovy intellij-idea junit4 geb cucumber-jvm

在 IntelliJ IDE 中运行 Geb 测试时出现以下错误。

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: features.step_definitions.MyHomeStepDef.to() is applicable for argument types: (java.lang.Class) values: [class geb.pages.MyLandingPage]
Possible solutions: is(java.lang.Object), run(), run(), any(), any(groovy.lang.Closure), with(groovy.lang.Closure)
  at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:97)
  at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
  at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
  at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
  at groovy.lang.Closure.call(Closure.java:415)
  at cucumber.runtime.groovy.GroovyBackend.invoke(GroovyBackend.java:133)
  at cucumber.runtime.groovy.GroovyStepDefinition.execute(GroovyStepDefinition.java:48)
  at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:45)
  at cucumber.runtime.Runtime.runStep(Runtime.java:248)
  ...
  at cucumber.cli.Main.main(Main.java:12)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  at ✽.Given I am on the My home page(D:\MyFolder\src\test\resources\features\my-login-page.feature:5)
Caused by: groovy.lang.MissingMethodException: No signature of method: features.step_definitions.MyHomeStepDef.to() is applicable for argument types: (java.lang.Class) values: [class geb.pages.MyLandingPage]
Possible solutions: is(java.lang.Object), run(), run(), any(), any(groovy.lang.Closure), with(groovy.lang.Closure)
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
  at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)
  at features.step_definitions.MyHomeStepDef$_run_closure1.doCall(MyHomeStepDef.groovy:25)
  .....
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

尝试通过Geb访问网页时步骤定义文件出错
Given(~'^I am on the My home page$') { ->

    to MyLandingPage
    waitFor { at(MyLandingPage) }
}

测试在命令行中完美运行 gradle test命令

最佳答案

我遇到了同样的问题,终于找到了解决方案。基于示例项目 https://github.com/geb/geb-example-cucumber-jvm.git您需要确保在运行配置的胶水列表中也引用了文件“env.groovy”。
cucumber-java settings
然后正确加载 BindingUpdater 并且在运行测试时所有特定于geb 的方法都在步骤文件中可用。

关于groovy - 使用 groovy 在 IntelliJ IDE 中运行 Cucumber Geb 测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25780040/

相关文章:

junit - 如何使用JUnit4以编程方式执行测试套件?

groovy - 使用 Groovy 进行选择排序

powershell - 在 PyCharm、PHPStorm 或 RubyMine 等 IntelliJ IDEA IDE 中使用 Powershell 作为终端

spring - 为什么我不能让 Spring 加载时间编织工作

java - Ninja 框架包括外部 Jar

java - Tomcat 10.0.4 不会加载带有 404 错误的 servlet(@WebServlet 类)

java - 对 ArrayList 的 ArrayList 进行 Junit 测试

java - 我用什么代替 Mockito 2.2 中的 Whitebox 来设置字段?

jenkins - 使用 Jenkins 和 Groovy 写入文件

gradle - Gradle脚本:将子文件夹和其他文件夹的内容复制到新位置