Skip to content

Commit

Permalink
Added configurable delay and retry counts for driver instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Apr 18, 2024
1 parent 041d96f commit 01a717d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Splitter;
import io.appium.java_client.AppiumDriver;
import net.serenitybdd.core.Serenity;
import net.serenitybdd.core.SystemTimeouts;
import net.serenitybdd.core.di.SerenityInfrastructure;
import net.serenitybdd.model.environment.EnvironmentSpecificConfiguration;
Expand Down Expand Up @@ -168,7 +169,7 @@ private WebDriver createWebDriver(Class<? extends WebDriver> driverClass, String
private WebDriver waitThenRetry(Class<? extends WebDriver> driverClass,
String options,
EnvironmentVariables environmentVariables) {
int maxRetryCount = WEBDRIVER_CREATION_RETRY_MAX_TIME.integerFrom(environmentVariables, 30);
int maxRetryCount = WEBDRIVER_CREATION_RETRY_COUNT.integerFrom(environmentVariables, 6);
return waitThenRetry(maxRetryCount, driverClass, options, environmentVariables, null);
}

Expand All @@ -178,14 +179,15 @@ private WebDriver waitThenRetry(int remainingTries,
EnvironmentVariables environmentVariables,
Exception cause) {
LOGGER.debug("Remaining tries: " + remainingTries);
int retryDelay = WEBDRIVER_CREATION_RETRY_DELAY.integerFrom(environmentVariables, 5);

if (remainingTries == 0) {
throw new DriverConfigurationError(
"After several attempts, could not instantiate new WebDriver instance of type " + driverClass +
" (" + cause.getMessage() + "). See below for more details.", cause);
}

PauseTestExecution.forADelayOf(30).seconds();
PauseTestExecution.forADelayOf(retryDelay).seconds();

try {
return createWebDriver(driverClass, options, environmentVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,18 @@ public enum ThucydidesSystemProperty {
*/
WEBDRIVER_CREATION_RETRY_CAUSES,

WEBDRIVER_CREATION_RETRY_MAX_TIME,
/**
* If we can't create the webdriver for some reason (for example, all parallel tests are in use),
* we wait for a short delay and try again a number of times.
* This is the time we wait between retries. The default is 5 seconds.
*/
WEBDRIVER_CREATION_RETRY_DELAY,
/**
* If we can't create the webdriver for some reason (for example, all parallel tests are in use),
* we wait for a short delay and try again a number of times. This is the maximum number of times we try to create the webdriver.
* The default is 6.
*/
WEBDRIVER_CREATION_RETRY_COUNT,

/**
* If set to true, the name of the actor will appear in "should" statements for Screenplay tests.
Expand Down

0 comments on commit 01a717d

Please sign in to comment.