Skip to content

Commit b2aa9fd

Browse files
committed
Update Wait and FluentWait for Java 8
With recent guava release, the Google versions of both Function and Predicate extend the Java 8 equivalents & so it's safe for us to make this move. Probably.
1 parent 6b8bdae commit b2aa9fd

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

java/client/src/org/openqa/selenium/support/ui/FluentWait.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2222
import static java.util.concurrent.TimeUnit.SECONDS;
2323

24-
import com.google.common.base.Function;
25-
import com.google.common.base.Predicate;
26-
import com.google.common.base.Supplier;
2724
import com.google.common.base.Throwables;
2825
import com.google.common.collect.ImmutableList;
2926
import com.google.common.collect.Lists;
@@ -34,6 +31,9 @@
3431
import java.util.Collection;
3532
import java.util.List;
3633
import java.util.concurrent.TimeUnit;
34+
import java.util.function.Function;
35+
import java.util.function.Predicate;
36+
import java.util.function.Supplier;
3737

3838
/**
3939
* An implementation of the {@link Wait} interface that may have its timeout and polling interval
@@ -50,12 +50,12 @@
5050
* Sample usage: <pre>
5151
* // Waiting 30 seconds for an element to be present on the page, checking
5252
* // for its presence once every 5 seconds.
53-
* Wait{@literal<WebDriver>} wait = new FluentWait{@literal<WebDriver>}(driver)
53+
* Wait&lt;WebDriver> wait = new FluentWait&lt;WebDriver>(driver)
5454
* .withTimeout(30, SECONDS)
5555
* .pollingEvery(5, SECONDS)
5656
* .ignoring(NoSuchElementException.class);
5757
*
58-
* WebElement foo = wait.until(new Function{@literal<WebDriver, WebElement>}() {
58+
* WebElement foo = wait.until(new Function&lt;WebDriver, WebElement>() {
5959
* public WebElement apply(WebDriver driver) {
6060
* return driver.findElement(By.id("foo"));
6161
* }
@@ -181,21 +181,24 @@ public FluentWait<T> ignoring(Class<? extends Throwable> exceptionType) {
181181
public FluentWait<T> ignoring(Class<? extends Throwable> firstType,
182182
Class<? extends Throwable> secondType) {
183183

184-
return this.ignoreAll(ImmutableList.<Class<? extends Throwable>>of(firstType, secondType));
184+
return this.ignoreAll(ImmutableList.of(firstType, secondType));
185185
}
186186

187187
/**
188188
* Repeatedly applies this instance's input value to the given predicate until the timeout expires
189-
* or the predicate evaluates to true.
189+
* or the predicate evaluates to true. This method has been deprecated to simplify the use of
190+
* Java 8 lambda expressions with this class. It is suggested calls to this method be replaced by
191+
* calls to {@link #until(Function)}.
190192
*
191193
* @param isTrue The predicate to wait on.
192194
* @throws TimeoutException If the timeout expires.
195+
* @deprecated Use a {@link Function} that returns a Boolean.
193196
*/
194197
public void until(final Predicate<T> isTrue) {
195198
until(new Function<T, Boolean>() {
196199
@Override
197200
public Boolean apply(T input) {
198-
return isTrue.apply(input);
201+
return isTrue.test(input);
199202
}
200203

201204
@Override
@@ -269,7 +272,8 @@ private Throwable propagateIfNotIgnored(Throwable e) {
269272
return e;
270273
}
271274
}
272-
throw Throwables.propagate(e);
275+
Throwables.throwIfUnchecked(e);
276+
throw new RuntimeException(e);
273277
}
274278

275279
/**

java/client/src/org/openqa/selenium/support/ui/Wait.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.openqa.selenium.support.ui;
1919

20-
import com.google.common.base.Function;
20+
import java.util.function.Function;
2121

2222
/**
2323
* A generic interface for waiting until a condition is true or not null. The condition may take a

0 commit comments

Comments
 (0)