use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlBreakTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("[object HTMLBRElement]")
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" + " <br id='myId'>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver) {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertTrue(HtmlBreak.class.isInstance(page.getHtmlElementById("myId")));
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlButton2Test method typeUnknownExternal.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "2", IE = "1")
public void typeUnknownExternal() 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" + " </form>\n" + " <button type='unknown' id='myButton' form='myForm'>Explicit Submit</button>\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 HtmlButton2Test method submitWithoutTypeExternal.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "2", IE = "1")
public void submitWithoutTypeExternal() 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" + " </form>\n" + " <button id='myButton' form='myForm'>Implicit Submit</button>\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 HtmlButton2Test method defaultButtonType_StandardsCompliantBrowser.
/**
* According to the HTML spec, the default type for a button is "submit".
* IE is different than the HTML spec and has a default type of "button".
* @throws Exception if the test fails
*/
@Test
@Alerts({ "submit", "1", "button-pushme", "Second" })
public void defaultButtonType_StandardsCompliantBrowser() throws Exception {
final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form id='form1' action='" + URL_SECOND + "' method='post'>\n" + " <button name='button' id='button' value='pushme'>PushMe</button>\n" + "</form></body></html>";
final String secondContent = "<html><head><title>Second</title></head><body'></body></html>";
getMockWebConnection().setResponse(URL_SECOND, secondContent);
final WebDriver driver = loadPage2(firstContent);
final WebElement button = driver.findElement(By.id("button"));
assertEquals(getExpectedAlerts()[0], button.getAttribute("type"));
button.click();
final List<NameValuePair> params = getMockWebConnection().getLastParameters();
assertEquals(getExpectedAlerts()[1], "" + params.size());
if (params.size() > 0) {
assertEquals(getExpectedAlerts()[2], params.get(0).getName() + "-" + params.get(0).getValue());
}
assertTitle(driver, getExpectedAlerts()[3]);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlButton2Test method onclickDisablesSubmit.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "1", FF = "2", FF_ESR = "2", IE = "2")
public void onclickDisablesSubmit() throws Exception {
final String html = "<html>\n" + "<head>\n" + " <script type='text/javascript'>\n" + " function submitForm() {\n" + " document.deliveryChannelForm.submitBtn.disabled = true;\n" + " }\n" + " </script>\n" + "</head>\n" + "<body>\n" + " <form action='test' name='deliveryChannelForm'>\n" + " <button name='submitBtn' type='submit' onclick='submitForm();'>Save</button>\n" + " </form>\n" + "</body>\n" + "</html>";
getMockWebConnection().setDefaultResponse("");
final WebDriver webDriver = loadPage2(html);
final WebElement input = webDriver.findElement(By.name("submitBtn"));
input.click();
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), getMockWebConnection().getRequestCount());
}
Aggregations