treeLogger.log(TreeLogger.WARN, message);
}
@Override
public void run() {
WebClient webClient = new WebClient(browser);
webClient.setAlertHandler(this);
// Adding a handler that ignores errors to work-around
// https://sourceforge.net/tracker/?func=detail&aid=3090806&group_id=47038&atid=448266
webClient.setCssErrorHandler(new ErrorHandler() {
public void error(CSSParseException exception) {
// ignore
}
public void fatalError(CSSParseException exception) {
treeLogger.log(TreeLogger.WARN,
"CSS fatal error: " + exception.getURI() + " ["
+ exception.getLineNumber() + ":"
+ exception.getColumnNumber() + "] " + exception.getMessage());
}
public void warning(CSSParseException exception) {
// ignore
}
});
webClient.setIncorrectnessListener(this);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(true);
webClient.setOnbeforeunloadHandler(this);
webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {
@Override
public void loadScriptError(HtmlPage htmlPage, URL scriptUrl,
Exception exception) {
treeLogger.log(TreeLogger.ERROR,
"Load Script Error: " + exception, exception);
}
@Override
public void malformedScriptURL(HtmlPage htmlPage, String url,
MalformedURLException malformedURLException) {
treeLogger.log(TreeLogger.ERROR,
"Malformed Script URL: " + malformedURLException.getLocalizedMessage());
}
@Override
public void scriptException(HtmlPage htmlPage,
ScriptException scriptException) {
treeLogger.log(TreeLogger.DEBUG,
"Script Exception: " + scriptException.getLocalizedMessage() +
", line " + scriptException.getFailingLine());
}
@Override
public void timeoutError(HtmlPage htmlPage, long allowedTime,
long executionTime) {
treeLogger.log(TreeLogger.ERROR,
"Script Timeout Error " + executionTime + " > " + allowedTime);
}
});
setupWebClient(webClient);
try {
Page page = webClient.getPage(url);
webClient.waitForBackgroundJavaScriptStartingBefore(2000);
if (treeLogger.isLoggable(TreeLogger.SPAM)) {
treeLogger.log(TreeLogger.SPAM, "getPage returned "
+ ((HtmlPage) page).asXml());
}
// TODO(amitmanjhi): call webClient.closeAllWindows()