Skip to content

Commit aee2417

Browse files
authored
use lambda expression in the Fluent Wait example (SeleniumHQ#1245)
When we use the code of the previous example, Sonar Lint says : Anonymous inner classes containing only one method should become lambdas (java:S1604) Before Java 8, the only way to partially support closures in Java was by using anonymous inner classes. But the syntax of anonymous classes may seem unwieldy and unclear. With Java 8, most uses of anonymous inner classes should be replaced by lambdas to highly increase the readability of the source code. Body of commit message is a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc. This example uses a lambda function. Fixes SeleniumHQ#1243 [deploy site]
1 parent 3a4bd47 commit aee2417

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

website_and_docs/content/documentation/webdriver/waits.en.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
437437
.pollingEvery(Duration.ofSeconds(5))
438438
.ignoring(NoSuchElementException.class);
439439

440-
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
441-
public WebElement apply(WebDriver driver) {
442-
return driver.findElement(By.id("foo"));
443-
}
440+
WebElement foo = wait.until(driver -> {
441+
return driver.findElement(By.id("foo"));
444442
});
445443
{{< /tab >}}
446444
{{< tab header="Python" >}}

website_and_docs/content/documentation/webdriver/waits.ja.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
358358
.pollingEvery(Duration.ofSeconds(5))
359359
.ignoring(NoSuchElementException.class);
360360

361-
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
362-
public WebElement apply(WebDriver driver) {
363-
return driver.findElement(By.id("foo"));
364-
}
361+
WebElement foo = wait.until(driver -> {
362+
return driver.findElement(By.id("foo"));
365363
});
366364
{{< /tab >}}
367365
{{< tab header="Python" >}}

website_and_docs/content/documentation/webdriver/waits.pt-br.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
444444
.pollingEvery(Duration.ofSeconds(5))
445445
.ignoring(NoSuchElementException.class);
446446

447-
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
448-
public WebElement apply(WebDriver driver) {
449-
return driver.findElement(By.id("foo"));
450-
}
447+
WebElement foo = wait.until(driver -> {
448+
return driver.findElement(By.id("foo"));
451449
});
452450
{{< /tab >}}
453451
{{< tab header="Python" >}}

website_and_docs/content/documentation/webdriver/waits.zh-cn.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,8 @@ Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
336336
.pollingEvery(Duration.ofSeconds(5))
337337
.ignoring(NoSuchElementException.class);
338338

339-
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
340-
public WebElement apply(WebDriver driver) {
341-
return driver.findElement(By.id("foo"));
342-
}
339+
WebElement foo = wait.until(driver -> {
340+
return driver.findElement(By.id("foo"));
343341
});
344342
{{< /tab >}}
345343
{{< tab header="Python" >}}

0 commit comments

Comments
 (0)