Search in sources :

Example 36 with BuggyWebDriver

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

the class HTMLOptionElement2Test method click2.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "opt-a; opt-b", CHROME = "opt-b")
@BuggyWebDriver("opt-a; b;")
@NotYetImplemented
public // what happens when running the test manually in the browser.
void click2() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + "  function log(x) {\n" + "    document.getElementById('log_').value += x + '; ';\n" + "  }\n" + "  function init() {\n" + "    s = document.getElementById('s');\n" + "    s.addEventListener('click', handle, false);\n" + "  }\n" + "  function handle(event) {\n" + "    log(s.options[s.selectedIndex].value);\n" + "  }\n" + "</script></head>\n" + "<body onload='init()'>\n" + "<form>\n" + "  <textarea id='log_' rows='4' cols='50'></textarea>\n" + "  <select id='s'>\n" + "    <option value='opt-a'>A</option>\n" + "    <option id='opt-b' value='b'>B</option>\n" + "    <option value='opt-c'>C</option>\n" + "  </select>\n" + "</form>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("s")).click();
    driver.findElement(By.id("opt-b")).click();
    final List<String> alerts = new LinkedList<>();
    final WebElement log = driver.findElement(By.id("log_"));
    alerts.add(log.getAttribute("value").trim());
    assertEquals(getExpectedAlerts(), alerts);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) LinkedList(java.util.LinkedList) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 37 with BuggyWebDriver

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

the class KeyboardEventTest method which.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "keydown:16,0,16,Shift,undefined,ShiftLeft,true", "keydown:65,0,65,A,undefined,KeyA,true", "keypress:65,65,65,A,undefined,KeyA,true", "keyup:65,0,65,A,undefined,KeyA,true", "keyup:16,0,16,Shift,undefined,ShiftLeft,false", "keydown:65,0,65,a,undefined,KeyA,false", "keypress:97,97,97,a,undefined,KeyA,false", "keyup:65,0,65,a,undefined,KeyA,false", "keydown:190,0,190,.,undefined,Period,false", "keypress:46,46,46,.,undefined,Period,false", "keyup:190,0,190,.,undefined,Period,false", "keydown:13,0,13,Enter,undefined,Enter,false", "keypress:13,13,13,Enter,undefined,Enter,false", "keyup:13,0,13,Enter,undefined,Enter,false" }, IE = { "keydown:16,0,16,Shift,,undefined,true", "keydown:65,0,65,A,A,undefined,true", "keypress:65,65,65,A,A,undefined,true", "keyup:65,0,65,A,A,undefined,true", "keyup:16,0,16,Shift,,undefined,false", "keydown:65,0,65,a,a,undefined,false", "keypress:97,97,97,a,a,undefined,false", "keyup:65,0,65,a,a,undefined,false", "keydown:190,0,190,.,.,undefined,false", "keypress:46,46,46,.,.,undefined,false", "keyup:190,0,190,.,.,undefined,false", "keydown:13,0,13,Enter,\\n,undefined,false", "keypress:13,13,13,Enter,\\n,undefined,false", "keyup:13,0,13,Enter,\\n,undefined,false" })
// https://github.com/SeleniumHQ/selenium/issues/2531
@BuggyWebDriver(CHROME = { "keydown:16,0,16,Shift,undefined,ShiftLeft,false", "keydown:65,0,65,A,undefined,KeyA,true", "keypress:65,65,65,A,undefined,KeyA,true", "keyup:65,0,65,A,undefined,KeyA,true", "keyup:16,0,16,Shift,undefined,ShiftLeft,false", "keydown:65,0,65,a,undefined,KeyA,false", "keypress:97,97,97,a,undefined,KeyA,false", "keyup:65,0,65,a,undefined,KeyA,false", "keydown:190,0,190,.,undefined,Period,false", "keypress:46,46,46,.,undefined,Period,false", "keyup:190,0,190,.,undefined,Period,false", "keydown:13,0,13,Enter,undefined,Enter,false", "keypress:13,13,13,Enter,undefined,Enter,false", "keyup:13,0,13,Enter,undefined,Enter,false" }, EDGE = { "keydown:16,0,16,Shift,undefined,ShiftLeft,false", "keydown:65,0,65,A,undefined,KeyA,true", "keypress:65,65,65,A,undefined,KeyA,true", "keyup:65,0,65,A,undefined,KeyA,true", "keyup:16,0,16,Shift,undefined,ShiftLeft,false", "keydown:65,0,65,a,undefined,KeyA,false", "keypress:97,97,97,a,undefined,KeyA,false", "keyup:65,0,65,a,undefined,KeyA,false", "keydown:190,0,190,.,undefined,Period,false", "keypress:46,46,46,.,undefined,Period,false", "keyup:190,0,190,.,undefined,Period,false", "keydown:13,0,13,Enter,undefined,Enter,false", "keypress:13,13,13,Enter,undefined,Enter,false", "keyup:13,0,13,Enter,undefined,Enter,false" }, FF_ESR = { "keydown:65,0,65,A,undefined,,false", "keypress:65,65,65,A,undefined,,false", "keyup:65,0,65,A,undefined,,false", "keydown:65,0,65,a,undefined,,false", "keypress:97,97,97,a,undefined,,false", "keyup:65,0,65,a,undefined,,false", "keydown:190,0,190,.,undefined,,false", "keypress:46,46,46,.,undefined,,false", "keyup:190,0,190,.,undefined,,false", "keydown:13,0,13,Enter,undefined,,false", "keypress:13,13,13,Enter,undefined,,false", "keyup:13,0,13,Enter,undefined,,false" }, FF = { "keydown:65,0,65,A,undefined,,false", "keypress:65,65,65,A,undefined,,false", "keyup:65,0,65,A,undefined,,false", "keydown:65,0,65,a,undefined,,false", "keypress:97,97,97,a,undefined,,false", "keyup:65,0,65,a,undefined,,false", "keydown:190,0,190,.,undefined,,false", "keypress:46,46,46,.,undefined,,false", "keyup:190,0,190,.,undefined,,false", "keydown:13,0,13,Enter,undefined,,false", "keypress:13,13,13,Enter,undefined,,false", "keyup:13,0,13,Enter,undefined,,false" }, IE = { "keydown:16,0,16,Shift,,undefined,false", "keydown:65,0,65,A,A,undefined,false", "keypress:65,65,65,A,A,undefined,false", "keyup:65,0,65,a,a,undefined,false", "keyup:16,0,16,Shift,,undefined,false", "keydown:65,0,65,a,a,undefined,false", "keypress:97,97,97,a,a,undefined,false", "keyup:65,0,65,a,a,undefined,false", "keydown:190,0,190,.,.,undefined,false", "keypress:46,46,46,.,.,undefined,false", "keyup:190,0,190,.,.,undefined,false", "keydown:13,0,13,Enter,\\n,undefined,false", "keypress:13,13,13,\\r,\\r,undefined,false", "keyup:13,0,13,Enter,\\n,undefined,false" })
public void which() throws Exception {
    final String html = "<html><head></head><body>\n" + "<input type='text' id='keyId'>\n" + "<script>\n" + "function handler(e) {\n" + "  e = e ? e : window.event;\n" + "  var log = e.type + ':' + e.keyCode + ',' + e.charCode + ',' + e.which + ',' " + "+ e.key + ',' + e.char + ',' + e.code + ',' + e.shiftKey;\n" + "  log = log.replace(/\\r/g, '\\\\r');\n" + "  log = log.replace(/\\n/g, '\\\\n');\n" + "  document.getElementById('myTextarea').value += log + '\\n';" + "}\n" + "document.getElementById('keyId').onkeyup = handler;\n" + "document.getElementById('keyId').onkeydown = handler;\n" + "document.getElementById('keyId').onkeypress = handler;\n" + "</script>\n" + "<textarea id='myTextarea' cols=80 rows=20></textarea>\n" + "</body></html>";
    final String keysToSend = "Aa." + Keys.RETURN;
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("keyId")).sendKeys(keysToSend);
    final String[] actual = driver.findElement(By.id("myTextarea")).getAttribute("value").split("\n");
    assertEquals(Arrays.asList(getExpectedAlerts()).toString(), Arrays.asList(actual).toString());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 38 with BuggyWebDriver

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

