2
2
3
3
import aquality .selenium .core .configurations .ITimeoutConfiguration ;
4
4
import aquality .selenium .core .localization .ILocalizationManager ;
5
+ import aquality .selenium .core .utilities .ElementActionRetrier ;
5
6
import io .appium .java_client .AppiumDriver ;
6
7
import io .appium .java_client .android .AndroidDriver ;
7
8
import io .appium .java_client .android .AndroidElement ;
8
9
import io .appium .java_client .ios .IOSDriver ;
9
10
import io .appium .java_client .ios .IOSElement ;
10
11
import org .openqa .selenium .Capabilities ;
12
+ import org .openqa .selenium .SessionNotCreatedException ;
11
13
import org .openqa .selenium .remote .http .HttpClient ;
12
14
import org .openqa .selenium .remote .http .HttpClient .Builder ;
13
15
import org .openqa .selenium .remote .http .HttpClient .Factory ;
14
16
15
17
import java .net .URL ;
16
18
import java .time .Duration ;
19
+ import java .util .Collections ;
20
+ import java .util .List ;
17
21
18
- abstract class ApplicationFactory implements IApplicationFactory {
22
+ public abstract class ApplicationFactory implements IApplicationFactory {
19
23
20
- private IllegalArgumentException getLoggedWrongPlatformNameException (String actualPlatform ) {
24
+ protected IllegalArgumentException getLoggedWrongPlatformNameException (String actualPlatform ) {
21
25
String message = AqualityServices .get (ILocalizationManager .class )
22
26
.getLocalizedMessage ("loc.platform.name.wrong" , actualPlatform );
23
27
IllegalArgumentException exception = new IllegalArgumentException (message );
24
28
AqualityServices .getLogger ().fatal (message , exception );
25
29
return exception ;
26
30
}
27
31
28
- AppiumDriver getDriver (URL serviceUrl ) {
32
+ protected AppiumDriver getDriver (URL serviceUrl ) {
29
33
PlatformName platformName = AqualityServices .getApplicationProfile ().getPlatformName ();
30
34
Capabilities capabilities = AqualityServices .getApplicationProfile ().getDriverSettings ().getCapabilities ();
31
35
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 ) {
32
42
AppiumDriver driver ;
33
43
switch (platformName ) {
34
44
case ANDROID :
@@ -43,7 +53,21 @@ AppiumDriver getDriver(URL serviceUrl) {
43
53
return driver ;
44
54
}
45
55
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 {
47
71
48
72
private final Factory defaultClientFactory = Factory .createDefault ();
49
73
private final Duration timeoutCommand = AqualityServices .get (ITimeoutConfiguration .class ).getCommand ();
@@ -64,7 +88,7 @@ public void cleanupIdleClients() {
64
88
}
65
89
}
66
90
67
- void logApplicationIsReady () {
91
+ protected void logApplicationIsReady () {
68
92
AqualityServices .getLocalizedLogger ().info ("loc.application.ready" , AqualityServices .getApplicationProfile ().getPlatformName ());
69
93
}
70
94
}
0 commit comments