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

我在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(),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),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特定方法.

相关文章

背景:    8月29日,凌晨4点左右,某服务告警,其中一个...
https://support.smartbear.comeadyapi/docs/soapui/steps/g...
有几个选项可用于执行自定义JMeter脚本并扩展基线JMeter功能...
Scala和Java为静态语言,Groovy为动态语言Scala:函数式编程,...
出处:https://www.jianshu.com/p/ce6f8a1f66f4一、一些内部...
在运行groovy的junit方法时,报了这个错误:java.lang.Excep...