Class AppiumFluentWait<T>

  • All Implemented Interfaces:
    org.openqa.selenium.support.ui.Wait<T>

    public class AppiumFluentWait<T>
    extends org.openqa.selenium.support.ui.FluentWait<T>
    • Field Summary

      • Fields inherited from class org.openqa.selenium.support.ui.FluentWait

        DEFAULT_SLEEP_TIMEOUT
    • Constructor Summary

      Constructors 
      Constructor Description
      AppiumFluentWait​(T input)
      The input value to pass to the evaluated conditions.
      AppiumFluentWait​(T input, java.time.Clock clock, org.openqa.selenium.support.ui.Sleeper sleeper)
      Creates wait object based on input value, clock and sleeper.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.time.Clock getClock()  
      protected java.util.List<java.lang.Class<? extends java.lang.Throwable>> getIgnoredExceptions()  
      protected T getInput()  
      protected java.time.Duration getInterval()  
      protected java.util.function.Supplier<java.lang.String> getMessageSupplier()  
      protected org.openqa.selenium.support.ui.Sleeper getSleeper()  
      protected java.time.Duration getTimeout()  
      protected java.lang.Throwable propagateIfNotIgnored​(java.lang.Throwable e)  
      <V> V until​(java.util.function.Function<? super T,​V> isTrue)
      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 timeout expires, the current thread is interrupted .
      AppiumFluentWait<T> withPollingStrategy​(java.util.function.Function<AppiumFluentWait.IterationInfo,​java.time.Duration> pollingStrategy)
      Sets the strategy for polling.
      • Methods inherited from class org.openqa.selenium.support.ui.FluentWait

        ignoreAll, ignoring, ignoring, pollingEvery, timeoutException, withMessage, withMessage, withTimeout
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AppiumFluentWait

        public AppiumFluentWait​(T input)
        The input value to pass to the evaluated conditions.
        Parameters:
        input - The input value to pass to the evaluated conditions.
      • AppiumFluentWait

        public AppiumFluentWait​(T input,
                                java.time.Clock clock,
                                org.openqa.selenium.support.ui.Sleeper sleeper)
        Creates wait object based on input value, clock and sleeper.
        Parameters:
        input - The input value to pass to the evaluated conditions.
        clock - The clock to use when measuring the timeout.
        sleeper - Used to put the thread to sleep between evaluation loops.
    • Method Detail

      • getClock

        protected java.time.Clock getClock()
      • getTimeout

        protected java.time.Duration getTimeout()
      • getInterval

        protected java.time.Duration getInterval()
      • getSleeper

        protected org.openqa.selenium.support.ui.Sleeper getSleeper()
      • getIgnoredExceptions

        protected java.util.List<java.lang.Class<? extends java.lang.Throwable>> getIgnoredExceptions()
      • getMessageSupplier

        protected java.util.function.Supplier<java.lang.String> getMessageSupplier()
      • getInput

        protected T getInput()
      • withPollingStrategy

        public AppiumFluentWait<T> withPollingStrategy​(java.util.function.Function<AppiumFluentWait.IterationInfo,​java.time.Duration> pollingStrategy)
        Sets the strategy for polling. The default strategy is null, which means, that polling interval is always a constant value and is set by FluentWait.pollingEvery(Duration) method. Otherwise the value set by that method might be just a helper to calculate the actual interval. Although, by setting an alternative polling strategy you may flexibly control the duration of this interval for each polling round. For example we'd like to wait two times longer than before each time we cannot find an element: final Wait<WebElement> wait = new AppiumFluentWait<>(el) .withPollingStrategy(info -> new Duration(info.getNumber() * 2, TimeUnit.SECONDS)) .withTimeout(6, TimeUnit.SECONDS); wait.until(WebElement::isDisplayed); Or we want the next time period is Euler's number e raised to the power of current iteration number: final Wait<WebElement> wait = new AppiumFluentWait<>(el) .withPollingStrategy(info -> new Duration((long) Math.exp(info.getNumber()), TimeUnit.SECONDS)) .withTimeout(6, TimeUnit.SECONDS); wait.until(WebElement::isDisplayed); Or we'd like to have some advanced algorithm, which waits longer first, but then use the default interval when it reaches some constant: final Wait<WebElement> wait = new AppiumFluentWait<>(el) .withPollingStrategy(info -> new Duration(info.getNumber() < 5 ? 4 - info.getNumber() : info.getInterval().in(TimeUnit.SECONDS), TimeUnit.SECONDS)) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(1, TimeUnit.SECONDS); wait.until(WebElement::isDisplayed);
        Parameters:
        pollingStrategy - Function instance, where the first parameter is the information about the current loop iteration (see AppiumFluentWait.IterationInfo) and the expected result is the calculated interval. It is highly recommended that the value returned by this lambda is greater than zero.
        Returns:
        A self reference.
      • until

        public <V> V until​(java.util.function.Function<? super T,​V> isTrue)
        Repeatedly applies this instance's input value to the given function until one of the following occurs:
        1. the function returns neither null nor false,
        2. the function throws an unignored exception,
        3. the timeout expires,
        4. the current thread is interrupted
        .
        Specified by:
        until in interface org.openqa.selenium.support.ui.Wait<T>
        Overrides:
        until in class org.openqa.selenium.support.ui.FluentWait<T>
        Type Parameters:
        V - The function's expected return type.
        Parameters:
        isTrue - the parameter to pass to the expected condition
        Returns:
        The functions' return value if the function returned something different from null or false before the timeout expired.
        Throws:
        org.openqa.selenium.TimeoutException - If the timeout expires.
      • propagateIfNotIgnored

        protected java.lang.Throwable propagateIfNotIgnored​(java.lang.Throwable e)