Search in sources :

Example 31 with NotYetImplemented

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

the class PerformanceTimingTest method toJSON.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object Object]")
@NotYetImplemented
public void toJSON() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    var performanceTiming = performance.timing;\n" + "    log(performanceTiming.toJSON());\n" + "  }\n" + "</script>\n" + "</head>\n" + "<body>\n" + "  <button id='clickMe' onClick='test()'>do it</button>\n" + "</body>\n" + "</html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("clickMe")).click();
    verifyTitle2(driver, getExpectedAlerts());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 32 with NotYetImplemented

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

the class WebClient2Test method makeSureTheCurrentJobHasEndedBeforeReplaceWindowPage.

/**
 * @throws Exception if something goes wrong
 */
@Test
@NotYetImplemented
public void makeSureTheCurrentJobHasEndedBeforeReplaceWindowPage() throws Exception {
    final String htmlContent1 = "<html>\n" + "<head>" + "  <title>Page 1</title>\n" + "</head>\n" + "<body>\n" + "  <script>\n" + "    function loadExtraContent() {\n" + "      for (var i = 0; i < 1000; i++) {\n" + "        var p = document.createElement('p');\n" + "        p.innerHTML = 'new content';\n" + "        var body = document.querySelector('body');\n" + "        if (body) { body.appendChild(p); }\n" + "      }\n" + "    }\n" + "    setTimeout(loadExtraContent, 1);" + "  </script>\n" + "</body>\n" + "</html>";
    final String htmlContent2 = "<html>\n" + "<head>" + "  <title>Page 2</title>\n" + "</head>\n" + "<body>\n" + "  <h1>Page2</h1>\n" + "  <p>This is page 2</p>\n" + "</body>\n" + "</html>";
    final WebClient client = getWebClient();
    final MockWebConnection webConnection = new MockWebConnection();
    webConnection.setDefaultResponse(htmlContent1);
    webConnection.setResponse(URL_SECOND, htmlContent2);
    client.setWebConnection(webConnection);
    // Load page 1. Has a setTimeout(...) function
    HtmlPage page = client.getPage(URL_FIRST);
    Thread.sleep(100);
    // Immediately load page 2. Timeout function was triggered already
    page = client.getPage(URL_SECOND);
    client.waitForBackgroundJavaScriptStartingBefore(100);
    // Fails: return 98 (about) instead of 1
    assertEquals(1, page.querySelectorAll("p").size());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test)

Example 33 with NotYetImplemented

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

the class Window3Test method onloadFrame.

