Implicit,Explicit and Fluent waits

Implicit waits:

Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step across the entire test script.

Ex:driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

In the above example we are implementing a default wait time of 10 sec between each consecutive test step.


Explicit waits:
Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, Explicit waits are applied for a particular step only.

Ex: WebDriverWait wait = new WebDriverWait(driver,30);
       wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));


Fluent wait:
FluentWait defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition(polling). In addition the user may configure the wait to ignore specific types of exceptions while waiting such as NoSuchElementExceptions when searching for an element on the page.

Ex: Wait wait = new FluentWait(driver)

     .withTimeout(30, SECONDS)

    .pollingEvery(5, SECONDS)

    .ignoring(NoSuchElementException.class);

     WebElement fw = wait.until(new Function()
    {

    public WebElement apply(WebDriver driver)
    {

    return driver.findElement(By.id("fw"));

    }

   });

 In above example there is waiting for 30 seconds for an element to be present on the page and checking for its presence once every 5 seconds.