Search in sources :

Example 46 with Alerts

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")));
    }
}
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 47 with Alerts

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 48 with Alerts

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 49 with Alerts

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]);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 50 with Alerts

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());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) 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