/** * Creates a generic {@code FluentWait<WebDriver>} instance * using the underlying web driver. * * @return the webdriver contained in a fluent wait. */ public FluentWait<WebDriver> fluentWait() { return new FluentWait<WebDriver>(super.getDriver()); }
/** * Creates a generic {@code FluentWait<WebDriver>} instance * using the underlying web driver. * * @return the webdriver contained in a fluent wait. */ public FluentWait<WebDriver> fluentWait() { return new FluentWait<WebDriver>(super.getDriver()); }
/** * Creates a generic {@code FluentWait<WebDriver>} instance * using the underlying web driver */ public FluentWait<WebDriver> fluentWait() { return new FluentWait<WebDriver>(super.getDriver()); }
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; } }
@Override public WebElement findElement(SearchContext context) { AppiumFunction<SearchContext, WebElement> searchingFunction = null; for (By by: bys) { searchingFunction = Optional.ofNullable(searchingFunction != null ? searchingFunction.andThen(getSearchingFunction(by)) : null).orElse(getSearchingFunction(by)); } FluentWait<SearchContext> waiting = new FluentWait<>(context); try { checkNotNull(searchingFunction); return waiting.until(searchingFunction); } catch (TimeoutException e) { throw new NoSuchElementException("Cannot locate an element using " + toString()); } } }
@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")); }
}); Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW")) .withTimeout(ofSeconds(30)); List<WebElement> elements = wait.until(compositeFunction);
/** * Creates a generic FluentWait<WebDriver> instance * using the underlying web driver */ public FluentWait<WebDriver> fluentWait() { return new FluentWait<WebDriver>(super.getDriver()); }
@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); }
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<>(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; }