From: <rb...@us...> - 2018-01-25 16:44:46
|
Revision: 15092 http://sourceforge.net/p/htmlunit/code/15092 Author: rbri Date: 2018-01-25 16:44:43 +0000 (Thu, 25 Jan 2018) Log Message: ----------- fix some problem to be able to run our test suite with edge Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-01-24 20:35:20 UTC (rev 15091) +++ trunk/htmlunit/src/changes/changes.xml 2018-01-25 16:44:43 UTC (rev 15092) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators"> + <action type="fix" dev="rbri" due-to="Frank Danek"> + Fix some problem to be able to run our test suite with edge. + </action> <action type="add" dev="rbri"> JavaScript: WeakSet and WeakMap constructor now supports user defined iterators also. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2018-01-24 20:35:20 UTC (rev 15091) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2018-01-25 16:44:43 UTC (rev 15092) @@ -1220,7 +1220,7 @@ if (event == null) { return false; } - else if (!(event.getSrcElement() instanceof HTMLElement)) { + if (!(event.getSrcElement() instanceof HTMLElement)) { return false; } final HTMLElement srcElement = (HTMLElement) event.getSrcElement(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java 2018-01-24 20:35:20 UTC (rev 15091) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java 2018-01-25 16:44:43 UTC (rev 15092) @@ -40,6 +40,7 @@ Pattern.compile("Starting ChromeDriver " + ExternalTest.CHROME_DRIVER_.replace(".", "\\.") + "\\.[0-9]+ ?\\(?[0-9a-f]*\\)? on port \\d*\r?\n" + "Only local connections are allowed\\.\r?\n"), + Pattern.compile(".*Unable to retrieve document state unexpected alert open\r?\n"), Pattern.compile(".*FirefoxOptions toCapabilities\r?\n"), Pattern.compile(".*Preferring the firefox binary in these options \\(.*\\)\r?\n"), Pattern.compile(".*geckodriver.*\r?\n"), @@ -49,7 +50,7 @@ Pattern.compile(".*\taddons\\..*\r?\n"), Pattern.compile("\\*\\*\\* Blocklist::.*\r?\n"), Pattern.compile("Started InternetExplorerDriver server \\(\\d\\d\\-bit\\)\r?\n" - + "3\\.6\\.0\\.0\r?\n" + + "3\\.8\\.0\\.0\r?\n" + "Listening on port \\d*\r?\n" + "Only local connections are allowed\r?\n"), // edge Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-01-24 20:35:20 UTC (rev 15091) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-01-25 16:44:43 UTC (rev 15092) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit; +import static com.gargoylesoftware.htmlunit.BrowserVersion.EDGE; import static com.gargoylesoftware.htmlunit.BrowserVersion.INTERNET_EXPLORER; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static org.junit.Assert.fail; @@ -357,6 +358,13 @@ } /** + * Closes the real Edge browser drivers. + */ + protected static void shutDownRealEdge() { + shutDownReal(EDGE); + } + + /** * Stops all WebServers. * @throws Exception if it fails */ @@ -805,7 +813,7 @@ WebDriver driver = getWebDriver(); if (!(driver instanceof HtmlUnitDriver)) { try { - driver.manage().window().setSize(new Dimension(1272, 768)); + resizeIfNeeded(driver); } catch (final NoSuchSessionException e) { // maybe the driver was killed by the test before; setup a new one @@ -812,7 +820,7 @@ shutDownRealBrowsers(); driver = getWebDriver(); - driver.manage().window().setSize(new Dimension(1272, 768)); + resizeIfNeeded(driver); } } driver.get(url.toExternalForm()); @@ -849,12 +857,32 @@ startWebServer("./", null, servlets); - final WebDriver driver = getWebDriver(); + WebDriver driver = getWebDriver(); + if (!(driver instanceof HtmlUnitDriver)) { + try { + resizeIfNeeded(driver); + } + catch (final NoSuchSessionException e) { + // maybe the driver was killed by the test before; setup a new one + shutDownRealBrowsers(); + + driver = getWebDriver(); + resizeIfNeeded(driver); + } + } driver.get(url.toExternalForm()); return driver; } + private void resizeIfNeeded(final WebDriver driver) { + final Dimension size = driver.manage().window().getSize(); + if (size.getWidth() != 1272 || size.getHeight() != 768) { + // only resize if needed because it may be quite expensive (e.g. Edge) + driver.manage().window().setSize(new Dimension(1272, 768)); + } + } + /** * Defines the provided HTML as the response for {@link WebTestCase#URL_FIRST} * and loads the page with this URL using the current WebDriver version; finally, asserts that the @@ -1054,7 +1082,19 @@ while (collectedAlerts.size() < alertsLength && System.currentTimeMillis() < maxWait) { try { final Alert alert = driver.switchTo().alert(); - collectedAlerts.add(alert.getText()); + String text = alert.getText(); + + if (useRealBrowser() && getBrowserVersion().isEdge()) { + // EdgeDriver reads empty strings as null -> harmonize + if (text == null) { + text = ""; + } + + // alerts for real Edge need some time until they may be accepted + Thread.sleep(100); + } + + collectedAlerts.add(text); alert.accept(); // handling of alerts requires some time @@ -1061,9 +1101,17 @@ // at least for tests with many alerts we have to take this into account maxWait += 100; - if (useRealBrowser() && getBrowserVersion().isIE()) { - // alerts for real IE are really slow - maxWait += 5000; + if (useRealBrowser()) { + if (getBrowserVersion().isIE()) { + // alerts for real IE are really slow + maxWait += 5000; + } + else if (getBrowserVersion().isEdge()) { + // closing one alert and opening the next one takes some time in real Edge + // (most probably due to the 'nice' fade animations...) + Thread.sleep(500); + maxWait += 800; + } } } catch (final NoAlertPresentException e) { |