Skip to content

Commit

Permalink
#2291 - Reworked actionWaitTimeout per comment in #2291
Browse files Browse the repository at this point in the history
  • Loading branch information
f-delahaye committed Dec 15, 2023
1 parent 2734543 commit e537429
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public class PlaywrightDriver implements Driver {
// Revert back to options.timeout
private static final Integer DEFAULT_TIMEOUT = null;

// Per doc, unless retry(int, int) is explicitely called, actions by default will not be retried and should fail immediately if the element is not available.
// Not sure how to tell PW "ignore timeout and fail immediately". 0 does not do that, so using an arbitrary very small timeout.
private static final int DEFAULT_ACTION_WAIT_TIMEOUT = 100;

private static final String FRIENDLY_ENGINE = "{\n"
+ " queryAll(root,args) {\n"
+ " function retain_right(rootRect, itemRect) {\n"
Expand Down Expand Up @@ -685,14 +681,10 @@ public Driver timeout() {
/**
* Timeout to be used for actions.
*
* By default, actions don't retry and don't wait. Note that global retry settings do NOT apply either for actions.
* Only explicit calls to retry() will set a timeout.
*
* Implementation note: I could not find how to tell PW don't wait (0 means never times out) so I'm using an arbitrary small timeout value.
*
* See https://github.com/karatelabs/karate/issues/2291 for a discussion on its implementation.
*/
int actionWaitTimeout() {
return options.isRetryEnabled() ? waitTimeout() : DEFAULT_ACTION_WAIT_TIMEOUT;
return options.isRetryEnabled() ? waitTimeout() : options.getRetryInterval();
}

int waitTimeout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public static void beforeAll() {
ScenarioEngine.set(scenarioEngine);
}

// Per doc and other driver implementations, global retry settings are not taken into account for actions, only explicit retry(count, interval) settings are.
// Per doc and other driver implementations, global retry count is not taken into account for actions, but retry interval is (and defines the wait timeout in PW).
@Test
void actionWithGlobalRetry() {

// global retry/
driver.setUrl("file://"+System.getProperty("user.dir")+"/src/test/resources/html/02.html");

TimeoutError te = assertThrows(TimeoutError.class, () -> driver.click("#slowDiv"));
assertTrue(te.getMessage().contains("Timeout 100ms exceeded"), te.getMessage());
assertTrue(te.getMessage().contains("Timeout "+RETRY_INTERVAL+"ms exceeded"), te.getMessage());
}


Expand Down

0 comments on commit e537429

Please sign in to comment.