Fluent wait
Fluent wait is a type of explicit wait where we can define polling intervals and ignore certain exceptions to proceed with further script execution even if the element is not found.
So, when we specify a fluent wait, we provide the following:
- Maximum wait time
- Polling interval or frequency to check the element
- Any specific exception to ignore
- Message that should appear after timeout
A simple example of a fluent wait implementation is as follows:
Wait wait = new FluentWait(appiumDriver) .withTimeout(10, TimeUnit.SECONDS) .pollingEvery(250, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(TimeoutException.class); wait.until(ExpectedConditions.visibilityOfElementLocated (By.id("text1")));
Let's implement the preceding in the iChooseAsMyCity(String city)
method and re-run the test to see what the results are:
@And("^I choose \"([^\"]*)\" as my city$") public void iChooseAsMyCity(String city) throws Throwable { Wait wait = new FluentWait...