微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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特定方法.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