From: <rb...@us...> - 2018-07-05 06:09:48
|
Revision: 15427 http://sourceforge.net/p/htmlunit/code/15427 Author: rbri Date: 2018-07-05 06:09:44 +0000 (Thu, 05 Jul 2018) Log Message: ----------- try to make our test suite more robust (when running in real browsers) Modified Paths: -------------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NoHttpResponseTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NoHttpResponseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NoHttpResponseTest.java 2018-07-05 06:08:05 UTC (rev 15426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NoHttpResponseTest.java 2018-07-05 06:09:44 UTC (rev 15427) @@ -83,7 +83,7 @@ try { driver.get(URL_FIRST.toString()); driver.findElement(By.id("loginButton")).click(); - assertEquals("right submit", driver.getTitle()); + assertTitle(driver, "right submit"); } finally { miniServer.shutDown(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-07-05 06:08:05 UTC (rev 15426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-07-05 06:09:44 UTC (rev 15427) @@ -63,6 +63,7 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; +import org.junit.ComparisonFailure; import org.openqa.selenium.Alert; import org.openqa.selenium.Dimension; import org.openqa.selenium.NoAlertPresentException; @@ -1150,6 +1151,33 @@ } /** + * Asserts the current title is equal to the expectation string. + * @param webdriver the driver in use + * @param expected the expected object + * @throws Exception in case of failure + */ + protected void assertTitle(final WebDriver webdriver, final String expected) throws Exception { + if (useRealBrowser()) { + final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME; + + while (true) { + try { + assertEquals(expected, webdriver.getTitle()); + break; + } + catch (final ComparisonFailure e) { + if (System.currentTimeMillis() > maxWait) { + throw e; + } + Thread.sleep(10); + } + } + } + + assertEquals(expected, webdriver.getTitle()); + } + + /** * Release resources but DON'T close the browser if we are running with a real browser. * Note that HtmlUnitDriver is not cached by default, but that can be configured by {@link #isWebClientCached()}. */ |