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());
}
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());
}
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());
}
}
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")));
}
}
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")));
}
}
Aggregations