2014-09-11 61 views
5

在IntelliJ IDE中運行Geb測試時出現以下錯誤。發生在步驟定義文件使用groovy在IntelliJ IDE中運行Cucumber 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) 

錯誤時嘗試通過蓋布訪問網頁

Given(~'^I am on the My home page$') { -> 

    to MyLandingPage 
    waitFor { at(MyLandingPage) } 
} 

測試是完全在命令行與gradle test命令

+0

這聽起來很明顯,但要確保已經將geb腳本所在的目錄添加爲「測試源」目錄。因此,如果Geb的東西在src/groovy中,右鍵單擊並選擇'Mark Directory As'>'Test Sources Root' – 2014-12-21 18:13:30

回答

0

運行在我的情況下加入瀏覽器.drive關閉修復了這個問題。 所以,你的例子是:

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

我有同樣的問題,終於找到了解決辦法。基於示例項目https://github.com/geb/geb-example-cucumber-jvm.git,您需要確保文件'env.groovy'也在運行配置的粘連列表中被引用。 cucumber-java settings 然後正確加載BindingUpdater,並在運行測試時在步驟文件中提供所有特定於geb的方法。

+0

是否有避免每次爲每個功能配置intellij的方法? – Ankit 2016-11-23 11:04:03

相關問題