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