Search in sources :

Example 51 with Alerts

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

the class HtmlButton2Test method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLButtonElement]")
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" + "<button id='myId'>OK</button>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertTrue(HtmlButton.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 52 with Alerts

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

the class HtmlButton2Test method typeUnknown.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("2")
public void typeUnknown() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n" + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "    <button type='unknown' id='myButton'>Explicit Submit</button>\n" + "  </form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse(secondContent);
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();
    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    if (expectedReqCount > 1) {
        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 53 with Alerts

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

the class DomElementTest method getElementsByTagName.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts({ "2", "2" })
public void getElementsByTagName() throws Exception {
    final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "function test() {\n" + "  log(document.f1.getElementsByTagName('input').length);\n" + "  log(document.f1.getElementsByTagName('INPUT').length);\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" + "  <form name='f1'>\n" + "    <input>\n" + "    <INPUT>\n" + "  </form>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final WebWindow webWindow = getWebWindowOf((HtmlUnitDriver) driver);
        final HtmlPage page = (HtmlPage) webWindow.getEnclosedPage();
        assertEquals(2, page.getForms().get(0).getElementsByTagName("input").size());
        assertEquals(2, page.getForms().get(0).getElementsByTagName("INPUT").size());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 54 with Alerts

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

the class HtmlCaptionTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLTableCaptionElement]")
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" + "  <table>\n" + "    <caption id='myId'/>\n" + "  </table>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertTrue(HtmlCaption.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 55 with Alerts

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

the class HtmlCheckBoxInput2Test method checkedAttribute.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts({ "true", "null", "false", "", "false", "yes" })
public void checkedAttribute() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    var checkbox = document.getElementById('c1');\n" + "    log(checkbox.checked);\n" + "    log(checkbox.getAttribute('checked'));\n" + "    checkbox = document.getElementById('c2');\n" + "    log(checkbox.checked);\n" + "    log(checkbox.getAttribute('checked'));\n" + "    checkbox = document.getElementById('c3');\n" + "    log(checkbox.checked);\n" + "    log(checkbox.getAttribute('checked'));\n" + "  }\n" + "</script>\n" + "</head><body>\n" + "<form>\n" + "  <input type='checkbox' id='c1' name='radar' value='initial'>\n" + "  <input type='checkbox' id='c2' name='radar' value='initial' checked>\n" + "  <input type='checkbox' id='c3' name='radar' value='initial' checked='yes'>\n" + "</form>\n" + "  <button id='clickMe' onClick='test()'>do it</button>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("c1")).click();
    driver.findElement(By.id("c2")).click();
    driver.findElement(By.id("c3")).click();
    driver.findElement(By.id("clickMe")).click();
    verifyTitle2(driver, getExpectedAlerts());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) 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