grails プロジェクトで cuke4duke を使用しています。features/support/env.groovy には
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.JavascriptExecutor
import com.gargoylesoftware.htmlunit.BrowserVersion
import com.gargoylesoftware.htmlunit.ConfirmHandler
import com.gargoylesoftware.htmlunit.Page
...
this.metaClass.mixin(cuke4duke.GroovyDsl)
...
public class ConfirmationHandler implements ConfirmHandler {
boolean handleConfirm(Page page, String message) {
called = true
if (text == null || text.length()==0) {
return answer
}
if (message.contains(text)) {
return answer
}
throw new RuntimeException("Expected '${text}' in confirmation message but got '${message}'")
}
public String text = null
public boolean answer = false
public boolean called = false
}
...
Before() {
...
browser = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6)
confirmation = new ConfirmationHandler()
browser.setConfirmHandler((ConfirmHandler) confirmation) // ERROR !
...
}
クラスは適切にコンパイルされているようですが、confirmHandler が必要なため、groovy は setConfirmHandler を呼び出すことができません... しかし、提供されたオブジェクトのクラスはインターフェイスを実装しています! 「ConfirmHandler の確認インスタンス」が true を出力することを確認しました。
注: HtmlUnit パッケージは Java で記述されています。
何か案は?(これはスタック トレースの先頭です)
[INFO] org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: メソッドのシグネチャがありません: org.openqa.selenium.htmlunit.HtmlUnitDriver.setConfirmHandler() は引数の型に適用されます: (ConfirmationHandler) 値: [ConfirmationHandler @ 6c08bae7] (NativeException)