org.openqa.selenium.support.ui

Class FluentWait<T>

  • Type Parameters:
    T - The input type for each condition used with this instance.
    All Implemented Interfaces:
    Wait<T>
    Direct Known Subclasses:
    WebDriverWait


    public class FluentWait<T>extends Objectimplements Wait<T>
    An implementation of the Wait interface that may have its timeout and polling interval configured on the fly.

    Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.

    Sample usage:

       // Waiting 30 seconds for an element to be present on the page, checking   // for its presence once every 5 seconds.   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"));     }   }); 

    This class makes no thread safety guarantees.

    • Field Detail

      • FIVE_HUNDRED_MILLIS

        public static final Duration FIVE_HUNDRED_MILLIS
    • Constructor Detail

      • FluentWait

        public FluentWait(T input)
        Parameters:
        input - The input value to pass to the evaluated conditions.
      • FluentWait

        public FluentWait(T input,                  Clock clock,                  Sleeper sleeper)
        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

      • withTimeout

        public FluentWait<T> withTimeout(long duration,                                 TimeUnit unit)
        Sets how long to wait for the evaluated condition to be true. The default timeout is FIVE_HUNDRED_MILLIS.
        Parameters:
        duration - The timeout duration.
        unit - The unit of time.
        Returns:
        A self reference.
      • withMessage

        public FluentWait<T> withMessage(String message)
        Sets the message to be displayed when time expires.
        Parameters:
        message - to be appended to default.
        Returns:
        A self reference.
      • withMessage

        public FluentWait<T> withMessage(com.google.common.base.Supplier<String> messageSupplier)
        Sets the message to be evaluated and displayed when time expires.
        Parameters:
        messageSupplier - to be evaluated on failure and appended to default.
        Returns:
        A self reference.
      • pollingEvery

        public FluentWait<T> pollingEvery(long duration,                                  TimeUnit unit)
        Sets how often the condition should be evaluated.

        In reality, the interval may be greater as the cost of actually evaluating a condition function is not factored in. The default polling interval is FIVE_HUNDRED_MILLIS.

        Parameters:
        duration - The timeout duration.
        unit - The unit of time.
        Returns:
        A self reference.
      • ignoreAll

        public <K extends ThrowableFluentWait<T> ignoreAll(Collection<Class<? extends K>> types)
        Configures this instance to ignore specific types of exceptions while waiting for a condition. Any exceptions not whitelisted will be allowed to propagate, terminating the wait.
        Type Parameters:
        K - an Exception that extends Throwable
        Parameters:
        types - The types of exceptions to ignore.
        Returns:
        A self reference.
      • until

        public void until(com.google.common.base.Predicate<T> isTrue)
        Repeatedly applies this instance's input value to the given predicate until the timeout expires or the predicate evaluates to true.
        Parameters:
        isTrue - The predicate to wait on.
        Throws:
        org.openqa.selenium.TimeoutException - If the timeout expires.
      • until

        public <V> V until(com.google.common.base.Function<? super T,V> isTrue)
        Repeatedly applies this instance's input value to the given function until one of the following occurs:
        1. the function returns neither null nor false,
        2. the function throws an unignored exception,
        3. the timeout expires,
        4. the current thread is interrupted
        Specified by:
        until in interface Wait<T>
        Type Parameters:
        V - The function's expected return type.
        Parameters:
        isTrue - the parameter to pass to the ExpectedCondition
        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.
      • timeoutException

        protected RuntimeException timeoutException(String message,                                            Throwable lastException)
        Throws a timeout exception. This method may be overridden to throw an exception that is idiomatic for a particular test infrastructure, such as an AssertionError in JUnit4.
        Parameters:
        message - The timeout message.
        lastException - The last exception to be thrown and subsequently suppressed while waiting on a function.
        Returns:
        Nothing will ever be returned; this return type is only specified as a convenience.

Copyright © 2016. All rights reserved.



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14