List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep)
From source file:com.cognifide.bdd.demo.BobcatWaitTest.java
License:Apache License
@Test public void seleniumWaitTest() { MyExpectedCondition condition = new MyExpectedCondition(); try {/*from w ww . j a v a2 s . com*/ new WebDriverWait(webDriver, TIME_OUT_IN_SECONDS, DELAY * 1000).until(condition); } catch (TimeoutException e) { // ignoring timeout } finally { assertThat(numberOfRetries(), is(condition.getWaitCounter())); } }
From source file:com.cognifide.qa.bb.provider.selenium.BobcatWebDriverWait.java
License:Apache License
/** * This method enhances Selenium's "until" method. * First it reduces implicit timeout to a near-zero value. * Then a timer is started and the condition is checked cyclically until it is fulfilled * or the timer times out, with delay between checks. * Finally, implicit timeout is set back to the value * defined in the property file (under "webdriver.defaultTimeout"). * * @param condition Selenium's condition object that is queried cyclically inside the wait loop. * @param <T> The function's expected return type. * @param delay Delay between polls in seconds * @return The function's return value if the function returned something different * from null or false before the timeout expired. *///w w w . j ava 2s . com public <T> T until(ExpectedCondition<T> condition, long delay) { webDriver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT_TIME, TimeUnit.SECONDS); final T result = new WebDriverWait(webDriver, timeOutInSeconds, delay * 1000L).until(condition::apply); webDriver.manage().timeouts().implicitlyWait(defaultTimeout, TimeUnit.SECONDS); return result; }
From source file:com.cognifide.qa.bb.wait.BobcatWait.java
License:Apache License
/** * @return an instance of {@link WebDriverWait} based on the provided {@link Timings} *///from w ww . j a v a 2s .c om protected WebDriverWait getWebDriverWait() { return new WebDriverWait(webDriverProvider.get(), timings.getExplicitTimeout(), timings.getPollingInterval()); }
From source file:com.github.licanhua.test.framework.util.PageHelper.java
License:Apache License
private static <T> void waitForElement(String message, ElementContext context, final T element, final Predicate<T> predicate) { WebDriver webDriver = context.getWebDriver(); int waitDuration = context.getWaitDurationInSeconds(); try {//ww w. j a v a2s .c o m Wait<WebDriver> wait = new WebDriverWait(webDriver, waitDuration, 100); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(final WebDriver webDriver) { try { return predicate.apply(element); } catch (final NoSuchElementException e) { return false; } catch (final StaleElementReferenceException e) { return false; } } }); } catch (TimeoutException e) { TimeoutException te = new TimeoutException(message + " timeout!", e); throw te; } }
From source file:com.github.licanhua.test.framework.util.PageHelper.java
License:Apache License
public static void waitForDocumentReadyState(WebDriverContext webDriverContext) { logger.info("Wait for document.readyState is complete"); Wait<WebDriver> wait = new WebDriverWait(webDriverContext.getWebDriver(), webDriverContext.getWaitDurationInSeconds(), 100); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { try { return ((JavascriptExecutor) driver).executeScript("return document.readyState") .equals("complete"); } catch (TimeoutException e) { throw new TimeoutException("Load document timeout\n" + e.getMessage()); }/* ww w . j a v a 2 s .c om*/ } }); }
From source file:com.github.wiselenium.elements.page.Page.java
License:Open Source License
@Override public WebDriverWait waitFor(long timeOutInSeconds, long sleepInMillis) { return new WebDriverWait(this.driver, timeOutInSeconds, sleepInMillis); }