Search in sources :

Example 36 with HtmlUnitNYI

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

the class Window3Test method scrollEvents.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "document", "body" }, IE = "document")
@HtmlUnitNYI(IE = { "document", "body" })
public void scrollEvents() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head>\n" + "<script>\n" + "  function log(msg) {\n" + "    var ta = document.getElementById('myTextArea');\n" + "    ta.value += msg + '; ';\n" + "  }\n" + "  function test() {\n" + "    document.addEventListener('scroll', function(e) { log(\"document\") });\n" + "    window.scroll(10, 20);\n" + "  }\n" + "</script>\n" + "</head>\n" + "<body onload='test()' onscroll='log(\"body\")'>\n" + "  <div onscroll='log(\"div\")' style='height: 1000px;'></div>\n" + "  <textarea id='myTextArea' cols='80' rows='30'></textarea>\n" + "</body>\n" + "</html>";
    final WebDriver driver = loadPage2(html);
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 37 with HtmlUnitNYI

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

the class ElementOwnPropertiesTest method collectStatistics.

private static void collectStatistics(final BrowserVersion browserVersion, final DefaultCategoryDataset dataset, final StringBuilder html, final int[] counts) {
    final Method[] methods = ElementOwnPropertiesTest.class.getMethods();
    Arrays.sort(methods, Comparator.comparing(Method::getName));
    for (final Method method : methods) {
        if (method.isAnnotationPresent(Test.class)) {
            final Alerts alerts = method.getAnnotation(Alerts.class);
            String[] expectedAlerts = {};
            if (BrowserVersionClassRunner.isDefined(alerts.value())) {
                expectedAlerts = alerts.value();
            }
            if (browserVersion == BrowserVersion.INTERNET_EXPLORER) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.IE(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.EDGE) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.EDGE(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.FIREFOX_ESR) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.FF_ESR(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.FIREFOX) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.FF(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.CHROME) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.CHROME(), alerts.DEFAULT());
            }
            final HtmlUnitNYI htmlUnitNYI = method.getAnnotation(HtmlUnitNYI.class);
            String[] nyiAlerts = {};
            if (htmlUnitNYI != null) {
                if (browserVersion == BrowserVersion.INTERNET_EXPLORER) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.IE());
                } else if (browserVersion == BrowserVersion.EDGE) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.EDGE());
                } else if (browserVersion == BrowserVersion.FIREFOX_ESR) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF_ESR());
                } else if (browserVersion == BrowserVersion.FIREFOX) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF());
                } else if (browserVersion == BrowserVersion.CHROME) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.CHROME());
                }
            }
            final List<String> realProperties = stringAsArray(String.join(",", expectedAlerts));
            final List<String> simulatedProperties = stringAsArray(String.join(",", nyiAlerts));
            final List<String> erroredProperties = new ArrayList<>(simulatedProperties);
            erroredProperties.removeAll(realProperties);
            final List<String> implementedProperties = new ArrayList<>(simulatedProperties);
            implementedProperties.retainAll(realProperties);
            counts[1] += implementedProperties.size();
            counts[0] += realProperties.size();
            htmlDetails(method.getName(), html, realProperties, implementedProperties, erroredProperties);
            dataset.addValue(implementedProperties.size(), "Implemented", method.getName());
            dataset.addValue(realProperties.size(), browserVersion.getNickname().replace("FF", "Firefox ").replace("IE", "Internet Explorer "), method.getName());
            dataset.addValue(erroredProperties.size(), "Should not be implemented", method.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 38 with HtmlUnitNYI

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

the class ElementPropertiesTest method collectStatistics.

private static void collectStatistics(final BrowserVersion browserVersion, final DefaultCategoryDataset dataset, final StringBuilder html, final int[] counts) {
    final Method[] methods = ElementPropertiesTest.class.getMethods();
    Arrays.sort(methods, Comparator.comparing(Method::getName));
    for (final Method method : methods) {
        if (method.isAnnotationPresent(Test.class)) {
            final Alerts alerts = method.getAnnotation(Alerts.class);
            String[] expectedAlerts = {};
            if (BrowserVersionClassRunner.isDefined(alerts.value())) {
                expectedAlerts = alerts.value();
            }
            if (browserVersion == BrowserVersion.INTERNET_EXPLORER) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.IE(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.EDGE) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.EDGE(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.FIREFOX_ESR) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.FF_ESR(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.FIREFOX) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.FF(), alerts.DEFAULT());
            } else if (browserVersion == BrowserVersion.CHROME) {
                expectedAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, alerts.CHROME(), alerts.DEFAULT());
            }
            final HtmlUnitNYI htmlUnitNYI = method.getAnnotation(HtmlUnitNYI.class);
            String[] nyiAlerts = {};
            if (htmlUnitNYI != null) {
                if (browserVersion == BrowserVersion.INTERNET_EXPLORER) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.IE());
                } else if (browserVersion == BrowserVersion.EDGE) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.EDGE());
                } else if (browserVersion == BrowserVersion.FIREFOX_ESR) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF_ESR());
                } else if (browserVersion == BrowserVersion.FIREFOX) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.FF());
                } else if (browserVersion == BrowserVersion.CHROME) {
                    nyiAlerts = BrowserVersionClassRunner.firstDefinedOrGiven(expectedAlerts, htmlUnitNYI.CHROME());
                }
            }
            final List<String> realProperties = stringAsArray(String.join(",", expectedAlerts));
            final List<String> simulatedProperties = stringAsArray(String.join(",", nyiAlerts));
            final List<String> erroredProperties = new ArrayList<>(simulatedProperties);
            erroredProperties.removeAll(realProperties);
            final List<String> implementedProperties = new ArrayList<>(simulatedProperties);
            implementedProperties.retainAll(realProperties);
            counts[1] += implementedProperties.size();
            counts[0] += realProperties.size();
            htmlDetails(method.getName(), html, realProperties, implementedProperties, erroredProperties);
            dataset.addValue(implementedProperties.size(), "Implemented", method.getName());
            dataset.addValue(realProperties.size(), browserVersion.getNickname().replace("FF", "Firefox ").replace("IE", "Internet Explorer "), method.getName());
            dataset.addValue(erroredProperties.size(), "Should not be implemented", method.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 39 with HtmlUnitNYI

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

the class HtmlSubmitInputTest method onclickDisables.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "1", IE = "2")
@HtmlUnitNYI(IE = "1")
public void onclickDisables() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "  <script type='text/javascript'>\n" + "    function submitForm() {\n" + "      document.deliveryChannelForm.submitBtn.disabled = true;\n" + "    }\n" + "  </script>\n" + "</head>\n" + "<body>\n" + "  <form action='test' name='deliveryChannelForm'>\n" + "    <input name='submitBtn' type='submit' value='Save' title='Save' onclick='submitForm();'>\n" + "  </form>\n" + "</body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse("");
    final WebDriver webDriver = loadPage2(html);
    final WebElement input = webDriver.findElement(By.name("submitBtn"));
    input.click();
    assertEquals(Integer.parseInt(getExpectedAlerts()[0]), getMockWebConnection().getRequestCount());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 40 with HtmlUnitNYI

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

