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のように見えるクラスローダーの問題を... –
それはEclipseの設定だったようだ。 Groovy Eclipseは、GroovyStarterを使用した起動設定を生成しました。コマンドラインでjavaを直接呼び出して成功した後、私はスクリプトを直接呼び出すように起動設定を変更し、正常に動作します。 GroovyStarterは動作する予定ですか? GroovyStarterの目的は、メイン・メソッドを持つクラスに対してスクリプトをコンパイルする場合です。 –