Search in sources :

Example 91 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlPreformattedTextTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLPreElement]")
public void simpleScriptable() throws Exception {
    final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    log(document.getElementById('myId'));\n" + "  }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "  <pre id='myId'>Some Text</pre>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertTrue(HtmlPreformattedText.class.isInstance(page.getHtmlElementById("myId")));
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 92 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlProgressTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLProgressElement]")
public void simpleScriptable() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    log(document.getElementById('myId'));\n" + "  }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "  <progress id='myId'></progress>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        if ("[object HTMLProgressElement]".equals(getExpectedAlerts()[0])) {
            assertTrue(HtmlProgress.class.isInstance(page.getHtmlElementById("myId")));
        } else {
            assertTrue(HtmlUnknownElement.class.isInstance(page.getHtmlElementById("myId")));
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 93 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class WindowConcurrency2Test method setIntervalZeroDelay.

/**
 * When <tt>setInterval()</tt> is called with a 0 millisecond delay, Internet Explorer turns it
 * into a <tt>setTimeout()</tt> call, and Firefox imposes a minimum timer restriction.
 *
 * @throws Exception if an error occurs
 */
@Test
@Alerts("xxx")
public void setIntervalZeroDelay() throws Exception {
    final String html = "<html><body><div id='d'></div>\n" + "<script>\n" + "  var count = 0;\n" + "  function doTimeout() {\n" + "    document.getElementById('d').innerHTML += 'x';\n" + "    count++;\n" + "    if (count > 2) {\n" + "      clearInterval(id);\n" + "    }\n" + "  }\n" + "  var id = setInterval(doTimeout, 0);\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    verifyAlerts(() -> driver.findElement(By.id("d")).getText(), getExpectedAlerts()[0]);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 94 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class WindowTest method showModalDialog.

/**
 * Basic test for the <tt>showModalDialog</tt> method. See bug #703.
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = { "undefined", "Jane", "Smith", "sdg", "finished" }, CHROME = "not available", EDGE = "not available", FF = "not available", FF_ESR = "not available")
public void showModalDialog() throws Exception {
    final String html1 = "<html><head><script>\n" + "  function test() {\n" + "    if (!window.showModalDialog) {alert('not available'); return; }\n" + "    alert(window.returnValue);\n" + "    var o = new Object();\n" + "    o.firstName = 'Jane';\n" + "    o.lastName = 'Smith';\n" + "    var ret = showModalDialog('myDialog.html', o, 'dialogHeight:300px; dialogLeft:200px;');\n" + "    alert(ret);\n" + "    alert('finished');\n" + "  }\n" + "</script></head><body>\n" + "  <button onclick='test()' id='b'>Test</button>\n" + "</body></html>";
    final String html2 = "<html><head><script>\n" + "  var o = window.dialogArguments;\n" + "  alert(o.firstName);\n" + "  alert(o.lastName);\n" + "  window.returnValue = 'sdg';\n" + "</script></head>\n" + "<body>foo</body></html>";
    final WebClient client = getWebClient();
    final List<String> actual = new ArrayList<>();
    client.setAlertHandler(new CollectingAlertHandler(actual));
    final MockWebConnection conn = new MockWebConnection();
    conn.setResponse(URL_FIRST, html1);
    conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2);
    client.setWebConnection(conn);
    final HtmlPage page = client.getPage(URL_FIRST);
    final HtmlElement button = page.getHtmlElementById("b");
    final HtmlPage dialogPage = button.click();
    if (getExpectedAlerts().length > 1) {
        final DialogWindow dialog = (DialogWindow) dialogPage.getEnclosingWindow();
        dialog.close();
    }
    assertEquals(getExpectedAlerts(), actual);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) ArrayList(java.util.ArrayList) CollectingAlertHandler(com.gargoylesoftware.htmlunit.CollectingAlertHandler) MockWebConnection(com.gargoylesoftware.htmlunit.MockWebConnection) WebClient(com.gargoylesoftware.htmlunit.WebClient) DialogWindow(com.gargoylesoftware.htmlunit.DialogWindow) URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 95 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class WindowTest method onbeforeunload_calledBeforeDownload.

/**
 * Download of next page is done first after onbeforeunload is done.
 * @throws Exception if an error occurs
 */
@Test
@Alerts("x")
public void onbeforeunload_calledBeforeDownload() throws Exception {
    final String html = "<html><body><script>\n" + "  window.onbeforeunload = function() { alert('x'); return 'hello'; };\n" + "  window.location = 'foo.html';\n" + "</script></body></html>";
    final WebClient webClient = getWebClientWithMockWebConnection();
    getMockWebConnection().setDefaultResponse("");
    final OnbeforeunloadHandler handler = new OnbeforeunloadHandler() {

        @Override
        public boolean handleEvent(final Page page, final String returnValue) {
            final String[] expectedRequests = { "" };
            assertEquals(expectedRequests, getMockWebConnection().getRequestedUrls(URL_FIRST));
            return true;
        }
    };
    webClient.setOnbeforeunloadHandler(handler);
    loadPageWithAlerts(html);
    final String[] expectedRequests = { "", "foo.html" };
    assertEquals(expectedRequests, getMockWebConnection().getRequestedUrls(URL_FIRST));
}
Also used : OnbeforeunloadHandler(com.gargoylesoftware.htmlunit.OnbeforeunloadHandler) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) 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