use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts 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.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WebSocketTest method wasClean.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: true", "onClose code: 1000 wasClean: true" }, FF = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: false", "onClose code: 1000 wasClean: false" }, FF_ESR = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: false", "onClose code: 1000 wasClean: false" }, IE = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onCloseListener code: 1000 wasClean: true", "onClose code: 1000 wasClean: true" })
@NotYetImplemented({ FF, FF_ESR })
public void wasClean() throws Exception {
expandExpectedAlertsVariables("ws://localhost:" + PORT);
final String expected = String.join("\n", getExpectedAlerts());
startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host", null, null, new EventsWebSocketHandler());
try {
final WebDriver driver = getWebDriver();
driver.get(URL_FIRST + "WebSocketTest_wasClean.html");
final WebElement logElement = driver.findElement(By.id("log"));
final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
String text;
do {
Thread.sleep(100);
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
} while (text.length() <= expected.length() && System.currentTimeMillis() < maxWait);
assertEquals(expected, text);
} finally {
stopWebServers();
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WebSocketTest method initialNoServerAvailable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts({ "§§URL§§", "", "blob" })
public void initialNoServerAvailable() throws Exception {
final String html = "<html>\n" + "<head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " var location = 'ws://localhost:" + PORT2 + "/';\n" + " var ws = new WebSocket(location);\n" + " log(ws.url);\n" + " log(ws.protocol);\n" + // + " log(ws.readyState);\n"
" log(ws.binaryType);\n" + " }\n" + "</script>\n" + "</head>\n" + "<body onload='test()'>\n" + "</body></html>";
expandExpectedAlertsVariables("ws://localhost:" + PORT2 + "/");
final WebDriver driver = loadPage2(html);
verifyTitle2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WebSocketTest method cookies.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts({ ": myname=My value!1", ": myname=My value!2" })
public void cookies() throws Exception {
final String[] expected = getExpectedAlerts();
startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host", null, null, new CookiesWebSocketHandler());
try {
final WebDriver driver = getWebDriver();
driver.get(URL_FIRST + "WebSocketTest_cookies.html");
driver.findElement(By.id("username")).sendKeys("Browser");
driver.findElement(By.id("joinB")).click();
final WebElement chatE = driver.findElement(By.id("chat"));
long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
do {
Thread.sleep(100);
} while (chatE.getText().length() <= expected[0].length() && System.currentTimeMillis() < maxWait);
assertEquals(expected[0], chatE.getText());
driver.findElement(By.id("phrase")).sendKeys("Hope you are fine!");
driver.findElement(By.id("sendB")).click();
maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
do {
Thread.sleep(100);
} while (!chatE.getText().contains(expected[1]) && System.currentTimeMillis() < maxWait);
assertEquals(expected[0] + "\n" + expected[1], chatE.getText());
} finally {
stopWebServers();
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WebSocketTest method events.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000", "onClose code: 1000" }, IE = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onCloseListener code: 1000", "onClose code: 1000" })
public void events() throws Exception {
expandExpectedAlertsVariables("ws://localhost:" + PORT);
final String expected = String.join("\n", getExpectedAlerts());
startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host", null, null, new EventsWebSocketHandler());
try {
final WebDriver driver = getWebDriver();
driver.get(URL_FIRST + "WebSocketTest_events.html");
final WebElement logElement = driver.findElement(By.id("log"));
final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
String text;
do {
Thread.sleep(100);
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
} while (text.length() <= expected.length() && System.currentTimeMillis() < maxWait);
assertEquals(expected, text);
} finally {
stopWebServers();
}
}
Aggregations