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