Skip to content

Commit f451a6a

Browse files
authored
feat(java): ✨ updated waitUntil method with timeout param (#962)
1 parent e38d3b3 commit f451a6a

File tree

8 files changed

+112
-67
lines changed

8 files changed

+112
-67
lines changed

core-java/src/main/java/io/github/boykaframework/actions/drivers/DriverActions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.openqa.selenium.WebDriver;
4949
import org.openqa.selenium.WebDriverException;
5050
import org.openqa.selenium.interactions.Actions;
51+
import org.openqa.selenium.support.ui.WebDriverWait;
5152

5253
/**
5354
* Device / Browser specific actions.
@@ -149,6 +150,17 @@ public <T> void waitUntil (final Function<WebDriver, T> condition) {
149150
});
150151
}
151152

153+
@Override
154+
public <T> void waitUntil (final Function<WebDriver, T> condition, final Duration timeout) {
155+
LOGGER.traceEntry ();
156+
LOGGER.info ("Waiting for the expected condition for {} duration...", timeout);
157+
ofNullable (this.listener).ifPresent (l -> l.onWaitUntil (timeout));
158+
performDriverAction (driver -> {
159+
final var wait = new WebDriverWait (driver, timeout);
160+
wait.until (condition);
161+
});
162+
}
163+
152164
private <D extends WebDriver> void saveLogType (final D driver, final String logType, final String logPath) {
153165
final var logEntries = driver.manage ()
154166
.logs ()

core-java/src/main/java/io/github/boykaframework/actions/interfaces/drivers/IDriverActions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,13 @@ public interface IDriverActions {
5858
* @param <T> type of condition
5959
*/
6060
<T> void waitUntil (final Function<WebDriver, T> condition);
61+
62+
/**
63+
* Wait for a specific condition to be true.
64+
*
65+
* @param condition condition to wait for
66+
* @param timeout Wait duration for the condition
67+
* @param <T> type of condition
68+
*/
69+
<T> void waitUntil (final Function<WebDriver, T> condition, Duration timeout);
6170
}

core-java/src/main/java/io/github/boykaframework/actions/interfaces/listeners/drivers/IDriverActionsListener.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ default void onSaveLogs () {
5959
default void onWaitUntil () {
6060
// not implemented.
6161
}
62+
63+
/**
64+
* Handle wait until method.
65+
*/
66+
default void onWaitUntil (final Duration timeout) {
67+
// not implemented.
68+
}
6269
}

core-java/src/test/java/io/github/boykaframework/testng/ui/theinternet/WindowTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static io.github.boykaframework.testng.ui.theinternet.pages.HomePage.homePage;
2929
import static io.github.boykaframework.testng.ui.theinternet.pages.MultiWindowPage.multiWindowPage;
3030
import static java.text.MessageFormat.format;
31+
import static java.time.Duration.ofSeconds;
3132
import static org.openqa.selenium.WindowType.TAB;
3233
import static org.openqa.selenium.support.ui.ExpectedConditions.urlMatches;
3334

@@ -129,8 +130,8 @@ public void testOpenWindow () {
129130
.findFirst ();
130131
assertWithMessage ("Window").that (newWindow.isPresent ())
131132
.isTrue ();
132-
onWindow ().switchTo (newWindow.get ());
133-
withDriver ().waitUntil (urlMatches (format ("{0}windows/new", URL)));
133+
onWindow ().switchTo (newWindow.orElseThrow ());
134+
withDriver ().waitUntil (urlMatches (format ("{0}windows/new", URL)), ofSeconds (10));
134135
navigate ().verifyUrl ()
135136
.isEqualTo (format ("{0}windows/new", URL));
136137
onElement (multiWindowPage ().getTitle ()).verifyText ()

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"@stylistic/eslint-plugin-js": "^2.12.1",
3939
"@stylistic/eslint-plugin-ts": "^2.12.1",
4040
"@types/node": "^22.10.2",
41-
"@typescript-eslint/eslint-plugin": "^8.18.2",
42-
"@typescript-eslint/parser": "^8.18.2",
41+
"@typescript-eslint/eslint-plugin": "^8.19.0",
42+
"@typescript-eslint/parser": "^8.19.0",
4343
"commitlint": "^19.6.1",
4444
"eslint": "^9.17.0",
4545
"eslint-config-google": "^0.14.0",
@@ -63,7 +63,7 @@
6363
"release-it": "^17.11.0",
6464
"ts-node": "^10.9.2",
6565
"typescript": "^5.7.2",
66-
"typescript-eslint": "^8.18.2"
66+
"typescript-eslint": "^8.19.0"
6767
},
6868
"scripts": {
6969
"preinstall": "npx only-allow pnpm",

pnpm-lock.yaml

Lines changed: 62 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/docs/api/actions/drivers/driver-actions.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ import org.openqa.selenium.support.ui.ExpectedConditions;
5656
. . .
5757
withDriver ().waitUntil (ExpectedConditions.urlMatches (URL));
5858
```
59+
60+
### `waitUntil(condition, timeout)` {#wait-until-with-timeout}
61+
62+
This method will wait for any given condition to be true. It takes in Selenium WebDrivers `ExpectedCondition<Boolean>` object as parameter.
63+
64+
```java
65+
import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
66+
import org.openqa.selenium.support.ui.ExpectedConditions;
67+
import java.time.Duration;
68+
. . .
69+
withDriver ().waitUntil (ExpectedConditions.urlMatches (URL), Duration.ofSeconds(10));
70+
```

website/docs/api/actions/interfaces/listeners/drivers/driver-actions-listener.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ This method will get executed after saving all the driver logs.
2222
## `onWaitUntil` {#on-wait-until}
2323

2424
This method will get executed after waiting until a particular condition.
25+
26+
## `onWaitUntil(timeout)` {#on-wait-until-timeout}
27+
28+
This method will get executed after waiting until a particular condition for provided timeout.

0 commit comments

Comments
 (0)