Skip to content

Commit f5f9f1a

Browse files
Ivaylo996ivaylo.dimitrov
and
ivaylo.dimitrov
authored
Added SingletonFactory to Android app() Services and added self-healing for after test PASS app crash (#69)
* Added SingletonFactory to Android app() Services and added self-healing for after test PASS app crash * Removed unused bracket --------- Co-authored-by: ivaylo.dimitrov <[email protected]>
1 parent 8c47b72 commit f5f9f1a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/AppLifecyclePlugin.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import solutions.bellatrix.core.plugins.TimeRecord;
2121
import solutions.bellatrix.core.utilities.DebugInformation;
2222
import solutions.bellatrix.core.utilities.PathNormalizer;
23+
import solutions.bellatrix.core.utilities.SingletonFactory;
2324
import solutions.bellatrix.web.configuration.WebSettings;
2425

2526
import java.lang.reflect.Method;
@@ -87,9 +88,13 @@ public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method m
8788
return;
8889
}
8990

90-
if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.RESTART_ON_FAIL && testResult == TestResult.SUCCESS ) {
91-
DriverService.getWrappedAndroidDriver().terminateApp(CURRENT_APP_CONFIGURATION.get().getAppPackage());
92-
DriverService.getWrappedAndroidDriver().activateApp(CURRENT_APP_CONFIGURATION.get().getAppPackage());
91+
if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.RESTART_ON_FAIL && testResult == TestResult.SUCCESS) {
92+
try {
93+
DriverService.getWrappedAndroidDriver().executeScript("window.location");
94+
} catch (Exception ex) {
95+
shutdownApp();
96+
}
97+
9398
return;
9499
}
95100

@@ -105,6 +110,7 @@ public void beforeTestFailed(Exception ex) {
105110

106111
private void shutdownApp() {
107112
DriverService.close();
113+
SingletonFactory.clear();
108114
PREVIOUS_APP_CONFIGURATION.set(null);
109115
}
110116

bellatrix.android/src/main/java/solutions/bellatrix/android/services/App.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,41 @@
1515

1616
import solutions.bellatrix.android.infrastructure.DriverService;
1717
import solutions.bellatrix.core.infrastructure.BellatrixApp;
18+
import solutions.bellatrix.core.utilities.SingletonFactory;
1819

1920
public class App implements BellatrixApp {
2021
private boolean disposed = false;
2122

2223
public AppService appService() {
23-
return new AppService();
24+
return SingletonFactory.getInstance(AppService.class);
2425
}
2526

2627
public ComponentCreateService create() {
27-
return new ComponentCreateService();
28+
return SingletonFactory.getInstance(ComponentCreateService.class);
2829
}
2930

3031
public ComponentWaitService waitFor() {
31-
return new ComponentWaitService();
32+
return SingletonFactory.getInstance(ComponentWaitService.class);
3233
}
3334

3435
public DeviceService device() {
35-
return new DeviceService();
36+
return SingletonFactory.getInstance(DeviceService.class);
3637
}
3738

3839
public FileSystemService fileSystem() {
39-
return new FileSystemService();
40+
return SingletonFactory.getInstance(FileSystemService.class);
4041
}
4142

4243
public KeyboardService keyboard() {
43-
return new KeyboardService();
44+
return SingletonFactory.getInstance(KeyboardService.class);
4445
}
4546

4647
public TouchActionsService touch() {
47-
return new TouchActionsService();
48+
return SingletonFactory.getInstance(TouchActionsService.class);
4849
}
4950

5051
public WebServiceFacade web() {
51-
return new WebServiceFacade();
52+
return SingletonFactory.getInstance(WebServiceFacade.class);
5253
}
5354

5455
@Override

0 commit comments

Comments
 (0)