View Javadoc

1   package com.atlassian.webdriver.waiter.webdriver;
2   
3   import com.atlassian.annotations.ExperimentalApi;
4   import org.openqa.selenium.NotFoundException;
5   import org.openqa.selenium.WebDriver;
6   import org.openqa.selenium.support.ui.Clock;
7   import org.openqa.selenium.support.ui.FluentWait;
8   import org.openqa.selenium.support.ui.Sleeper;
9   import org.openqa.selenium.support.ui.SystemClock;
10  import org.openqa.selenium.support.ui.WebDriverWait;
11  
12  import java.util.concurrent.TimeUnit;
13  
14  /**
15   * A specialization of {@link FluentWait} that uses WebDriver instances
16   * and uses milliseconds for the time interval instead of seconds.
17   * @see org.openqa.selenium.support.ui.WebDriverWait
18   *
19   * <strong>WARNING</strong>: This API is still experimental and may be changed between versions.
20   *
21   * @since 2.1.0
22   */
23  @ExperimentalApi
24  public class AtlassianWebDriverWait extends FluentWait<WebDriver>
25  {
26      public AtlassianWebDriverWait(WebDriver input, Clock clock, Sleeper sleeper)
27      {
28          super(input, clock, sleeper);
29      }
30      
31      /**
32     * @param driver The WebDriver instance to pass to the expected conditions
33     * @param timeOutInMilliSeconds The timeout in seconds when an expectation is
34     * called
35     */
36    public AtlassianWebDriverWait(WebDriver driver, long timeOutInMilliSeconds) {
37      this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInMilliSeconds,
38              WebDriverWait.DEFAULT_SLEEP_TIMEOUT
39      );
40    }
41  
42    /**
43     * @param driver The WebDriver instance to pass to the expected conditions
44     * @param timeOutInMilliSeconds The timeout in seconds when an expectation is
45     * called
46     * @param sleepInMillis The duration in milliseconds to sleep between polls.
47     */
48    public AtlassianWebDriverWait(WebDriver driver, long timeOutInMilliSeconds, long sleepInMillis) {
49      this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInMilliSeconds, sleepInMillis);
50    }
51  
52    /**
53     * @param driver The WebDriver instance to pass to the expected conditions
54     * @param clock The clock to use when measuring the timeout
55     * @param sleeper Object used to make the current thread go to sleep.
56     * @param timeOutInMilliSeconds The timeout in seconds when an expectation is
57     * @param sleepTimeOut The timeout used whilst sleeping. Defaults to 500ms
58  *     called.
59     */
60    protected AtlassianWebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper,
61            long timeOutInMilliSeconds, long sleepTimeOut) {
62      super(driver, clock, sleeper);
63      withTimeout(timeOutInMilliSeconds, TimeUnit.MILLISECONDS);
64      pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS);
65      ignoring(NotFoundException.class);
66    }
67      
68  }