4
我正在嘗試運行Geb庫的基本示例(http://www.gebish.org/manual/current/intro.html#introduction)。下面是代碼:Groovy無法通過關閉
import geb.Browser
Browser.drive {
go "http://google.com/ncr"
// make sure we actually got to the page
assert title == "Google"
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
// wait for the change to results page to happen
// (google updates the page dynamically without a new request)
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
assert firstLink.text() == "Wikipedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
waitFor { title == "Wikipedia" }
}
當我嘗試運行此(使用Eclipse的支持Groovy)我得到以下異常:
Caught: groovy.lang.MissingMethodException: No signature of method: static geb.Browser.drive() is applicable for argument types: (ExampleScript$_run_closure1) values: [[email protected]]
Possible solutions: drive(groovy.lang.Closure), drive(geb.Browser, groovy.lang.Closure), drive(geb.Configuration, groovy.lang.Closure), drive(java.util.Map, groovy.lang.Closure), print(java.lang.Object), print(java.io.PrintWriter)
groovy.lang.MissingMethodException: No signature of method: static geb.Browser.drive() is applicable for argument types: (ExampleScript$_run_closure1) values: [[email protected]]
Possible solutions: drive(groovy.lang.Closure), drive(geb.Browser, groovy.lang.Closure), drive(geb.Configuration, groovy.lang.Closure), drive(java.util.Map, groovy.lang.Closure), print(java.lang.Object), print(java.io.PrintWriter)
at ExampleScript.run(ExampleScript.groovy:21)
我認爲這是說,我傳遞給關閉靜態Browser.drive方法是不是與groovy.lang.Closure
類型兼容,但我不知道爲什麼。簡單的groovy hello world腳本可以正常工作,但傳遞閉包給方法總會返回類似的錯誤。
如果你在Eclipse之外運行它,它會工作嗎?看起來像Eclipse給你類加載器的問題... – 2012-03-15 09:14:52
它看起來像是Eclipse的配置。 Groovy Eclipse生成了一個使用GroovyStarter的啓動配置。在命令行直接成功調用java後,我改變了啓動配置,直接調用我的腳本,它工作正常。 GroovyStarter是否有望運作?如果腳本編譯爲帶有主方法的類,GroovyStarter的目的是什麼? – 2012-03-15 13:53:10