Skip to content

Commit f915e8a

Browse files
committed
add retry for driver creation to application factory
1 parent 6d138f8 commit f915e8a

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/main/java/aquality/appium/mobile/application/ApplicationFactory.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,43 @@
22

33
import aquality.selenium.core.configurations.ITimeoutConfiguration;
44
import aquality.selenium.core.localization.ILocalizationManager;
5+
import aquality.selenium.core.utilities.ElementActionRetrier;
56
import io.appium.java_client.AppiumDriver;
67
import io.appium.java_client.android.AndroidDriver;
78
import io.appium.java_client.android.AndroidElement;
89
import io.appium.java_client.ios.IOSDriver;
910
import io.appium.java_client.ios.IOSElement;
1011
import org.openqa.selenium.Capabilities;
12+
import org.openqa.selenium.SessionNotCreatedException;
1113
import org.openqa.selenium.remote.http.HttpClient;
1214
import org.openqa.selenium.remote.http.HttpClient.Builder;
1315
import org.openqa.selenium.remote.http.HttpClient.Factory;
1416

1517
import java.net.URL;
1618
import java.time.Duration;
19+
import java.util.Collections;
20+
import java.util.List;
1721

18-
abstract class ApplicationFactory implements IApplicationFactory {
22+
public abstract class ApplicationFactory implements IApplicationFactory {
1923

20-
private IllegalArgumentException getLoggedWrongPlatformNameException(String actualPlatform) {
24+
protected IllegalArgumentException getLoggedWrongPlatformNameException(String actualPlatform) {
2125
String message = AqualityServices.get(ILocalizationManager.class)
2226
.getLocalizedMessage("loc.platform.name.wrong", actualPlatform);
2327
IllegalArgumentException exception = new IllegalArgumentException(message);
2428
AqualityServices.getLogger().fatal(message, exception);
2529
return exception;
2630
}
2731

28-
AppiumDriver getDriver(URL serviceUrl) {
32+
protected AppiumDriver getDriver(URL serviceUrl) {
2933
PlatformName platformName = AqualityServices.getApplicationProfile().getPlatformName();
3034
Capabilities capabilities = AqualityServices.getApplicationProfile().getDriverSettings().getCapabilities();
3135
Factory httpClientFactory = new ClientFactory();
36+
return new CustomActionRetrier(Collections.singletonList(SessionNotCreatedException.class))
37+
.doWithRetry(() -> createSession(platformName, serviceUrl, httpClientFactory, capabilities));
38+
}
39+
40+
protected AppiumDriver createSession(PlatformName platformName, URL serviceUrl, Factory httpClientFactory,
41+
Capabilities capabilities) {
3242
AppiumDriver driver;
3343
switch (platformName) {
3444
case ANDROID:
@@ -43,7 +53,21 @@ AppiumDriver getDriver(URL serviceUrl) {
4353
return driver;
4454
}
4555

46-
class ClientFactory implements Factory{
56+
protected class CustomActionRetrier extends ElementActionRetrier {
57+
private final List<Class<? extends Exception>> handledExceptions;
58+
59+
CustomActionRetrier(List<Class<? extends Exception>> handledExceptions) {
60+
super(AqualityServices.getConfiguration().getRetryConfiguration());
61+
this.handledExceptions = handledExceptions;
62+
}
63+
64+
@Override
65+
public List<Class<? extends Exception>> getHandledExceptions() {
66+
return handledExceptions;
67+
}
68+
}
69+
70+
protected class ClientFactory implements Factory {
4771

4872
private final Factory defaultClientFactory = Factory.createDefault();
4973
private final Duration timeoutCommand = AqualityServices.get(ITimeoutConfiguration.class).getCommand();
@@ -64,7 +88,7 @@ public void cleanupIdleClients() {
6488
}
6589
}
6690

67-
void logApplicationIsReady() {
91+
protected void logApplicationIsReady() {
6892
AqualityServices.getLocalizedLogger().info("loc.application.ready", AqualityServices.getApplicationProfile().getPlatformName());
6993
}
7094
}

src/main/java/aquality/appium/mobile/application/LocalApplicationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class LocalApplicationFactory extends ApplicationFactory {
99
@Override
1010
public Application getApplication() {
1111
AppiumServiceBuilder builder = new AppiumServiceBuilder()
12-
.withArgument(() -> "--allow-insecure", " chromedriver_autodownload");
12+
.withArgument(() -> "--allow-insecure", "chromedriver_autodownload");
1313
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(builder);
1414
service.start();
1515
AppiumDriver driver = getDriver(service.getUrl());

0 commit comments

Comments
 (0)