diff --git a/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java b/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java index 2de1a59794f7e..06d89c85ec630 100644 --- a/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java +++ b/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java @@ -24,6 +24,7 @@ import org.openqa.selenium.WrapsDriver; import org.openqa.selenium.remote.RemoteWebDriver; +import java.time.Clock; import java.time.Duration; /** @@ -38,16 +39,31 @@ public class WebDriverWait extends FluentWait { * list by calling ignoring(exceptions to add). * * @param driver The WebDriver instance to pass to the expected conditions - * @param timeOutInSeconds The timeout in seconds when an expectation is called + * @param timeoutInSeconds The timeout in seconds when an expectation is called * @see WebDriverWait#ignoring(java.lang.Class) + * @deprecated Instead, use {@link WebDriverWait#WebDriverWait(WebDriver, Duration)}. */ - public WebDriverWait(WebDriver driver, long timeOutInSeconds) { + @Deprecated + public WebDriverWait(WebDriver driver, long timeoutInSeconds) { + this(driver, Duration.ofSeconds(timeoutInSeconds)); + } + + /** + * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in + * the 'until' condition, and immediately propagate all others. You can add more to the ignore + * list by calling ignoring(exceptions to add). + * + * @param driver The WebDriver instance to pass to the expected conditions + * @param timeout The timeout when an expectation is called + * @see WebDriverWait#ignoring(java.lang.Class) + */ + public WebDriverWait(WebDriver driver, Duration timeout) { this( driver, - java.time.Clock.systemDefaultZone(), - Sleeper.SYSTEM_SLEEPER, - timeOutInSeconds, - DEFAULT_SLEEP_TIMEOUT); + timeout, + Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT), + Clock.systemDefaultZone(), + Sleeper.SYSTEM_SLEEPER); } /** @@ -56,35 +72,62 @@ public WebDriverWait(WebDriver driver, long timeOutInSeconds) { * list by calling ignoring(exceptions to add). * * @param driver The WebDriver instance to pass to the expected conditions - * @param timeOutInSeconds The timeout in seconds when an expectation is called + * @param timeoutInSeconds The timeout in seconds when an expectation is called * @param sleepInMillis The duration in milliseconds to sleep between polls. * @see WebDriverWait#ignoring(java.lang.Class) + * @deprecated Instead, use {@link WebDriverWait#WebDriverWait(WebDriver, Duration, Duration)}. */ - public WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis) { + @Deprecated + public WebDriverWait(WebDriver driver, long timeoutInSeconds, long sleepInMillis) { + this(driver, Duration.ofSeconds(timeoutInSeconds), Duration.ofMillis(sleepInMillis)); + } + + /** + * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in + * the 'until' condition, and immediately propagate all others. You can add more to the ignore + * list by calling ignoring(exceptions to add). + * + * @param driver The WebDriver instance to pass to the expected conditions + * @param timeoutInSeconds The timeout in seconds when an expectation is called + * @param sleepInMillis The duration in milliseconds to sleep between polls. + * @see WebDriverWait#ignoring(java.lang.Class) + */ + public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep) { + this(driver, timeout, sleep, Clock.systemDefaultZone(), Sleeper.SYSTEM_SLEEPER); + } + + /** + * @param driver the WebDriver instance to pass to the expected conditions + * @param clock used when measuring the timeout + * @param sleeper used to make the current thread go to sleep + * @param timeoutInSeconds the timeout in seconds when an expectation is called + * @param sleepInMillis the timeout in millis used whilst sleeping + * @deprecated Instead, use {@link WebDriverWait#WebDriverWait(WebDriver, Duration, Duration, + * Clock, Sleeper)}. + */ + @Deprecated + public WebDriverWait( + WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis) { this( driver, - java.time.Clock.systemDefaultZone(), - Sleeper.SYSTEM_SLEEPER, - timeOutInSeconds, - sleepInMillis); + Duration.ofSeconds(timeoutInSeconds), + Duration.ofMillis(sleepInMillis), + clock, + sleeper); } /** - * @param driver The WebDriver instance to pass to the expected conditions - * @param clock The clock to use when measuring the timeout - * @param sleeper Object used to make the current thread go to sleep. - * @param timeOutInSeconds The timeout in seconds when an expectation is - * @param sleepTimeOut The timeout used whilst sleeping. Defaults to 500ms called. + * @param driver the WebDriver instance to pass to the expected conditions + * @param clock used when measuring the timeout + * @param sleeper used to make the current thread go to sleep + * @param timeout the timeout when an expectation is called + * @param sleep the timeout used whilst sleeping */ public WebDriverWait( - WebDriver driver, - java.time.Clock clock, - Sleeper sleeper, - long timeOutInSeconds, - long sleepTimeOut) { + WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper) { super(driver, clock, sleeper); - withTimeout(Duration.ofSeconds(timeOutInSeconds)); - pollingEvery(Duration.ofMillis(sleepTimeOut)); + withTimeout(timeout); + pollingEvery(sleep); ignoring(NotFoundException.class); this.driver = driver; }