Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/JSWaiter.java =================================================================== diff -u -r19086 -r19104 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/JSWaiter.java (.../JSWaiter.java) (revision 19086) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/JSWaiter.java (.../JSWaiter.java) (revision 19104) @@ -1,10 +1,14 @@ package test.forgon.disinfectsystem.selenium.tools; +import java.util.concurrent.TimeUnit; + import org.apache.log4j.Logger; import org.openqa.selenium.JavascriptException; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.FluentWait; +import org.openqa.selenium.support.ui.Wait; import org.openqa.selenium.support.ui.WebDriverWait; /** @@ -74,30 +78,30 @@ //Wait Until JS Ready public static void waitUntilJSReady() { - WebDriverWait wait = new WebDriverWait(jsWaitDriver,15); + + Wait wait = new FluentWait(jsWaitDriver) + .withTimeout(15000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(JavascriptException.class); + JavascriptExecutor jsExec = (JavascriptExecutor) jsWaitDriver; + //Get JS is Ready + boolean jsReady = false; + //Wait for Javascript to load ExpectedCondition jsLoad = driver -> ((JavascriptExecutor) jsWaitDriver) - .executeScript("return document.readyState").toString().equals("complete"); + .executeScript("return document.readyState").toString().equals("complete"); - //Get JS is Ready - boolean jsReady = false; - try{ - jsReady = (Boolean) jsExec.executeScript("return document.readyState").toString().equals("complete"); - } - // 捕获JavascriptException,忽略该异常 - catch (JavascriptException e){ - e.printStackTrace(); - logger.debug(e.getMessage()); - } + jsReady = (Boolean) jsExec.executeScript("return document.readyState").toString().equals("complete"); + //Wait Javascript until it is Ready! if(!jsReady) { - logger.debug("JS in NOT Ready!"); - //Wait for Javascript to load - wait.until(jsLoad); + logger.debug("JS is NOT Ready!"); + //Wait for Javascript to load + wait.until(jsLoad); } else { - logger.debug("JS is Ready!"); + logger.debug("JS is Ready!"); } }