Search in sources :

Example 1 with BuggyWebDriver

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

Example 2 with BuggyWebDriver

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);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) InputStream(java.io.InputStream) Page(com.gargoylesoftware.htmlunit.Page) URL(java.net.URL) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 3 with BuggyWebDriver

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);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) InputStream(java.io.InputStream) Page(com.gargoylesoftware.htmlunit.Page) URL(java.net.URL) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 4 with BuggyWebDriver

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());
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 5 with BuggyWebDriver

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();
        }
    }
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)43 Test (org.junit.Test)42 WebDriver (org.openqa.selenium.WebDriver)41 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)35 WebElement (org.openqa.selenium.WebElement)15 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)11 Actions (org.openqa.selenium.interactions.Actions)8 LogEntries (org.openqa.selenium.logging.LogEntries)8 LogEntry (org.openqa.selenium.logging.LogEntry)8 Logs (org.openqa.selenium.logging.Logs)8 URL (java.net.URL)7 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)6 LinkedList (java.util.LinkedList)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)4 InputStream (java.io.InputStream)4 Page (com.gargoylesoftware.htmlunit.Page)3 Action (org.openqa.selenium.interactions.Action)3 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)2 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)1