Search in sources :

Example 96 with Alerts

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);
}
Also used : WebConsole(com.gargoylesoftware.htmlunit.WebConsole) ArrayList(java.util.ArrayList) Logger(com.gargoylesoftware.htmlunit.WebConsole.Logger) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 97 with Alerts

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();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 98 with Alerts

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());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 99 with Alerts

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();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 100 with Alerts

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();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)1266 Test (org.junit.Test)1261 WebDriver (org.openqa.selenium.WebDriver)894 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)398 URL (java.net.URL)238 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)206 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)159 WebElement (org.openqa.selenium.WebElement)146 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)128 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)101 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)97 ArrayList (java.util.ArrayList)90 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)54 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)48 XMLDocumentTest.callLoadXMLDocumentFromString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromString)47 XMLDocumentTest.callSerializeXMLDocumentToString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callSerializeXMLDocumentToString)44 File (java.io.File)30 WebClient (com.gargoylesoftware.htmlunit.WebClient)29 InputStream (java.io.InputStream)29