the class HtmlAreaTest method referer.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("§§URL§§")
@BuggyWebDriver(FF = "WebDriverException", FF_ESR = "WebDriverException", IE = "WebDriverException")
public void referer() throws Exception {
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = createWebClient("");
    driver.get(URL_FIRST.toExternalForm());
    try {
        driver.findElement(By.id("third")).click();
        final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
        assertEquals(getExpectedAlerts()[0], lastAdditionalHeaders.get(HttpHeader.REFERER));
    } catch (final WebDriverException e) {
        e.printStackTrace();
        assertEquals(getExpectedAlerts()[0], "WebDriverException");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 39 with BuggyWebDriver

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

the class HtmlAreaTest method click_javascriptUrlLeadingWhitespace.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("clicked")
@BuggyWebDriver(FF = "Todo", FF_ESR = "Todo")
public void click_javascriptUrlLeadingWhitespace() 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></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 40 with BuggyWebDriver

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

the class HtmlElement2Test method typeAtEndOfEditableDivWithParagraphInside.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("Hello-world")
@BuggyWebDriver(FF = "-worldHello", FF_ESR = "-worldHello")
public void typeAtEndOfEditableDivWithParagraphInside() throws Exception {
    final String html = "<html><head><script>\n" + "  function test() {\n" + "    alert(document.getElementById('myInput').value);\n" + "  }\n" + "</script></head>\n" + "<body>\n" + "  <input id='myButton' type='button' onclick='test()'>\n" + "  <div id='myInput' contenteditable='true'><p>Hello</p></div>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement div = driver.findElement(By.id("myInput"));
    div.sendKeys("-world");
    assertEquals(getExpectedAlerts()[0], div.getText());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) 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