@Override public Statement apply(Statement statement) throws Throwable { return () -> { Clock clock = new SystemClock(); long end = clock.laterBy(timeout.in(TimeUnit.MILLISECONDS)); Throwable lastException; do { try { return statement.evaluate(); } catch (Throwable e) { lastException = e; if (ignoring.stream().anyMatch(clazz -> clazz.isInstance(e))) { try { Thread.sleep(polling.in(TimeUnit.MILLISECONDS)); } catch (InterruptedException i) { break; } } else { Throwables.propagate(e); } } } while ((clock.isNowBefore(end))); throw lastException; }; }
protected SearchContextWait(final SearchContext input, final Clock clock, final Sleeper sleeper, final long timeout, final TimeUnit timeoutTimeUnit, final long sleep, final TimeUnit sleepTimeUnit) { super(input, clock, sleeper); withTimeout(timeout, timeoutTimeUnit); pollingEvery(sleep, sleepTimeUnit); ignoring(NotFoundException.class); }
/** * Wait will ignore instances of NotFoundException that are encountered * (thrown) by default in the 'until' condition, and immediately propagate * all others. You can add more to the ignore list by calling * ignoring(exceptions to add). * * @param context * The SearchContext instance to pass to the expected conditions * @param clock * The clock to use when measuring the timeout * @param sleeper * Object used to make the current thread go to sleep. * @param timeOutInSeconds * The timeout in seconds when an expectation is * @param sleepTimeOut * The timeout used whilst sleeping. Defaults to 500ms called. */ public SearchContextWait(SearchContext context, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut) { super(context, clock, sleeper); withTimeout(timeOutInSeconds, TimeUnit.SECONDS); pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS); ignoring(NotFoundException.class); this.context = context; }
/** * @param driver * The WebDriver instance to pass to the expected conditions * @param clock * The clock to use when measuring the timeout * @param sleeper * Object used to make the current thread go to sleep. * @param timeOutInSeconds * The timeout in seconds when an expectation is * @param sleepTimeOut * The timeout used whilst sleeping. Defaults to 500ms called. */ protected QAFWebDriverWait(QAFExtendedWebDriver driver, Clock clock, Sleeper sleeper, long timeOutInMiliSeconds, long sleepTimeOut) { super(driver, clock, sleeper); withTimeout(timeOutInMiliSeconds, TimeUnit.MILLISECONDS); pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS); ignoring(StaleElementReferenceException.class); }
/** * @param element * The WebElement instance to pass to the expected conditions * @param clock * The clock to use when measuring the timeout * @param sleeper * Object used to make the current thread go to sleep. * @param timeOutInSeconds * The timeout in seconds when an expectation is * @param sleepTimeOut * The timeout used whilst sleeping. Defaults to 500ms called. */ @SuppressWarnings("unchecked") protected QAFWebElementWait(QAFExtendedWebElement element, Clock clock, Sleeper sleeper, long timeOutInMiliSeconds, long sleepTimeOut) { super(element, clock, sleeper); withTimeout(timeOutInMiliSeconds, TimeUnit.MILLISECONDS); pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS); ignore(NoSuchElementException.class, StaleElementReferenceException.class); }