/**
 * Same as {@link #onload()} but from frame.
 *
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "framing window DOMContentLoaded 1 capture", "framing document DOMContentLoaded 1", "framing document DOMContentLoaded 1 capture", "framing window DOMContentLoaded 1", "window DOMContentLoaded 1 capture", "window DOMContentLoaded 2 capture", "document DOMContentLoaded 1", "document DOMContentLoaded 1 capture", "document DOMContentLoaded 2", "document DOMContentLoaded 2 capture", "window DOMContentLoaded 1", "window DOMContentLoaded 2", "window at load 1", "window at load 1 capture", "window at load 2", "onload 2", "window at load 2 capture", "framing document at load 1 capture", "frame onload", "framing window at load 1", "framing window at load 1 capture", "frameset onload", "after" }, IE = { "framing window DOMContentLoaded 1 capture", "framing document DOMContentLoaded 1", "framing document DOMContentLoaded 1 capture", "framing window DOMContentLoaded 1", "framing document at load 1 capture", "window DOMContentLoaded 1 capture", "window DOMContentLoaded 2 capture", "document DOMContentLoaded 1", "document DOMContentLoaded 1 capture", "document DOMContentLoaded 2", "document DOMContentLoaded 2 capture", "window DOMContentLoaded 1", "window DOMContentLoaded 2", "window at load 1", "window at load 1 capture", "window at load 2", "onload 2", "window at load 2 capture", "framing document at load 1 capture", "frame onload", "framing window at load 1", "framing window at load 1 capture", "frameset onload", "document at load 1 capture", "document at load 2 capture", "document at load 1 capture", "document at load 2 capture", "after" })
// The extra 'document at load' from <script> not yet handled (waiting on onloadScript())
@NotYetImplemented(IE)
public void onloadFrame() throws Exception {
    final String content = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + "  function log(msg) {\n" + "    window.parent.document.title += msg + ';';\n" + "  }\n" + "  window.addEventListener('load', function () { log('window at load 1') })\n" + "  window.addEventListener('load', function () { log('window at load 1 capture') }, true)\n" + "  window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 1') })\n" + "  window.addEventListener('DOMContentLoaded', " + "function () { log('window DOMContentLoaded 1 capture') }, true)\n" + "  document.addEventListener('load', function () { log('document at load 1') })\n" + "  document.addEventListener('load', function () { log('document at load 1 capture') }, true)\n" + "  document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 1') })\n" + "  document.addEventListener('DOMContentLoaded', " + "function () { log('document DOMContentLoaded 1 capture') }, true)\n" + "</script>\n" + "</head>\n" + "<body >\n" + "<script>\n" + "  window.addEventListener('load', function () { log('window at load 2') })\n" + "  window.onload = function () { log('onload 2') }\n" + "  window.addEventListener('load', function () { log('window at load 2 capture') }, true)\n" + "  window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 2') })\n" + "  window.addEventListener('DOMContentLoaded', " + "function () { log('window DOMContentLoaded 2 capture') }, true)\n" + "  document.addEventListener('load', function () { log('document at load 2 capture') }, true)\n" + "  document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 2') })\n" + "  document.addEventListener('DOMContentLoaded', " + "function () { log('document DOMContentLoaded 2 capture') }, true)\n" + "  window.addEventListener('load', " + "function (event) { var x = event; " + "window.setTimeout(function () { log('after', x.eventPhase) }, 100) }, true)\n" + "</script>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse(content);
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + "  function log(msg) {\n" + "    window.document.title += msg + ';';\n" + "  }\n" + "  window.addEventListener('load', function () { log('framing window at load 1') })\n" + "  window.addEventListener('load', function () { log('framing window at load 1 capture') }, true)\n" + "  window.addEventListener('DOMContentLoaded', " + "function () { log('framing window DOMContentLoaded 1') })\n" + "  window.addEventListener('DOMContentLoaded', " + "function () { log('framing window DOMContentLoaded 1 capture') }, true)\n" + // should not fire because bubbles = false
    "  document.addEventListener('load', " + "function () { log('framing document at load 1') })\n" + "  document.addEventListener('load', " + "function () { log('framing document at load 1 capture') }, true)\n" + "  document.addEventListener('DOMContentLoaded', " + "function () { log('framing document DOMContentLoaded 1') })\n" + "  document.addEventListener('DOMContentLoaded', " + "function () { log('framing document DOMContentLoaded 1 capture') }, true)\n" + "</script>\n" + "</head>\n" + "<frameset onload='log(\"frameset onload\")'>\n" + "<frame src='test_onload.html' onload='log(\"frame onload\")'>\n" + "</frameset>\n" + "</html>";
    final WebDriver driver = loadPage2(html);
    Thread.sleep(200);
    final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
    assertEquals(String.join("\n", getExpectedAlerts()), text);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 34 with NotYetImplemented

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

the class Window3Test method onloadScript.

/**
 * Tests load and error events of 'script' tags.
 * Checks that they should be using EventTarget.fireEvent()
 * rather than Event.executeEventLocally().
 *
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "document at load capture", "element 1 onload", "window at error capture", "document at error capture", "element 2 onerror", "document DOMContentLoaded", "window DOMContentLoaded", "window at load", "window at load capture", "body onload" }, IE = { "window at error", "window at error capture", "document at load capture", "element 1 onload", "window at error capture", "document at error capture", "element 2 onerror", "document DOMContentLoaded", "window DOMContentLoaded", "window at load", "window at load capture", "body onload", "document at load capture" })
@NotYetImplemented
public void onloadScript() throws Exception {
    getMockWebConnection().setResponse(URL_SECOND, "");
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + "  function log(msg) {\n" + "    window.parent.document.title += msg + ';';\n" + "  }\n" + "  window.addEventListener('load', function () { log('window at load') })\n" + "  window.addEventListener('load', function () { log('window at load capture') }, true)\n" + "  window.addEventListener('error', function () { log('window at error') })\n" + "  window.addEventListener('error', function () { log('window at error capture') }, true)\n" + "  window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded') })\n" + "  document.addEventListener('load', function () { log('document at load') })\n" + "  document.addEventListener('load', function () { log('document at load capture') }, true)\n" + "  document.addEventListener('error', function () { log('document at error') })\n" + "  document.addEventListener('error', function () { log('document at error capture') }, true)\n" + "  document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded') })\n" + "</script>\n" + "</head>\n" + "<body onload='log(\"body onload\")'>\n" + "  <script src='" + URL_SECOND + "' onload='log(\"element 1 onload\")' " + "onerror='log(\"element 1 onerror\")'></script>\n" + "  <script src='missing.txt' onload='log(\"element 2 onload\")' " + "onerror='log(\"element 2 onerror\")'></script>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", com.gargoylesoftware.htmlunit.util.MimeType.TEXT_HTML);
    final WebDriver driver = loadPage2(html);
    Thread.sleep(200);
    final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
    assertEquals(String.join("\n", getExpectedAlerts()), text);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 35 with NotYetImplemented

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

the class Location2Test method locationAfterOpenClosePopup.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("§§URL§§test.html")
// real browsers don't show the alert, since it is quickly closed through JavaScript
@NotYetImplemented
@BuggyWebDriver(IE = "§§URL§§")
public void locationAfterOpenClosePopup() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "  <title>test</title>\n" + "  <script>\n" + "    function test() {\n" + "      var win = window.open('" + URL_SECOND + "','test','',true);\n" + "      win.close();\n" + "      location.href = 'test.html';\n" + "    }\n" + "  </script>\n" + "</head>\n" + "<body>\n" + "  <button id='click' onclick='test()'>Test</button>\n" + "</body>\n" + "</html>";
    final String popup = "<html>\n" + "<head>\n" + "  <title>popup with script</title>\n" + "  <script>\n" + "    alert('the root of all evil');\n" + "  </script>\n" + "</head>\n" + "<body>Popup</body>\n" + "</html>";
    final String target = "<html>\n" + "<head>\n" + "  <title>target</title>\n" + "</head>\n" + "<body>Target</body>\n" + "</html>";
    getMockWebConnection().setResponse(URL_SECOND, popup);
    getMockWebConnection().setResponse(new URL(URL_FIRST, "test.html"), target);
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("click")).click();
    try {
        assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
    } finally {
        // TODO [IE] when run with real IE the window is closed and all following tests are broken
        releaseResources();
        shutDownAll();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) URL(java.net.URL) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)66 Test (org.junit.Test)65 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)54 WebDriver (org.openqa.selenium.WebDriver)54 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)16 URL (java.net.URL)15 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)12 WebElement (org.openqa.selenium.WebElement)11 ArrayList (java.util.ArrayList)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)4 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)4 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)4 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 InputStream (java.io.InputStream)3 CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)2 MSXMLTestHelper.callSerializeXMLDOMDocumentToString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callSerializeXMLDOMDocumentToString)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 File (java.io.File)2