Search in sources :

Example 31 with Alerts

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

the class HtmlAnchorTest method href_js_escaping.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts({ "hi", "%28%29" })
public void href_js_escaping() throws Exception {
    final String html = "<html><head>\n<script>\n" + "  function sayHello(text) {\n" + "    alert(text);\n" + "  }\n" + "</script></head>\n" + "<body>\n" + "  <a id='myAnchor' href=\"javascript:sayHello%28'hi'%29\">My Link</a>\n" + "  <input id='myButton' type=button onclick=\"javascript:sayHello('%28%29')\" value='My Button'>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myAnchor")).click();
    verifyAlerts(driver, getExpectedAlerts()[0]);
    driver.findElement(By.id("myButton")).click();
    verifyAlerts(driver, getExpectedAlerts()[1]);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 32 with Alerts

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

the class HtmlAnchorTest method clickNestedButtonElement.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("§§URL§§page2.html")
public void clickNestedButtonElement() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "  <a href='page2.html'>\n" + "    <button id='theButton'></button>\n" + "  </a>\n" + "</body></html>";
    expandExpectedAlertsVariables(URL_FIRST);
    getMockWebConnection().setDefaultResponse("");
    final WebDriver driver = loadPage2(html);
    final WebElement button = driver.findElement(By.id("theButton"));
    assertEquals("button", button.getTagName());
    button.click();
    assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 33 with Alerts

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

the class HtmlAnchorTest method clickNestedSubmitElement.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("page2.html")
public void clickNestedSubmitElement() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "  <a href='page2.html'>\n" + "    <input type='submit' id='theInput' />\n" + "  </a>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse("");
    final WebDriver driver = loadPage2(html);
    final WebElement input = driver.findElement(By.id("theInput"));
    assertEquals("input", input.getTagName());
    input.click();
    assertEquals(URL_FIRST + getExpectedAlerts()[0], driver.getCurrentUrl());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 34 with Alerts

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

the class HtmlAnchorTest method click_refererHeader.

/**
 * Tests the 'Referer' HTTP header.
 * @throws Exception on test failure
 */
@Test
@Alerts("§§URL§§index.html?test")
public void click_refererHeader() throws Exception {
    final String firstContent = "<html><head><title>Page A</title></head>\n" + "<body><a href='" + URL_SECOND + "' id='link'>link</a></body>\n" + "</html>";
    final String secondContent = "<html><head><title>Page B</title></head>\n" + "<body></body>\n" + "</html>";
    expandExpectedAlertsVariables(URL_FIRST);
    final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
    getMockWebConnection().setResponse(indexUrl, firstContent);
    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
    driver.findElement(By.id("link")).click();
    assertEquals(2, getMockWebConnection().getRequestCount());
    final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
    assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get(HttpHeader.REFERER));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 35 with Alerts

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

the class HtmlAnchorTest method controlClick_refererHeader.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("§§URL§§index.html?test")
public void controlClick_refererHeader() throws Exception {
    final String firstContent = "<html><head><title>Page A</title></head>\n" + "<body>\n" + "  <a href='" + URL_SECOND + "' id='link'>link</a>\n" + "</body>\n" + "</html>";
    final String secondContent = "<html><head><title>Page B</title></head>\n" + "<body></body>\n" + "</html>";
    expandExpectedAlertsVariables(URL_FIRST);
    final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
    getMockWebConnection().setResponse(indexUrl, firstContent);
    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
    new Actions(driver).keyDown(Keys.CONTROL).click(driver.findElement(By.id("link"))).keyUp(Keys.CONTROL).build().perform();
    Thread.sleep(DEFAULT_WAIT_TIME / 10);
    assertEquals(2, getMockWebConnection().getRequestCount());
    final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
    assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get(HttpHeader.REFERER));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Actions(org.openqa.selenium.interactions.Actions) URL(java.net.URL) 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