Skip to content

Commit

Permalink
Add Duration-based constructors to WebDriverWait
Browse files Browse the repository at this point in the history
Also deprecate the ambiguous `long`-based constructors.
  • Loading branch information
kluever authored and shs96c committed May 16, 2019
1 parent c5334a3 commit 55fbedc
Showing 1 changed file with 67 additions and 24 deletions.
91 changes: 67 additions & 24 deletions java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.time.Clock;
import java.time.Duration;

/**
Expand All @@ -38,16 +39,31 @@ public class WebDriverWait extends FluentWait<WebDriver> {
* 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);
}

/**
Expand All @@ -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;
}
Expand Down

0 comments on commit 55fbedc

Please sign in to comment.