use of com.gargoylesoftware.htmlunit.WebConsole in project htmlunit by HtmlUnit.
the class WindowTest method dump.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "", FF = "info: Dumper", FF_ESR = "info: Dumper")
public void dump() throws Exception {
final WebConsole console = getWebClient().getWebConsole();
final List<String> messages = new ArrayList<>();
console.setLogger(new Logger() {
@Override
public void warn(final Object message) {
}
@Override
public void trace(final Object message) {
}
@Override
public void info(final Object message) {
messages.add("info: " + message);
}
@Override
public void error(final Object message) {
}
@Override
public void debug(final Object message) {
}
@Override
public boolean isTraceEnabled() {
return false;
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public boolean isErrorEnabled() {
return true;
}
});
final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " if (window.dump) {\n" + " window.dump('Dumper');\n" + " }\n" + "}\n" + "</script></head><body onload='test()'></body></html>";
loadPage(html);
assertEquals(getExpectedAlerts(), messages);
}
use of com.gargoylesoftware.htmlunit.WebConsole in project htmlunit by HtmlUnit.
the class Console2Test method log.
private void log(final String logInput) throws Exception {
final WebConsole console = getWebClient().getWebConsole();
final List<String> messages = new ArrayList<>();
console.setLogger(new Logger() {
@Override
public void warn(final Object message) {
}
@Override
public void trace(final Object message) {
}
@Override
public void info(final Object message) {
messages.add("info: " + message);
}
@Override
public void error(final Object message) {
}
@Override
public void debug(final Object message) {
}
@Override
public boolean isTraceEnabled() {
return false;
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public boolean isErrorEnabled() {
return true;
}
});
final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " window.console.log(" + logInput + ");\n" + "}\n" + "</script></head><body onload='test()'></body></html>";
loadPage(html);
assertEquals(getExpectedAlerts(), messages);
}
use of com.gargoylesoftware.htmlunit.WebConsole in project selenium_java by sergueik.
the class HtmlUnitConsole method setHtmlUnitConsole.
/**
* Set console handler for HtmlUnitDriver.
*
* @param driver HtmlUnitDriver.
*/
public static void setHtmlUnitConsole(WebDriver driver) {
try {
Field f = driver.getClass().getDeclaredField("webClient");
f.setAccessible(true);
WebClient webClient = (WebClient) f.get(driver);
WebConsole webConsole = webClient.getWebConsole();
com.gargoylesoftware.htmlunit.WebConsole.Logger logger = webConsole.getLogger();
if (logger != null && logger instanceof HtmlUnitConsole)
return;
webConsole.setLogger(INSTANCE);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
log.warn("Cannot set htmlunit console.", e);
return;
}
}
use of com.gargoylesoftware.htmlunit.WebConsole in project htmlunit by HtmlUnit.
the class Console method error.
/**
* This method performs logging to the console at {@code error} level.
* @param cx the JavaScript context
* @param thisObj the scriptable
* @param args the arguments passed into the method
* @param funObj the function
*/
@JsxFunction
public static void error(final Context cx, final Scriptable thisObj, final Object[] args, final Function funObj) {
final WebConsole webConsole = toWebConsole(thisObj);
final Formatter oldFormatter = webConsole.getFormatter();
webConsole.setFormatter(FORMATTER_);
webConsole.error(args);
webConsole.setFormatter(oldFormatter);
}
use of com.gargoylesoftware.htmlunit.WebConsole in project selenese-runner-java by vmi.
the class HtmlUnitConsole method setHtmlUnitConsole.
/**
* Set console handler for HtmlUnitDriver.
*
* @param driver HtmlUnitDriver.
*/
public static void setHtmlUnitConsole(WebDriver driver) {
try {
Field f = driver.getClass().getDeclaredField("webClient");
f.setAccessible(true);
WebClient webClient = (WebClient) f.get(driver);
WebConsole webConsole = webClient.getWebConsole();
com.gargoylesoftware.htmlunit.WebConsole.Logger logger = webConsole.getLogger();
if (logger != null && logger instanceof HtmlUnitConsole)
return;
webConsole.setLogger(INSTANCE);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
log.warn("Cannot set htmlunit console.", e);
return;
}
}
Aggregations