use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class Location2Test method locationAfterOpenClosePopup.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("§§URL§§test.html")
// real browsers don't show the alert, since it is quickly closed through JavaScript
@NotYetImplemented
@BuggyWebDriver(IE = "§§URL§§")
public void locationAfterOpenClosePopup() throws Exception {
final String html = "<html>\n" + "<head>\n" + " <title>test</title>\n" + " <script>\n" + " function test() {\n" + " var win = window.open('" + URL_SECOND + "','test','',true);\n" + " win.close();\n" + " location.href = 'test.html';\n" + " }\n" + " </script>\n" + "</head>\n" + "<body>\n" + " <button id='click' onclick='test()'>Test</button>\n" + "</body>\n" + "</html>";
final String popup = "<html>\n" + "<head>\n" + " <title>popup with script</title>\n" + " <script>\n" + " alert('the root of all evil');\n" + " </script>\n" + "</head>\n" + "<body>Popup</body>\n" + "</html>";
final String target = "<html>\n" + "<head>\n" + " <title>target</title>\n" + "</head>\n" + "<body>Target</body>\n" + "</html>";
getMockWebConnection().setResponse(URL_SECOND, popup);
getMockWebConnection().setResponse(new URL(URL_FIRST, "test.html"), target);
expandExpectedAlertsVariables(URL_FIRST);
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("click")).click();
try {
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
} finally {
// TODO [IE] when run with real IE the window is closed and all following tests are broken
releaseResources();
shutDownAll();
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class Location2Test method reloadPost.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "3", "null", "§§URL§§/" }, CHROME = { "3", "§§URL§§", "§§URL§§/second/a.html?urlParam=urlVal" }, EDGE = { "3", "§§URL§§", "§§URL§§/second/a.html?urlParam=urlVal" }, FF = { "3", "§§URL§§", "§§URL§§/" }, FF_ESR = { "3", "§§URL§§", "§§URL§§/" })
// FF opens a confirmation window for the post
@BuggyWebDriver(FF_ESR = { "2", "null", "§§URL§§/" })
public void reloadPost() throws Exception {
final String form = "<html>\n" + " <head></head>\n" + " <body>\n" + " <form method='POST' name='form' action='" + URL_SECOND + "a.html?urlParam=urlVal'>\n" + " <input type='hidden' name='p1' value='seven'>\n" + " <input type='hidden' name='p2' value=''>\n" + " <input type='submit' id='enter' name='sub' value='ok'>\n" + " </form>\n" + " </body>\n" + "</html>";
final String html = "<html>\n" + " <head></head>\n" + " <body>\n" + " <a href='javascript:window.location.reload(true);' id='link'>reload</a>\n" + " </body>\n" + "</html>";
getMockWebConnection().setDefaultResponse(html);
final WebDriver driver = loadPage2(form, URL_FIRST);
assertEquals(1, getMockWebConnection().getRequestCount());
driver.findElement(By.id("enter")).click();
assertEquals(2, getMockWebConnection().getRequestCount());
driver.findElement(By.id("link")).click();
// works only in the debugger
try {
driver.switchTo().alert().accept();
} catch (final NoAlertPresentException e) {
// ignore
}
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), getMockWebConnection().getRequestCount());
assertEquals(HttpMethod.POST, getMockWebConnection().getLastWebRequest().getHttpMethod());
assertEquals(URL_SECOND + "a.html?urlParam=urlVal", getMockWebConnection().getLastWebRequest().getUrl());
final List<NameValuePair> params = getMockWebConnection().getLastWebRequest().getRequestParameters();
assertEquals(4, params.size());
assertEquals("p1", params.get(0).getName());
assertEquals("seven", params.get(0).getValue());
assertEquals("sub", params.get(1).getName());
assertEquals("ok", params.get(1).getValue());
assertEquals("p2", params.get(2).getName());
assertEquals("", params.get(2).getValue());
assertEquals("urlParam", params.get(3).getName());
assertEquals("urlVal", params.get(3).getValue());
expandExpectedAlertsVariables("http://localhost:" + PORT);
final Map<String, String> additionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
assertEquals(getExpectedAlerts()[1], "" + additionalHeaders.get(HttpHeader.ORIGIN));
assertEquals(getExpectedAlerts()[2], additionalHeaders.get(HttpHeader.REFERER));
assertEquals("localhost:" + PORT, additionalHeaders.get(HttpHeader.HOST));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method doubleClick.
/**
* FF behaves is different.
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = "click href click doubleClick href ", IE = "click href click doubleClick ")
@BuggyWebDriver(FF = "click doubleClick click href href ", FF_ESR = "click doubleClick click href href ")
@NotYetImplemented
public void doubleClick() throws Exception {
final String html = "<html>\n" + "<body>\n" + " <a id='myAnchor' " + "href=\"javascript:document.getElementById('myTextarea').value+='href ';void(0);\" " + "onClick=\"document.getElementById('myTextarea').value+='click ';\" " + "onDblClick=\"document.getElementById('myTextarea').value+='doubleClick ';\">foo</a>\n" + " <textarea id='myTextarea'></textarea>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
final Actions action = new Actions(driver);
action.doubleClick(driver.findElement(By.id("myAnchor")));
action.perform();
assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("myTextarea")).getAttribute("value"));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method clickNestedOptionElement.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("§§URL§§page2.html")
@BuggyWebDriver(FF = "§§URL§§", FF_ESR = "§§URL§§")
public void clickNestedOptionElement() throws Exception {
final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" + " <select size=2>\n" + " <option id='theOption'>test</option>\n" + " </select>\n" + " </a>\n" + "</body></html>";
expandExpectedAlertsVariables(URL_FIRST);
getMockWebConnection().setDefaultResponse("");
final WebDriver driver = loadPage2(html);
final WebElement option = driver.findElement(By.id("theOption"));
assertEquals("option", option.getTagName());
option.click();
assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlApplet2Test method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "[object HTMLUnknownElement]", "[object HTMLCollection]", "0", "undefined" }, IE = { "[object HTMLAppletElement]", "[object HTMLCollection]", "1", "[object HTMLAppletElement]" })
@BuggyWebDriver(IE = { "The page you are viewing uses Java. More information on Java support " + "is available from the Microsoft website.", "[object HTMLAppletElement]", "[object HTMLCollection]", "1", "[object HTMLAppletElement]" })
public void simpleScriptable() throws Exception {
final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " alert(document.getElementById('myId'));\n" + " alert(document.applets);\n" + " alert(document.applets.length);\n" + " alert(document.applets[0]);\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <applet id='myId'></applet>\n" + "</body></html>";
final WebDriver driver = loadPageWithAlerts2(html);
if (driver instanceof HtmlUnitDriver) {
if (getBrowserVersion().isChrome() || getBrowserVersion().isFirefox() || getBrowserVersion().isEdge()) {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertTrue(HtmlUnknownElement.class.isInstance(page.getHtmlElementById("myId")));
} else {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertTrue(HtmlApplet.class.isInstance(page.getHtmlElementById("myId")));
}
}
}
Aggregations