Skip to content

Commit 9a86fcb

Browse files
committed
Fix logic to find success box in page objects
1 parent 054ade1 commit 9a86fcb

File tree

12 files changed

+76
-36
lines changed

12 files changed

+76
-36
lines changed

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch07/page_objects/BasicLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void with(String username, String password) {
4747
}
4848

4949
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
50+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
5151
WebElement success = wait.until(
5252
ExpectedConditions.visibilityOfElementLocated(successBox));
5353
return success.isDisplayed();

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch07/page_objects/ExtendedLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020

2121
import org.openqa.selenium.By;
22+
import org.openqa.selenium.TimeoutException;
2223
import org.openqa.selenium.WebElement;
2324
import org.openqa.selenium.support.ui.ExpectedConditions;
2425
import org.openqa.selenium.support.ui.WebDriverWait;
@@ -47,10 +48,14 @@ public void with(String username, String password) {
4748
}
4849

4950
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
51-
WebElement success = wait.until(
52-
ExpectedConditions.visibilityOfElementLocated(successBox));
53-
return success.isDisplayed();
51+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
52+
try {
53+
WebElement success = wait.until(
54+
ExpectedConditions.visibilityOfElementLocated(successBox));
55+
return success.isDisplayed();
56+
} catch (TimeoutException e) {
57+
return false;
58+
}
5459
}
5560

5661
}

selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch07/page_objects/FactoryLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.Duration;
2020

21+
import org.openqa.selenium.TimeoutException;
2122
import org.openqa.selenium.WebElement;
2223
import org.openqa.selenium.support.CacheLookup;
2324
import org.openqa.selenium.support.FindBy;
@@ -61,10 +62,14 @@ public void with(String username, String password) {
6162
}
6263

6364
public boolean successBoxPresent() {
64-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
65-
WebElement success = wait
66-
.until(ExpectedConditions.visibilityOf(successBox));
67-
return success.isDisplayed();
65+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
66+
try {
67+
WebElement success = wait
68+
.until(ExpectedConditions.visibilityOf(successBox));
69+
return success.isDisplayed();
70+
} catch (TimeoutException e) {
71+
return false;
72+
}
6873
}
6974

7075
}

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch07/page_objects/BasicLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void with(String username, String password) {
4747
}
4848

4949
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
50+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
5151
WebElement success = wait.until(
5252
ExpectedConditions.visibilityOfElementLocated(successBox));
5353
return success.isDisplayed();

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch07/page_objects/ExtendedLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020

2121
import org.openqa.selenium.By;
22+
import org.openqa.selenium.TimeoutException;
2223
import org.openqa.selenium.WebElement;
2324
import org.openqa.selenium.support.ui.ExpectedConditions;
2425
import org.openqa.selenium.support.ui.WebDriverWait;
@@ -47,10 +48,14 @@ public void with(String username, String password) {
4748
}
4849

4950
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
51-
WebElement success = wait.until(
52-
ExpectedConditions.visibilityOfElementLocated(successBox));
53-
return success.isDisplayed();
51+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
52+
try {
53+
WebElement success = wait.until(
54+
ExpectedConditions.visibilityOfElementLocated(successBox));
55+
return success.isDisplayed();
56+
} catch (TimeoutException e) {
57+
return false;
58+
}
5459
}
5560

5661
}

selenium-webdriver-junit5-seljup/src/test/java/io/github/bonigarcia/webdriver/seljup/ch07/page_objects/FactoryLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.Duration;
2020

21+
import org.openqa.selenium.TimeoutException;
2122
import org.openqa.selenium.WebElement;
2223
import org.openqa.selenium.support.CacheLookup;
2324
import org.openqa.selenium.support.FindBy;
@@ -61,10 +62,14 @@ public void with(String username, String password) {
6162
}
6263

6364
public boolean successBoxPresent() {
64-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
65-
WebElement success = wait
66-
.until(ExpectedConditions.visibilityOf(successBox));
67-
return success.isDisplayed();
65+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
66+
try {
67+
WebElement success = wait
68+
.until(ExpectedConditions.visibilityOf(successBox));
69+
return success.isDisplayed();
70+
} catch (TimeoutException e) {
71+
return false;
72+
}
6873
}
6974

7075
}

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch07/page_objects/BasicLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void with(String username, String password) {
4747
}
4848

4949
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
50+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
5151
WebElement success = wait.until(
5252
ExpectedConditions.visibilityOfElementLocated(successBox));
5353
return success.isDisplayed();

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch07/page_objects/ExtendedLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020

2121
import org.openqa.selenium.By;
22+
import org.openqa.selenium.TimeoutException;
2223
import org.openqa.selenium.WebElement;
2324
import org.openqa.selenium.support.ui.ExpectedConditions;
2425
import org.openqa.selenium.support.ui.WebDriverWait;
@@ -47,10 +48,14 @@ public void with(String username, String password) {
4748
}
4849

4950
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
51-
WebElement success = wait.until(
52-
ExpectedConditions.visibilityOfElementLocated(successBox));
53-
return success.isDisplayed();
51+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
52+
try {
53+
WebElement success = wait.until(
54+
ExpectedConditions.visibilityOfElementLocated(successBox));
55+
return success.isDisplayed();
56+
} catch (TimeoutException e) {
57+
return false;
58+
}
5459
}
5560

5661
}

selenium-webdriver-junit5/src/test/java/io/github/bonigarcia/webdriver/jupiter/ch07/page_objects/FactoryLoginPage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.Duration;
2020

21+
import org.openqa.selenium.TimeoutException;
2122
import org.openqa.selenium.WebElement;
2223
import org.openqa.selenium.support.CacheLookup;
2324
import org.openqa.selenium.support.FindBy;
@@ -61,10 +62,14 @@ public void with(String username, String password) {
6162
}
6263

6364
public boolean successBoxPresent() {
64-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
65-
WebElement success = wait
66-
.until(ExpectedConditions.visibilityOf(successBox));
67-
return success.isDisplayed();
65+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
66+
try {
67+
WebElement success = wait
68+
.until(ExpectedConditions.visibilityOf(successBox));
69+
return success.isDisplayed();
70+
} catch (TimeoutException e) {
71+
return false;
72+
}
6873
}
6974

7075
}

selenium-webdriver-testng/src/test/java/io/github/bonigarcia/webdriver/testng/ch07/page_objects/BasicLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void with(String username, String password) {
4747
}
4848

4949
public boolean successBoxPresent() {
50-
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
50+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
5151
WebElement success = wait.until(
5252
ExpectedConditions.visibilityOfElementLocated(successBox));
5353
return success.isDisplayed();

0 commit comments

Comments
 (0)