Search in sources :

Example 61 with NotYetImplemented

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

the class DocumentTest method setActive.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "null", "text1", "not available" }, IE = { "null", "text1", "onfocus text2", "text2", "onfocus text2" })
@NotYetImplemented(IE)
public // the execution order is not yet correct: the onfocus is called during onload not after it
void setActive() throws Exception {
    final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "  log(document.activeElement);\n" + "  function test() {\n" + "    log(document.activeElement.id);\n" + "    var inp = document.getElementById('text2');\n" + "    if (inp.setActive) {\n" + "      inp.setActive();\n" + "      log(document.activeElement.id);\n" + "    } else { log('not available'); }\n" + "  }\n" + "</script></head>\n" + "<body>\n" + "  <input id='text1' onclick='test()'>\n" + "  <input id='text2' onfocus='log(\"onfocus text2\")'>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    verifyTitle2(driver, getExpectedAlerts()[0]);
    Thread.sleep(100);
    driver.findElement(By.id("text1")).click();
    verifyTitle2(driver, getExpectedAlerts());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 62 with NotYetImplemented

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

the class EventNodeTest method clickEventsLabel.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "mousedown label,mouseup label,click label,focus text,click text,", IE = "mousedown label,mouseup label,click label,click text,focus text,")
@NotYetImplemented(IE)
public void clickEventsLabel() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "  <script>\n" + "    function log(text) {\n" + "      var textarea = document.getElementById('myTextarea');\n" + "      textarea.value += text + ',';\n" + "    }\n" + "  </script>\n" + "</head><body>\n" + "  <label id='testLabel' for='testInput'" + " onfocus=\"log('will not be triggered')\" onmousedown=\"log('mousedown label')\"" + " onclick=\"log('click label')\" onmouseup=\"log('mouseup label')\">test label</label>\n" + "  <form>\n" + "    <input type='text' id='testInput' onmousedown=\"log('mousedown text')\"" + " onclick=\"log('click text')\" onmouseup=\"log('mouseup text')\" onfocus=\"log('focus text')\">\n" + "  </form>\n" + "  <textarea id='myTextarea' cols='80' rows='10'></textarea>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("testLabel")).click();
    final String expected = getExpectedAlerts()[0];
    assertEquals(expected, driver.findElement(By.id("myTextarea")).getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 63 with NotYetImplemented

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

the class ComputedCSSStyleDeclarationTest method stringPropertiesNotAttached.

/**
 * Compares all {@code style} and {@code getComputedStyle}, for not-attached elements.
 *
 * @throws Exception if the test fails
 */
@Test
@NotYetImplemented
public void stringPropertiesNotAttached() throws Exception {
    // to fix Chrome, look into ComputedCSSStyleDeclaration.defaultIfEmpty first condition
    final String html = "<html><head><body>\n" + "  <textarea id='myTextarea' cols='120' rows='20'></textarea>\n" + "  </div>\n" + "<script>\n" + "var e = document.createElement('div');\n" + "var array = [];\n" + "try {\n" + "  for (var i in e.style) {\n" + "    var s1 = e.style[i];\n" + "    var s2 = window.getComputedStyle(e, null)[i];\n" + "    if ('height' == i || 'width' == i || 'cssText' == i) {\n" + "      s2 = 'skipped';\n" + "    }\n" + "    if(typeof s1 == 'string')\n" + "      array.push(i + '=' + s1 + ':' + s2);\n" + "  }\n" + "} catch (e) { array[array.length] = 'exception'; }\n" + "array.sort();\n" + "document.getElementById('myTextarea').value = array.join('\\n');\n" + "</script></body></html>";
    final WebDriver driver = loadPage2(html);
    final String expected = loadExpectation("ComputedCSSStyleDeclarationTest.properties.notAttached", ".txt");
    final String actual = driver.findElement(By.id("myTextarea")).getAttribute("value");
    assertEquals(expected, actual);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test)

Example 64 with NotYetImplemented

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

the class Document2Test method activeElement_iframe.

/**
 * Regression test for issue 1568.
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "[object HTMLBodyElement]", "§§URL§§#", "§§URL§§#" }, IE = { "null", "§§URL§§#", "§§URL§§#" })
@NotYetImplemented(IE)
public void activeElement_iframe() throws Exception {
    final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "  <a id='insert' " + "onclick=\"insertText(" + "'<html><head></head><body>first frame text</body></html>');\" href=\"#\">\n" + "insert text to frame</a>\n" + "  <a id= 'update' " + "onclick=\"insertText(" + "'<html><head></head><body>another frame text</body></html>');\" href=\"#\">\n" + "change frame text again</a><br>\n" + "  <iframe id='innerFrame' name='innerFrame' src='frame1.html'></iframe>\n" + "  <script>\n" + "    alert(document.activeElement);\n" + "    function insertText(text) {\n" + "      with (innerFrame.document) {\n" + "        open();\n" + "        writeln(text);\n" + "        close();\n" + "      }\n" + "      alert(document.activeElement);\n" + "    }\n" + "  </script>\n" + "</body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
    getMockWebConnection().setResponse(new URL("http://example.com/frame1.html"), "");
    final WebDriver driver = loadPage2(html);
    expandExpectedAlertsVariables(URL_FIRST);
    verifyAlerts(driver, getExpectedAlerts()[0]);
    driver.findElement(By.id("insert")).click();
    verifyAlerts(driver, getExpectedAlerts()[1]);
    driver.switchTo().frame(driver.findElement(By.id("innerFrame")));
    assertEquals("first frame text", driver.findElement(By.tagName("body")).getText());
    driver.switchTo().defaultContent();
    driver.findElement(By.id("update")).click();
    verifyAlerts(driver, getExpectedAlerts()[2]);
    driver.switchTo().frame(driver.findElement(By.id("innerFrame")));
    assertEquals("another frame text", driver.findElement(By.tagName("body")).getText());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) URL(java.net.URL) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 65 with NotYetImplemented

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

the class JQueryExtractor method generateTestCases.

/**
 * Generates the java code of the test cases.
 * @param testClass the class containing the tests
 * @param dir the directory which holds the expectations
 * @throws Exception if an error occurs.
 */
public static void generateTestCases(final Class<? extends WebDriverTestCase> testClass, final File dir) throws Exception {
    final TestedBrowser[] browsers = TestedBrowser.values();
    // main browsers regardless of version e.g. "FF"
    final List<String> mainNames = new ArrayList<>();
    for (final TestedBrowser b : browsers) {
        final String name = b.name();
        if (!"NONE".equals(name) && Character.isLetter(name.charAt(name.length() - 1))) {
            mainNames.add(name);
        }
    }
    final Map<String, List<String>> browserVersions = new HashMap<>();
    for (final TestedBrowser b : browsers) {
        final String name = b.name();
        for (final String mainName : mainNames) {
            if (!name.equals(mainName) && name.startsWith(mainName)) {
                List<String> list = browserVersions.get(mainName);
                if (list == null) {
                    list = new ArrayList<>();
                    browserVersions.put(mainName, list);
                }
                list.add(name);
            }
        }
    }
    final Map<String, Expectations> browserExpectations = new HashMap<>();
    final File[] files = dir.listFiles();
    if (files != null) {
        for (final File file : files) {
            if (file.isFile() && file.getName().endsWith(".txt")) {
                for (final TestedBrowser b : browsers) {
                    final String browserName = b.name();
                    if (file.getName().equalsIgnoreCase("results." + browserName.replace('_', '.') + ".txt")) {
                        browserExpectations.put(browserName, Expectations.readExpectations(file));
                    }
                }
            }
        }
    }
    // gather all the tests (some tests don't get executed for all browsers)
    final List<Test> allTests = computeTestsList(browserExpectations);
    final Collection<String> availableBrowserNames = new TreeSet<>(browserExpectations.keySet());
    for (final Test test : allTests) {
        final Map<String, String> testExpectation = new TreeMap<>();
        final Map<Integer, List<String>> lineToBrowser = new TreeMap<>();
        for (final String browserName : availableBrowserNames) {
            final Expectation expectation = browserExpectations.get(browserName).getExpectation(test);
            if (expectation != null) {
                List<String> browsersForLine = lineToBrowser.get(expectation.getLine());
                if (browsersForLine == null) {
                    browsersForLine = new ArrayList<>();
                    lineToBrowser.put(expectation.getLine(), browsersForLine);
                }
                browsersForLine.add(browserName);
                final String str = expectation.getTestResult();
                testExpectation.put(browserName, str.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\""));
            }
        }
        System.out.println("    /**");
        System.out.println("     * Test " + lineToBrowser + ".");
        System.out.println("     * @throws Exception if an error occurs");
        System.out.println("     */");
        System.out.println("    @Test");
        System.out.print("    @Alerts(");
        final boolean allSame = testExpectation.size() == availableBrowserNames.size() && new HashSet<>(testExpectation.values()).size() == 1;
        if (allSame) {
            final String first = testExpectation.keySet().iterator().next();
            String expectation = testExpectation.get(first);
            if (expectation.length() > 100) {
                expectation = expectation.substring(0, 50) + "\"\n            + \"" + expectation.substring(50);
            }
            System.out.print("\"" + expectation + '"');
        } else {
            final List<String> cleanedBrowserNames = new ArrayList<>(testExpectation.keySet());
            Collections.sort(cleanedBrowserNames);
            if (testExpectation.size() == availableBrowserNames.size()) {
                // Hack a bit to avoid redundant alerts
                // find the best default
                int matches = 0;
                ArrayList<String> defaultBrowsers = null;
                for (final String browser : cleanedBrowserNames) {
                    final String expectation = testExpectation.get(browser);
                    final ArrayList<String> matchBrowsers = new ArrayList<>();
                    int matchCount = 0;
                    for (final String otherBrowser : cleanedBrowserNames) {
                        if (!browser.equals(otherBrowser) && expectation.equals(testExpectation.get(otherBrowser))) {
                            matchCount++;
                            matchBrowsers.add(otherBrowser);
                        }
                    }
                    if (matches < matchCount) {
                        matches = matchCount;
                        matchBrowsers.add(browser);
                        defaultBrowsers = matchBrowsers;
                    }
                }
                if (matches > 1) {
                    testExpectation.put("DEFAULT", testExpectation.get(defaultBrowsers.get(0)));
                    cleanedBrowserNames.add(0, "DEFAULT");
                    for (final String browser : defaultBrowsers) {
                        testExpectation.remove(browser);
                        cleanedBrowserNames.remove(browser);
                    }
                }
            }
            boolean first = true;
            if (cleanedBrowserNames.size() == 1 && "DEFAULT".equals(cleanedBrowserNames.get(0))) {
                System.out.print("\"" + testExpectation.get("DEFAULT") + '"');
            } else {
                for (final String browserName : cleanedBrowserNames) {
                    final String expectation = testExpectation.get(browserName);
                    if (expectation == null) {
                        // test didn't run for this browser
                        continue;
                    }
                    if (!first) {
                        System.out.println(",");
                        System.out.print("            ");
                    }
                    System.out.print(browserName + " = \"" + expectation + '"');
                    first = false;
                }
            }
        }
        System.out.println(")");
        final String methodName = test.getName().replaceAll("\\W", "_");
        try {
            final Method method = testClass.getMethod(methodName);
            final NotYetImplemented notYetImplemented = method.getAnnotation(NotYetImplemented.class);
            if (null != notYetImplemented) {
                final TestedBrowser[] notYetImplementedBrowsers = notYetImplemented.value();
                if (notYetImplementedBrowsers.length > 0) {
                    final List<String> browserNames = new ArrayList<>(notYetImplementedBrowsers.length);
                    for (final TestedBrowser browser : notYetImplementedBrowsers) {
                        browserNames.add(browser.name());
                    }
                    Collections.sort(browserNames);
                    // TODO dirty hack
                    if (browserNames.size() == 5 && browserNames.contains("CHROME") && browserNames.contains("EDGE") && browserNames.contains("FF") && browserNames.contains("FF_ESR") && browserNames.contains("IE")) {
                        System.out.println("    @NotYetImplemented");
                    } else {
                        System.out.print("    @NotYetImplemented(");
                        if (browserNames.size() > 1) {
                            System.out.print("{ ");
                        }
                        System.out.print(String.join(", ", browserNames));
                        if (browserNames.size() > 1) {
                            System.out.print(" }");
                        }
                        System.out.println(")");
                    }
                }
            }
        } catch (final NoSuchMethodException e) {
        // ignore
        }
        System.out.println("    public void " + methodName + "() throws Exception {");
        System.out.println("        runTest(\"" + test.getName().replace("\"", "\\\"") + "\");");
        System.out.println("    }");
        System.out.println();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestedBrowser(com.gargoylesoftware.htmlunit.junit.BrowserRunner.TestedBrowser) JQuery1x8x2Test(com.gargoylesoftware.htmlunit.libraries.JQuery1x8x2Test) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) File(java.io.File)

Aggregations

NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)66 Test (org.junit.Test)65 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)54 WebDriver (org.openqa.selenium.WebDriver)54 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)16 URL (java.net.URL)15 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)12 WebElement (org.openqa.selenium.WebElement)11 ArrayList (java.util.ArrayList)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)4 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)4 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)4 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 InputStream (java.io.InputStream)3 CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)2 MSXMLTestHelper.callSerializeXMLDOMDocumentToString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callSerializeXMLDOMDocumentToString)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 File (java.io.File)2