Search in sources :

Example 36 with Alerts

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

the class HtmlAreaTest method thisInJavascriptHref.

/**
 * In action "this" should be the window and not the area.
 * @throws Exception if the test fails
 */
@Test
@Alerts("true")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void thisInJavascriptHref() throws Exception {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
        final byte[] directBytes = IOUtils.toByteArray(is);
        final URL urlImage = new URL(URL_FIRST, "img.jpg");
        final List<NameValuePair> emptyList = Collections.emptyList();
        getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
    }
    final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + "  <area href='javascript:alert(this == window)' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map></body></html>";
    final WebDriver driver = loadPage2(html);
    final Page page;
    if (driver instanceof HtmlUnitDriver) {
        page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
    } else {
        page = null;
    }
    verifyAlerts(driver);
    driver.findElement(By.id("a2")).click();
    verifyAlerts(driver, getExpectedAlerts());
    if (driver instanceof HtmlUnitDriver) {
        final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertSame(page, secondPage);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) InputStream(java.io.InputStream) Page(com.gargoylesoftware.htmlunit.Page) URL(java.net.URL) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 37 with Alerts

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

the class HtmlAreaTest method click_javascriptUrlMixedCase.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("clicked")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void click_javascriptUrlMixedCase() throws Exception {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
        final byte[] directBytes = IOUtils.toByteArray(is);
        final URL urlImage = new URL(URL_FIRST, "img.jpg");
        final List<NameValuePair> emptyList = Collections.emptyList();
        getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
    }
    final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + "  <area href='javasCRIpT:alert(\"clicked\")' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Page page;
    if (driver instanceof HtmlUnitDriver) {
        page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
    } else {
        page = null;
    }
    verifyAlerts(driver);
    driver.findElement(By.id("a2")).click();
    verifyAlerts(driver, getExpectedAlerts());
    if (driver instanceof HtmlUnitDriver) {
        final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertSame(page, secondPage);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) InputStream(java.io.InputStream) Page(com.gargoylesoftware.htmlunit.Page) URL(java.net.URL) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 38 with Alerts

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

the class HtmlAreaTest method isDisplayedEmptyCircle.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = { "false", "false", "true" }, IE = { "false", "false", "false" })
@HtmlUnitNYI(IE = { "false", "false", "true" })
public void isDisplayedEmptyCircle() throws Exception {
    final String html = "<html><head><title>Page A</title></head>\n" + "<body>\n" + "  <img id='myImg' usemap='#imgmap'" + " src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAA" + "HElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='>\n" + "  <map id='myMap' name='imgmap'>\n" + "    <area id='myArea1' shape='circle' coords='0,0,0'>\n" + "    <area id='myArea2' shape='circle' >\n" + "    <area id='myArea3' shape='circle' coords='0,0,0.8'>\n" + "  </map>\n" + "</body></html>";
    final String[] expected = getExpectedAlerts();
    setExpectedAlerts(new String[] {});
    final WebDriver driver = loadPage2(html);
    boolean displayed = driver.findElement(By.id("myArea1")).isDisplayed();
    assertEquals(Boolean.parseBoolean(expected[0]), displayed);
    displayed = driver.findElement(By.id("myArea2")).isDisplayed();
    assertEquals(Boolean.parseBoolean(expected[1]), displayed);
    displayed = driver.findElement(By.id("myArea3")).isDisplayed();
    assertEquals(Boolean.parseBoolean(expected[2]), displayed);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 39 with Alerts

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

the class HtmlBackgroundSoundTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "[object HTMLUnknownElement]", IE = "[object HTMLBGSoundElement]")
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" + "  <bgsound id='myId'/>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver && getExpectedAlerts()[0].contains("Sound")) {
        assertTrue(HtmlBackgroundSound.class.isInstance(toHtmlElement(driver.findElement(By.id("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 40 with Alerts

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

the class FocusableElement2Test method bodyLoad.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "body", "active: body", "onload", "active: body", "onfocus:[object Window]", "active: body" }, CHROME = { "body", "active: body", "onload", "active: body" }, EDGE = { "body", "active: body", "onload", "active: body" }, IE = { "body", "active: null", "onfocusin:body", "active: body", "onload", "active: body", "onfocus:[object Window]", "active: body" })
@HtmlUnitNYI(FF = { "body", "active: body", "onload", "active: body" }, FF_ESR = { "body", "active: body", "onload", "active: body" }, IE = { "body", "active: body", "onload", "active: body" })
public // TODO FF & FF68 fail due to wrong body vs. window event handling
void bodyLoad() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <script>\n" + logger() + "      function test() {\n" + "        log('onload');\n" + "      }\n" + "    </script>\n" + "  </head>\n" + "  <body id='body' onload='test()' " + logEvents("") + ">\n" + "    <script>\n" + "      log('body');" + "    </script>\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)

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