Class AppiumFluentWait<T>

java.lang.Object
org.openqa.selenium.support.ui.FluentWait<T>
io.appium.java_client.AppiumFluentWait<T>
All Implemented Interfaces:
org.openqa.selenium.support.ui.Wait<T>

@NullMarked public class AppiumFluentWait<T> extends org.openqa.selenium.support.ui.FluentWait<T>
  • Constructor Details

    • 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, 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 Details

    • withPollDelay

      public AppiumFluentWait<T> withPollDelay(Duration pollDelay)
      Sets how long to wait before starting to evaluate condition to be true. The default pollDelay is DEFAULT_POLL_DELAY_DURATION.
      Parameters:
      pollDelay - The pollDelay duration.
      Returns:
      A self reference.
    • getClock

      protected Clock getClock()
    • getTimeout

      protected Duration getTimeout()
    • getInterval

      protected Duration getInterval()
    • getSleeper

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

      protected List<Class<? extends Throwable>> getIgnoredExceptions()
    • getMessageSupplier

      protected Supplier<@Nullable String> getMessageSupplier()
    • getInput

      protected T getInput()
    • withPollingStrategy

      public AppiumFluentWait<T> withPollingStrategy(Function<AppiumFluentWait.IterationInfo,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 extends @Nullable Object> @NonNull V until(Function<? super T,? extends 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 Throwable propagateIfNotIgnored(Throwable e)