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

时间:2014-09-11 05:55:09

标签: 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命令

在命令行中完美地运行测试

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

在我的情况下,添加Browser.drive闭包修复了问题。 所以你的例子是:

Given(~'^I am on the My home page$') { ->
    Browser.drive {
        to MyLandingPage
        waitFor { at(MyLandingPage) }
    }
}