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