improve wait for page load 5.5.0-alpha-8
authorJochen Kemnade <jkemnade@apache.org>
Fri, 3 Nov 2017 10:18:55 +0000 (11:18 +0100)
committerJochen Kemnade <jkemnade@apache.org>
Fri, 3 Nov 2017 10:18:55 +0000 (11:18 +0100)
tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java

index 313e4e5..6ae7c64 100644 (file)
 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