Search in sources :

Example 26 with Alerts

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

the class CookieManager4Test method domain2.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("c4=4")
public void domain2() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "c1=1; Path=/"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "c2=2; Domain=host1." + DOMAIN + "; Path=/"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "c3=3; Domain=host2." + DOMAIN + "; Path=/"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "c4=4; Domain=" + DOMAIN + "; Path=/"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "c5=5; Domain=.org; Path=/"));
    final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "<p>Cookie Domain Test</p>\n" + "<script>\n" + "  location.replace('" + URL_HOST3 + "');\n" + "</script>\n" + "</body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE);
    final URL firstUrl = new URL(URL_HOST1);
    getMockWebConnection().setResponse(firstUrl, html, 200, "Ok", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(firstUrl);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) URL(java.net.URL) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 27 with Alerts

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

the class HtmlAnchorTest method clickNestedInputTextElement.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = "page2.html", IE = "")
public void clickNestedInputTextElement() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "  <a href='page2.html'>\n" + "    <input type='text' 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 28 with Alerts

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

the class HtmlAnchorTest method clickNestedRadioElement.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = "", FF = "page2.html", FF_ESR = "page2.html")
public void clickNestedRadioElement() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "  <a href='page2.html'>\n" + "    <input type='radio' id='theRadio' name='myRadio' value='Milk'>\n" + "  </a>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse("");
    final WebDriver driver = loadPage2(html);
    final WebElement radio = driver.findElement(By.id("theRadio"));
    assertEquals("input", radio.getTagName());
    radio.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 29 with Alerts

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

the class HtmlAnchorTest method encoding.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts({ "§§URL§§bug.html?h%C3%B6=G%C3%BCnter", "h\u00F6", "G\u00FCnter" })
public void encoding() throws Exception {
    final String href = "bug.html?" + URLEncoder.encode("h\u00F6", "UTF-8") + '=' + URLEncoder.encode("G\u00FCnter", "UTF-8");
    final String html = "<html>\n" + "<head>\n" + "  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + "</head>\n" + "<body>\n" + "  <a href='" + href + "' id='myLink'>Click me</a>\n" + "</body></html>";
    getMockWebConnection().setDefaultResponse(html, MimeType.TEXT_HTML, UTF_8);
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    driver.findElement(By.id("myLink")).click();
    assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
    final List<NameValuePair> requestedParams = getMockWebConnection().getLastWebRequest().getRequestParameters();
    assertEquals(1, requestedParams.size());
    assertEquals(getExpectedAlerts()[1], requestedParams.get(0).getName());
    assertEquals(getExpectedAlerts()[2], requestedParams.get(0).getValue());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 30 with Alerts

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

the class HtmlAnchorTest method shiftClick.

/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({ "1", "First" })
@BuggyWebDriver(IE = { "0", "Second" })
public void shiftClick() throws Exception {
    final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>Click Me</a>\n" + "</form></body></html>";
    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final WebDriver driver = loadPage2(html);
    final WebElement link = driver.findElement(By.linkText("Click Me"));
    final int windowsSize = driver.getWindowHandles().size();
    new Actions(driver).moveToElement(link).keyDown(Keys.SHIFT).click().keyUp(Keys.SHIFT).perform();
    Thread.sleep(100);
    assertEquals("Should have opened a new window", windowsSize + Integer.parseInt(getExpectedAlerts()[0]), driver.getWindowHandles().size());
    assertEquals("Should not have navigated away", getExpectedAlerts()[1], driver.getTitle());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) 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