/** * Repeatedly applies this instance's input value to the given function until one of the following occurs: * the function returns neither null nor false, * the function throws an unignored exception, * the default timeout expires * * useful in situations where FluentAdapter#await is too specific * (for example to check against page source or title) * * @param f function to execute */ public <T>T waitUntil(Function<WebDriver, T> f) { FluentWait<WebDriver> wait = fluentWait().withTimeout(3000, TimeUnit.MILLISECONDS); return waitUntil(wait,f); }
/** * Repeatedly applies this instance's input value to the given function until one of the following occurs: * * <ul> * <li> the function returns neither null nor false,</li> * <li> the function throws an unignored exception,</li> * <li> the default timeout expires</li> * </ul> * * useful in situations where FluentAdapter#await is too specific * (for example to check against page source or title) * * @param f function to execute * @param <T> the return type * @return the return value. */ public <T>T waitUntil(Function<WebDriver, T> f) { FluentWait<WebDriver> wait = fluentWait().withTimeout(Duration.ofMillis(3000)); return waitUntil(wait,f); }
/** * Repeatedly applies this instance's input value to the given function until one of the following occurs: * * <ul> * <li> the function returns neither null nor false,</li> * <li> the function throws an unignored exception,</li> * <li> the default timeout expires</li> * </ul> * * useful in situations where FluentAdapter#await is too specific * (for example to check against page source or title) * * @param f function to execute * @param <T> the return type * @return the return value. */ public <T>T waitUntil(Function<WebDriver, T> f) { FluentWait<WebDriver> wait = fluentWait().withTimeout(Duration.ofMillis(3000)); return waitUntil(wait,f); }
private <T> T waitFor(Supplier<T> supplier) { WaitingFunction<T> function = new WaitingFunction<>(); try { FluentWait<Supplier<T>> wait = new FluentWait<>(supplier) .ignoring(NoSuchElementException.class); wait.withTimeout(duration); return wait.until(function); } catch (TimeoutException e) { if (function.foundStaleElementReferenceException != null) { throw StaleElementReferenceException .class.cast(function.foundStaleElementReferenceException); } throw e; } }
@Test(expected = TimeoutException.class) public void nullPointerExceptionSafetyTestWithPrecondition() { Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context")) .withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500)); assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0); }
@Test(expected = TimeoutException.class) public void nullPointerExceptionSafetyTestWithPostConditions() { Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context")) .withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500)); assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0); } }
@Test public void complexWaitingTestWithPreCondition() { AppiumFunction<Pattern, List<WebElement>> compositeFunction = searchingFunction.compose(contextFunction); Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW")) .withTimeout(ofSeconds(30)); List<WebElement> elements = wait.until(compositeFunction); assertThat("Element size should be 1", elements.size(), is(1)); assertThat("WebView is expected", driver.getContext(), containsString("WEBVIEW")); }
.withTimeout(ofSeconds(30)); List<WebElement> elements = wait.until(compositeFunction); assertThat("Element size should be 1", elements.size(), is(1));
@Override public SebContextWait withTimeout(long duration, TimeUnit unit) { super.withTimeout(duration, unit); this.timeout = new Duration(duration, unit); return this; }
public FluentWait<WebDriver> doWait() { return new FluentWait(driver) .withTimeout(waitForTimeout) .pollingEvery(Duration.ofMillis(WAIT_FOR_ELEMENT_PAUSE_LENGTH)) .ignoreAll(NewList.of(NoSuchElementException.class, NoSuchFrameException.class, StaleElementReferenceException.class, InvalidElementStateException.class)); }
@Override public Wait<WebDriver> waitForCondition() { return new FluentWait<WebDriver>(driver, webdriverClock, sleeper) .withTimeout(timeoutInMilliseconds, TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
public FluentWait<WebDriver> doWait() { return new FluentWait(driver) .withTimeout(waitForTimeoutInMilliseconds, TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
@Override public Wait<WebDriver> waitForCondition() { return new FluentWait<>(driver, webdriverClock, sleeper) .withTimeout(waitForTimeoutInMilliseconds, TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
private Wait<WebDriver> waitBriefly() { return new FluentWait<>(driver, webdriverClock, sleeper) .withTimeout(500, TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
@Override public Wait<WebDriver> waitForCondition() { return new FluentWait<>(driver, webdriverClock, sleeper) .withTimeout(waitForTimeoutInMilliseconds, TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
public FluentWait<WebDriver> doWait() { return new FluentWait(driver) .withTimeout(waitForTimeout.in(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .pollingEvery(WAIT_FOR_ELEMENT_PAUSE_LENGTH, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class, NoSuchFrameException.class); }
public Replies waitForReplyToAppearWithOpenGraph(final String url) { new FluentWait<>(driver).withTimeout(DiscussionsConstants.TIMEOUT, TimeUnit.SECONDS) .until((Function<WikiaWebDriver, Boolean>) input -> wait.forElementVisible(replyOpenGraph) .getAttribute("href") .contains(url)); return this; }
default Element untilFound(Supplier<By> by) { waitForPageToLoad(); return new FluentWait<>(this) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.MILLISECONDS) .ignoring(Exception.class) .until((ExplicitWait e) -> e.findElement(by)); }
public void waitForLoadingSpinnerWith(final String categoryName) { waitForLoadingSpinner(); changeImplicitWait(0, TimeUnit.SECONDS); try { new FluentWait<>(getPost()).withTimeout(DiscussionsConstants.TIMEOUT, TimeUnit.SECONDS) .until((Function<Post, Boolean>) p -> p.getPosts() .stream() .allMatch(postEntity -> postEntity.findCategory().endsWith(categoryName))); } finally { restoreDefaultImplicitWait(); } }
default Element untilFound2(Supplier<By> by) { waitForPageToLoad(); Element element = new FluentWait<>(this) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.MILLISECONDS) .ignoring(Exception.class) .until((ExplicitWait e) -> e.findElement(by)); element.setSearchContext(this); element.setLocator((ExplicitWait e) -> this.untilFound2(by)); return element; }