Repository: tapestry-5 Updated Branches: refs/heads/master 8932267e4 -> 3eaf96507
improve wait for page load Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/3eaf9650 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/3eaf9650 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/3eaf9650 Branch: refs/heads/master Commit: 3eaf96507902268728b07a77894ebcef024819a5 Parents: 8932267 Author: Jochen Kemnade <[email protected]> Authored: Fri Nov 3 11:18:55 2017 +0100 Committer: Jochen Kemnade <[email protected]> Committed: Fri Nov 3 11:18:55 2017 +0100 ---------------------------------------------------------------------- .../apache/tapestry5/test/SeleniumTestCase.java | 32 +++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3eaf9650/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java ---------------------------------------------------------------------- diff --git a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java index 313e4e5..6ae7c64 100644 --- a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java +++ b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java @@ -13,13 +13,10 @@ package org.apache.tapestry5.test; import com.thoughtworks.selenium.CommandProcessor; -import com.thoughtworks.selenium.HttpCommandProcessor; import com.thoughtworks.selenium.Selenium; import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; import com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor; -import io.github.bonigarcia.wdm.FirefoxDriverManager; - import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -27,7 +24,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; -import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.internal.WrapsDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -980,7 +976,7 @@ public abstract class SeleniumTestCase extends Assert implements Selenium @Override public boolean isElementPresent(String locator) { - return selenium.isElementPresent(locator); + return webDriver.findElement(convertLocator(locator)) != null; } @Override @@ -1353,7 +1349,12 @@ public abstract class SeleniumTestCase extends Assert implements Selenium protected void waitForCondition(ExpectedCondition condition) { - WebDriverWait wait = new WebDriverWait(webDriver, 10); + waitForCondition(condition, 10l); + } + + protected void waitForCondition(ExpectedCondition condition, long timeoutSeconds) + { + WebDriverWait wait = new WebDriverWait(webDriver, timeoutSeconds); wait.until(condition); } @@ -1382,26 +1383,9 @@ public abstract class SeleniumTestCase extends Assert implements Selenium return; } - final long pollingStartTime = System.currentTimeMillis(); - - long sleepTime = 20; - - while (true) - { - if (isElementPresent("css=body[data-page-initialized='true']")) - { - return; - } - - if ((System.currentTimeMillis() - pollingStartTime) > 30000) - { - reportAndThrowAssertionError("Page did not finish initializing after 30 seconds."); - } - sleep(sleepTime); + waitForCondition(ExpectedConditions.attributeToBe(By.cssSelector("body"), "data-page-initialized", "true"), 30); - sleepTime *= 2; - } } @Override