the class XMLHttpRequestTest method enctypeBufferSource.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("null")
@HtmlUnitNYI(CHROME = "text/plain", EDGE = "text/plain", FF = "text/plain", FF_ESR = "text/plain", IE = "text/plain")
public void enctypeBufferSource() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "function doTest() {\n" + "  try {\n" + "    var typedArray = new Int8Array(8);\n" + "    var xhr = new XMLHttpRequest();\n" + "    xhr.open('post', '/test2', false);\n" + "    xhr.send(typedArray);\n" + "    log('done');\n" + "  } catch (e) {\n" + "    log('error: ' + e.message);\n" + "  }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body onload='doTest()'>\n" + "</body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse("<html><title>Response</title></html>");
    final WebDriver driver = loadPage2(html);
    verifyTitle2(driver, new String[] { "done" });
    String headerValue = getMockWebConnection().getLastWebRequest().getAdditionalHeaders().get(HttpHeader.CONTENT_TYPE);
    // Can't test equality for multipart/form-data as it will have the form:
    // multipart/form-data; boundary=---------------------------42937861433140731107235900
    headerValue = StringUtils.substringBefore(headerValue, ";");
    assertEquals(getExpectedAlerts()[0], "" + headerValue);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)72 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 Test (org.junit.Test)68 WebDriver (org.openqa.selenium.WebDriver)54 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)14 URL (java.net.URL)14 WebElement (org.openqa.selenium.WebElement)14 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)11 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)9 ArrayList (java.util.ArrayList)7 InputStream (java.io.InputStream)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 Page (com.gargoylesoftware.htmlunit.Page)1 UnexpectedPage (com.gargoylesoftware.htmlunit.UnexpectedPage)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1