Search in sources :

Example 41 with Alerts

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

the class FocusableElement2Test method bodySwitchFromBodyToNotFocusable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: body", "before", "active: body", "after", "active: body" }, CHROME = { "before", "active: body", "after", "active: body" }, EDGE = { "before", "active: body", "after", "active: body" }, IE = { "onfocusin:body", "active: body", "onfocus:[object Window]", "active: body", "before", "active: body", "after", "active: body" })
@HtmlUnitNYI(FF = { "before", "active: body", "after", "active: body" }, FF_ESR = { "before", "active: body", "after", "active: body" }, IE = { "before", "active: body", "after", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodySwitchFromBodyToNotFocusable() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <script>\n" + logger() + "      function test() {\n" + "        log('before');\n" + "        document.getElementById('focusId').focus();\n" + "        document.getElementById('focusId').blur();\n" + "        log('after');\n" + "      }\n" + "    </script>\n" + "  </head>\n" + "  <body id='body' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + "    <div id='focusId' " + logEvents("F") + ">div</div>\n" + "  </body>\n" + "</html>\n";
    final WebDriver driver = loadPage2(html);
    assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 42 with Alerts

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

the class FocusableElement2Test method bodySwitchFromBodyToFocusable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: body", "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, CHROME = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, EDGE = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, IE = { "onfocusin:body", "active: body", "onfocus:[object Window]", "active: body", "before", "active: body", "onfocusout:body", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "onfocusin:body", "active: body", "after", "active: body", "onfocusF:focusId", "active: body", "onblurF:focusId", "active: body" })
@HtmlUnitNYI(FF = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, FF_ESR = { "before", "active: body", "onfocusF:focusId", "active: focusId", "onfocusinF:focusId", "active: focusId", "onfocusin:focusId", "active: focusId", "onblurF:focusId", "active: body", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "after", "active: body" }, IE = { "before", "active: body", "onfocusout:body", "active: body", "onfocusinF:focusId", "active: body", "onfocusin:focusId", "active: body", "onfocusF:focusId", "active: focusId", "onfocusoutF:focusId", "active: body", "onfocusout:focusId", "active: body", "onblurF:focusId", "active: body", "after", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodySwitchFromBodyToFocusable() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <script>\n" + logger() + "      function test() {\n" + "        log('before');\n" + "        document.getElementById('focusId').focus();\n" + "        document.getElementById('focusId').blur();\n" + "        log('after');\n" + "      }\n" + "    </script>\n" + "  </head>\n" + "  <body id='body' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + "    <input type='text' id='focusId' " + logEvents("F") + ">\n" + "  </body>\n" + "</html>\n";
    final WebDriver driver = loadPage2(html);
    assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 43 with Alerts

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

the class FocusableElement2Test method body.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "onfocus:[object Window]", "active: focusId", "before", "active: focusId", "after", "active: focusId" }, CHROME = { "before", "active: focusId", "after", "active: focusId" }, EDGE = { "before", "active: focusId", "after", "active: focusId" }, IE = { "onfocusin:focusId", "active: focusId", "onfocus:[object Window]", "active: focusId", "before", "active: focusId", "after", "active: focusId" })
@HtmlUnitNYI(FF = { "before", "active: focusId", "after", "active: focusId" }, FF_ESR = { "before", "active: focusId", "after", "active: focusId" }, IE = { "before", "active: focusId", "onfocusout:focusId", "active: focusId", "after", "active: focusId" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void body() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <script>\n" + logger() + "      function test() {\n" + "        log('before');\n" + "        document.getElementById('focusId').focus();\n" + "        document.getElementById('focusId').focus();\n" + "        document.getElementById('focusId').blur();\n" + "        document.getElementById('focusId').blur();\n" + "        log('after');\n" + "      }\n" + "    </script>\n" + "  </head>\n" + "  <body id='focusId' onload='setTimeout(test, 10)' " + logEvents("") + ">\n" + "  </body>\n" + "</html>\n";
    final WebDriver driver = loadPage2(html);
    assertTitle(driver, String.join(";", getExpectedAlerts()) + (getExpectedAlerts().length > 0 ? ";" : ""));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 44 with Alerts

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

the class HtmlAnchor2Test method clickWithDownloadAttributeDataUrl.

/**
 * Not testable with Selenium.
 *
 * @exception Exception If the test fails
 */
@Test
@Alerts(DEFAULT = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" }, IE = { "0", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
@HtmlUnitNYI(IE = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
public void clickWithDownloadAttributeDataUrl() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "  <title>First</title>\n" + "</head>\n" + "<body>\n" + "  <a id='clickMe' href='data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP" + "C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA" + "AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J" + "REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq" + "ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0" + "vr4MkhoXe0rZigAAAABJRU5ErkJggg==' download='lora.html'>Click Me</a>\n" + "</body></html>";
    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final int windowsSize = getWebClient().getWebWindows().size();
    final HtmlPage page = loadPage(html);
    page.getElementById("clickMe").click();
    assertEquals("Should have opened a new window", windowsSize + Integer.parseInt(getExpectedAlerts()[0]), getWebClient().getWebWindows().size());
    assertEquals("Should not have navigated away", getExpectedAlerts()[1], page.getTitleText());
    final WebWindow dataWindow = getWebClient().getWebWindows().get(getWebClient().getWebWindows().size() - 1);
    final Page dataPage = dataWindow.getEnclosedPage();
    assertTrue("Should be an UnexpectedPage", dataPage instanceof UnexpectedPage);
    try (InputStream resultInputStream = ((UnexpectedPage) dataPage).getInputStream()) {
        final ImageInputStream resultImageIS = ImageIO.createImageInputStream(resultInputStream);
        final BufferedImage resultBufferedIIS = ImageIO.read(resultImageIS);
        compareImages(getExpectedAlerts()[2], null, resultBufferedIIS);
    }
}
Also used : UnexpectedPage(com.gargoylesoftware.htmlunit.UnexpectedPage) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) UnexpectedPage(com.gargoylesoftware.htmlunit.UnexpectedPage) Page(com.gargoylesoftware.htmlunit.Page) BufferedImage(java.awt.image.BufferedImage) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 45 with Alerts

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

the class HtmlBaseTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLBaseElement]")
public void simpleScriptable() throws Exception {
    final String html = "<html><head>\n" + "<base id='myId' target='MyNewWindow'>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    log(document.getElementById('myId'));\n" + "  }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertTrue(HtmlBase.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)

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