public class AppiumFluentWait<T>
extends org.openqa.selenium.support.ui.FluentWait<T>
Modifier and Type | Class and Description |
---|---|
static class |
AppiumFluentWait.IterationInfo |
Constructor and Description |
---|
AppiumFluentWait(T input)
The input value to pass to the evaluated conditions.
|
AppiumFluentWait(T input,
org.openqa.selenium.support.ui.Clock clock,
org.openqa.selenium.support.ui.Sleeper sleeper)
Creates wait object based on
input value, clock and sleeper . |
Modifier and Type | Method and Description |
---|---|
protected org.openqa.selenium.support.ui.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.
|
public AppiumFluentWait(T input)
input
- The input value to pass to the evaluated conditions.public AppiumFluentWait(T input, org.openqa.selenium.support.ui.Clock clock, org.openqa.selenium.support.ui.Sleeper sleeper)
input
value, clock
and sleeper
.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.protected org.openqa.selenium.support.ui.Clock getClock()
protected java.time.Duration getTimeout()
protected java.time.Duration getInterval()
protected org.openqa.selenium.support.ui.Sleeper getSleeper()
protected java.util.List<java.lang.Class<? extends java.lang.Throwable>> getIgnoredExceptions()
protected java.util.function.Supplier<java.lang.String> getMessageSupplier()
protected T getInput()
public AppiumFluentWait<T> withPollingStrategy(java.util.function.Function<AppiumFluentWait.IterationInfo,java.time.Duration> pollingStrategy)
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);
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.public <V> V until(java.util.function.Function<? super T,V> isTrue)
until
in interface org.openqa.selenium.support.ui.Wait<T>
until
in class org.openqa.selenium.support.ui.FluentWait<T>
V
- The function's expected return type.isTrue
- the parameter to pass to the expected conditionorg.openqa.selenium.TimeoutException
- If the timeout expires.protected java.lang.Throwable propagateIfNotIgnored(java.lang.Throwable e)