use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver 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());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlAreaTest method thisInJavascriptHref.
/**
* In action "this" should be the window and not the area.
* @throws Exception if the test fails
*/
@Test
@Alerts("true")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void thisInJavascriptHref() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_FIRST, "img.jpg");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
}
final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + " <area href='javascript:alert(this == window)' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map></body></html>";
final WebDriver driver = loadPage2(html);
final Page page;
if (driver instanceof HtmlUnitDriver) {
page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
} else {
page = null;
}
verifyAlerts(driver);
driver.findElement(By.id("a2")).click();
verifyAlerts(driver, getExpectedAlerts());
if (driver instanceof HtmlUnitDriver) {
final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertSame(page, secondPage);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlAreaTest method click_javascriptUrlMixedCase.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("clicked")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void click_javascriptUrlMixedCase() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_FIRST, "img.jpg");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
}
final String html = "<html><head><title>foo</title></head><body>\n" + "<img src='img.jpg' width='145' height='126' usemap='#somename'>\n" + "<map name='somename'>\n" + " <area href='javasCRIpT:alert(\"clicked\")' id='a2' shape='rect' coords='0,0,30,30'/>\n" + "</map>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
final Page page;
if (driver instanceof HtmlUnitDriver) {
page = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
} else {
page = null;
}
verifyAlerts(driver);
driver.findElement(By.id("a2")).click();
verifyAlerts(driver, getExpectedAlerts());
if (driver instanceof HtmlUnitDriver) {
final Page secondPage = getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertSame(page, secondPage);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class HtmlDateInputTest method typeInto.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("2018-03-22")
@BuggyWebDriver(CHROME = "80322-02-01", EDGE = "80322-02-01")
public void typeInto() throws Exception {
final String html = "<html>\n" + "<head>\n" + "<script>\n" + " function test() {\n" + " var input = document.getElementById('input');\n" + " alert(input.value);\n" + " }\n" + "</script>\n" + "</head>\n" + "<body>\n" + " <input id='input' type='date'>\n" + " <button id='tester' onclick='test()'>Test</button>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("input")).sendKeys("2018-03-22");
driver.findElement(By.id("tester")).click();
verifyAlerts(driver, getExpectedAlerts());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver in project htmlunit by HtmlUnit.
the class StorageTest method localStorageShouldBeShared.
/**
* Note that this test will work only with WebDriver instances that support starting 2 instances in parallel.
* @throws Exception if the test fails
*/
@Test
@Alerts("I was here")
@BuggyWebDriver(CHROME = "", EDGE = "", FF = "", FF_ESR = "")
// But when executed manually the LocalStorage is shared.
@NotYetImplemented
public // TODO somehow persist the LocalStorage
void localStorageShouldBeShared() throws Exception {
final String html1 = "<html><body>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "try {\n" + " localStorage.clear();\n" + " localStorage.setItem('hello', 'I was here');\n" + "} catch(e) { log('exception'); }\n" + "</script></body></html>";
final WebDriver driver = loadPage2(html1);
final List<String> alerts = getCollectedAlerts(driver);
final String html2 = "<html><body><script>\n" + "try {\n" + " log(localStorage.getItem('hello'));\n" + "} catch(e) { log('exception'); }\n" + "</script></body></html>";
getMockWebConnection().setResponse(URL_FIRST, html2);
releaseResources();
// we have to control 2nd driver by ourself
WebDriver driver2 = null;
try {
driver2 = buildWebDriver();
driver2.get(URL_FIRST.toString());
final List<String> newAlerts = getCollectedAlerts(driver2);
alerts.addAll(newAlerts);
assertEquals(getExpectedAlerts(), alerts);
} finally {
if (!(driver2 instanceof HtmlUnitDriver)) {
shutDownAll();
}
}
}
Aggregations