我在 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 !
...
}
似乎该类已正确编译,但 groovy 无法调用 setConfirmHandler ,因为它需要一个 ConfirmHandler ......但提供的对象的类实现了接口!我检查了“confirmation instanceof ConfirmHandler”打印为真。
注意:HtmlUnit 包是用 Java 编写的。
有任何想法吗?(这是堆栈跟踪的顶部)
[INFO] org.codehaus.groovy.runtime.InvokerInvocationException:groovy.lang.MissingMethodException:没有方法签名:org.openqa.selenium.htmlunit.HtmlUnitDriver.setConfirmHandler()适用于参数类型:(ConfirmationHandler)值:[ConfirmationHandler @6c08bae7] (NativeException)