Search in sources :

Example 76 with Alerts

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

the class HtmlSearchInputTest method maxLengthValidationValid.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts({ "1234", "§§URL§§second/", "2" })
public void maxLengthValidationValid() throws Exception {
    final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" + "<body>\n" + "  <form id='myForm' action='" + URL_SECOND + "' method='" + HttpMethod.POST + "'>\n" + "    <input type='search' maxlength='5' id='foo'>\n" + "    <button id='myButton' type='submit'>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().setResponse(URL_SECOND, secondContent);
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    final WebElement foo = driver.findElement(By.id("foo"));
    foo.sendKeys("1234");
    assertEquals(getExpectedAlerts()[0], foo.getAttribute("value"));
    // invalid data
    driver.findElement(By.id("myButton")).click();
    assertEquals(getExpectedAlerts()[1], getMockWebConnection().getLastWebRequest().getUrl());
    assertEquals(Integer.parseInt(getExpectedAlerts()[2]), getMockWebConnection().getRequestCount());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 77 with Alerts

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

the class HtmlSearchInputTest method minLengthValidationInvalid.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = { "1234", "§§URL§§", "1" }, IE = { "1234", "§§URL§§second/", "2" })
public void minLengthValidationInvalid() throws Exception {
    final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" + "<body>\n" + "  <form id='myForm' action='" + URL_SECOND + "' method='" + HttpMethod.POST + "'>\n" + "    <input type='search' minlength='5' id='foo'>\n" + "    <button id='myButton' type='submit'>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().setResponse(URL_SECOND, secondContent);
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    final WebElement foo = driver.findElement(By.id("foo"));
    foo.sendKeys("1234");
    assertEquals(getExpectedAlerts()[0], foo.getAttribute("value"));
    // invalid data
    driver.findElement(By.id("myButton")).click();
    assertEquals(getExpectedAlerts()[1], getMockWebConnection().getLastWebRequest().getUrl());
    assertEquals(Integer.parseInt(getExpectedAlerts()[2]), getMockWebConnection().getRequestCount());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 78 with Alerts

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

the class HtmlTable2Test method getVisibleText.

/**
 * Verifies getVisibleText().
 * @throws Exception if the test fails
 */
@Test
@Alerts("One Two\n1 2")
public void getVisibleText() throws Exception {
    final String htmlContent = "<html>\n" + "<head></head>\n" + "<body>\n" + "  <table id='tester'>" + "    <tr><th>One</th><th>Two</th></tr>" + "    <tr><td>1</td><td>2</td></tr>" + "  </table>\n" + "</body></html>";
    final WebDriver driver = loadPage2(htmlContent);
    final String text = driver.findElement(By.id("tester")).getText();
    assertEquals(getExpectedAlerts()[0], text);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertEquals(getExpectedAlerts()[0], page.getBody().getVisibleText());
    }
}
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 79 with Alerts

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

the class HtmlTableCellTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "[object HTMLTableCellElement]", "[object HTMLTableCellElement]" }, IE = { "[object HTMLTableDataCellElement]", "[object HTMLTableHeaderCellElement]" })
public void simpleScriptable() throws Exception {
    final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  function test() {\n" + "    log(document.getElementById('myId1'));\n" + "    log(document.getElementById('myId2'));\n" + "  }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "  <table>\n" + "    <tr>\n" + "      <td id='myId1'/>\n" + "      <th id='myId2'/>\n" + "    </tr>\n" + "  </table>\n" + "</body></html>";
    final WebDriver driver = loadPageVerifyTitle2(html);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertTrue(HtmlTableCell.class.isInstance(page.getHtmlElementById("myId1")));
        assertTrue(HtmlTableCell.class.isInstance(page.getHtmlElementById("myId2")));
    }
}
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 80 with Alerts

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

the class HtmlTableColumnTest method simpleScriptable.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("[object HTMLTableColElement]")
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" + "    <col 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(HtmlTableColumn.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