grails 프로젝트에서 cuke4duke를 사용하고 있습니다. 특징/지원/env.groovy는정의 된 클래스는 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 기대로 끝내 setConfirmHandler를 호출 할 수 없습니다 ...하지만 제공된 객체의 클래스는 인터페이스를 구현! 나는 "confirmation instanceof ConfirmHandler"가 사실인지 확인했다.
참고 : HtmlUnit 패키지는 Java로 작성되었습니다.
아이디어가 있으십니까? (이 스택 트레이스의 상부이다)
[INFO] org.codehaus.groovy.runtime.InvokerInvocationException : groovy.lang.MissingMethodException : org.openqa.selenium.htmlunit : 아니오 서명 방법. HtmlUnitDriver.setConfirmHandler()는 인수 유형 적용 : (ConfirmationHandler) 값 : [ConfirmationHandler @ 6c08bae7] (NativeException)
예, 실수입니다. 잘못된 클래스에서 메서드를 호출하고있었습니다. 이제 작동합니다. – carlosayam