Package io.appium.java_client
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>
public class AppiumFluentWait<T> extends org.openqa.selenium.support.ui.FluentWait<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AppiumFluentWait.IterationInfo
-
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 oninput
value,clock
andsleeper
.
-
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>
withPollDelay(java.time.Duration pollDelay)
Sets how long to wait before starting to evaluate condition to be true.AppiumFluentWait<T>
withPollingStrategy(java.util.function.Function<AppiumFluentWait.IterationInfo,java.time.Duration> pollingStrategy)
Sets the strategy for polling.
-
-
-
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 oninput
value,clock
andsleeper
.- 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
-
withPollDelay
public AppiumFluentWait<T> withPollDelay(java.time.Duration pollDelay)
Sets how long to wait before starting to evaluate condition to be true. The default pollDelay isDEFAULT_POLL_DELAY_DURATION
.- Parameters:
pollDelay
- The pollDelay duration.- Returns:
- A self reference.
-
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 byFluentWait.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 (seeAppiumFluentWait.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:- the function returns neither null nor false,
- the function throws an unignored exception,
- the timeout expires,
- the current thread is interrupted
- Specified by:
until
in interfaceorg.openqa.selenium.support.ui.Wait<T>
- Overrides:
until
in classorg.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)
-
-