I'm using cuke4duke in a grails project. The features/support/env.groovy has
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 !
...
}
It seems the class gets properly compiled, but groovy cannot call setConfirmHandler as it expects a ConfirmHandler... but the provided object's class implements the interface! I checked that "confirmation instanceof ConfirmHandler" prints true.
Note: the HtmlUnit package is written in Java.
Any ideas? (this is the top of the stack trace)
[INFO] org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: org.openqa.selenium.htmlunit.HtmlUnitDriver.setConfirmHandler() is applicable for argument types: (ConfirmationHandler) values: [ConfirmationHandler@6c08bae7] (NativeException)
Dont you need to do:
browser.getWebClient().setConfirmHandler( confirmation )
As I can't see that HtmlUnitDriver has a setConfirmHandler
method...