Fluent Wait uses two parameters β timeout value and polling frequency.
1. The maximum amount of time to wait for a condition
2. The frequency to check the success or failure of a specified condition.
Also, if you want to configure the wait to ignore exceptions such as , then you can add it to the Fluent Wait command syntax.
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
analyze of the above sample code.
1. Fluent Wait starts with capturing the start time to determine the delay.
2. Fluent Wait then checks the condition defined in the until() method.
3. If the condition fails, Fluent Wait makes the application to wait as per the value set by the pollingEvery(5, SECONDS)
method call. Here in this example, itβs 5 seconds.
4. After the wait defined in Step 3 expires, the start time is checked against the current time. If the difference of the wait start time (set in step-1) and the current time is less than the time set in withTimeout(30, SECONDS
) method, then Step-2 will need to repeat.
The above steps will recur until either the timeout expires or the condition becomes true.
Function is the functional interface
@FunctionalInterface
public interface Function<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
*/
R apply(T t);
/**
* Returns a composed function that first applies the {@code before}
* function to its input, and then applies this function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param <V> the type of input to the {@code before} function, and to the
* composed function
* @param before the function to apply before this function is applied
* @return a composed function that first applies the {@code before}
* function and then applies this function
* @throws NullPointerException if before is null
*