Search in sources :

Example 41 with BuggyWebDriver

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

the class MutationObserverTest method attributeValue2.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("[object HTMLHeadingElement]-attributes")
@BuggyWebDriver(FF = "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLHeadingElement]-attributes", FF_ESR = "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLInputElement]-attributes\n" + "[object HTMLHeadingElement]-attributes")
public void attributeValue2() throws Exception {
    final String html = "<html><head><script>\n" + "  function makeRed() {\n" + "    document.getElementById('headline').setAttribute('style', 'color: red');\n" + "  }\n" + "  function print(mutation) {\n" + "    log(mutation.target + '-' + mutation.type);\n" + "  }\n" + "  function log(x) {\n" + "    document.getElementById('log').value += x + '\\n';\n" + "  }\n" + "  function test() {\n" + "    var mobs = new MutationObserver(function(mutations) {\n" + "      mutations.forEach(print)\n" + "    });\n" + "    mobs.observe(document.getElementById('container'), {\n" + "      attributes: true,\n" + "      childList: true,\n" + "      characterData: true,\n" + "      subtree: true\n" + "    });\n" + "    document.addEventListener('beforeunload', function() {\n" + "      mobs.disconnect();\n" + "    });\n" + "  }\n" + "</script></head><body onload='test()'>\n" + "  <div id='container'>\n" + "    <h1 id='headline' style='font-style: italic'>Some headline</h1>\n" + "    <input id='id1' type='button' onclick='makeRed()' value='Make Red'>\n" + "  </div>\n" + "  <textarea id='log' cols='80' rows='40'></textarea>\n" + "</body></html>\n";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("id1")).click();
    final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
    assertEquals(String.join("\n", getExpectedAlerts()), text);
}
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 42 with BuggyWebDriver

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

the class BrowserVersionClassRunner method setAlerts.

private void setAlerts(final WebTestCase testCase, final Method method) {
    final Alerts alerts = method.getAnnotation(Alerts.class);
    String[] expectedAlerts = {};
    if (alerts != null) {
        expectedAlerts = NO_ALERTS_DEFINED;
        if (isDefined(alerts.value())) {
            expectedAlerts = alerts.value();
        } else {
            if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER) {
                expectedAlerts = firstDefined(alerts.IE(), alerts.DEFAULT());
            } else if (browserVersion_ == BrowserVersion.EDGE) {
                expectedAlerts = firstDefined(alerts.EDGE(), alerts.DEFAULT());
            } else if (browserVersion_ == BrowserVersion.FIREFOX_ESR) {
                expectedAlerts = firstDefined(alerts.FF_ESR(), alerts.DEFAULT());
            } else if (browserVersion_ == BrowserVersion.FIREFOX) {
                expectedAlerts = firstDefined(alerts.FF(), alerts.DEFAULT());
            } else if (browserVersion_ == BrowserVersion.CHROME) {
                expectedAlerts = firstDefined(alerts.CHROME(), alerts.DEFAULT());
            }
        }
    }
    if (isRealBrowser()) {
        final BuggyWebDriver buggyWebDriver = method.getAnnotation(BuggyWebDriver.class);
        if (buggyWebDriver != null) {
            if (isDefined(buggyWebDriver.value())) {
                expectedAlerts = buggyWebDriver.value();
            } else {
                if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER) {
                    expectedAlerts = firstDefinedOrGiven(expectedAlerts, buggyWebDriver.IE(), buggyWebDriver.DEFAULT());
                } else if (browserVersion_ == BrowserVersion.EDGE) {
                    expectedAlerts = firstDefinedOrGiven(expectedAlerts, buggyWebDriver.EDGE(), buggyWebDriver.DEFAULT());
                } else if (browserVersion_ == BrowserVersion.FIREFOX_ESR) {
                    expectedAlerts = firstDefinedOrGiven(expectedAlerts, buggyWebDriver.FF_ESR(), buggyWebDriver.DEFAULT());
                } else if (browserVersion_ == BrowserVersion.FIREFOX) {
                    expectedAlerts = firstDefinedOrGiven(expectedAlerts, buggyWebDriver.FF(), buggyWebDriver.DEFAULT());
                } else if (browserVersion_ == BrowserVersion.CHROME) {
                    expectedAlerts = firstDefinedOrGiven(expectedAlerts, buggyWebDriver.CHROME(), buggyWebDriver.DEFAULT());
                }
            }
        }
    } else {
        final HtmlUnitNYI htmlUnitNYI = method.getAnnotation(HtmlUnitNYI.class);
        if (htmlUnitNYI != null) {
            if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER) {
                expectedAlerts = firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.IE());
            } else if (browserVersion_ == BrowserVersion.EDGE) {
                expectedAlerts = firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.EDGE());
            } else if (browserVersion_ == BrowserVersion.FIREFOX_ESR) {
                expectedAlerts = firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF_ESR());
            } else if (browserVersion_ == BrowserVersion.FIREFOX) {
                expectedAlerts = firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF());
            } else if (browserVersion_ == BrowserVersion.CHROME) {
                expectedAlerts = firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.CHROME());
            }
        }
    }
    testCase.setExpectedAlerts(expectedAlerts);
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 43 with BuggyWebDriver

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

the class ExtJS22Test method debug_console.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("Hello from the Ext console.")
@BuggyWebDriver(IE = "Todo")
public void debug_console() throws Exception {
    final WebDriver driver = getPage("debug", "debug-console");
    final List<WebElement> anchors = driver.findElements(By.xpath("//a"));
    assertEquals(2, anchors.size());
    anchors.get(1).click();
    assertEquals(getExpectedAlerts()[0], driver.findElement(By.xpath("//div[starts-with(text(), 'Hello')][1]")).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