17
17
import solutions .bellatrix .core .configuration .ConfigurationService ;
18
18
import solutions .bellatrix .core .plugins .Plugin ;
19
19
import solutions .bellatrix .core .plugins .TestResult ;
20
+ import solutions .bellatrix .core .plugins .TimeRecord ;
20
21
import solutions .bellatrix .core .utilities .DebugInformation ;
21
22
import solutions .bellatrix .core .utilities .PathNormalizer ;
22
23
import solutions .bellatrix .web .configuration .WebSettings ;
@@ -45,8 +46,8 @@ public class AppLifecyclePlugin extends Plugin {
45
46
public void preBeforeClass (Class type ) {
46
47
if (ConfigurationService .get (WebSettings .class ).getExecutionType () == "regular" ) {
47
48
CURRENT_APP_CONFIGURATION .set (getExecutionAppClassLevel (type ));
48
- if (shouldRestartApp ()) {
49
- restartApp ();
49
+ if (shouldReinstallApp ()) {
50
+ reinstallApp ();
50
51
// TODO: maybe we can simplify and remove this parameter.
51
52
IS_APP_STARTED_DURING_PRE_BEFORE_CLASS .set (true );
52
53
} else {
@@ -72,33 +73,42 @@ public void preBeforeTest(TestResult testResult, Method memberInfo) {
72
73
CURRENT_APP_CONFIGURATION .get ().setTestName (testFullName );
73
74
74
75
if (!IS_APP_STARTED_DURING_PRE_BEFORE_CLASS .get ()) {
75
- if (shouldRestartApp ()) {
76
- restartApp ();
76
+ if (shouldReinstallApp ()) {
77
+ reinstallApp ();
77
78
}
78
79
}
79
80
80
81
IS_APP_STARTED_DURING_PRE_BEFORE_CLASS .set (false );
81
82
}
82
83
83
84
@ Override
84
- public void postAfterTest (TestResult testResult , Method memberInfo , Throwable failedTestException ) {
85
+ public void postAfterTest (TestResult testResult , TimeRecord timeRecord , Method memberInfo , Throwable failedTestException ) {
85
86
if (CURRENT_APP_CONFIGURATION .get ().getLifecycle () == Lifecycle .REUSE_IF_STARTED ) {
86
87
return ;
87
88
}
88
89
89
- if (CURRENT_APP_CONFIGURATION .get ().getLifecycle () == Lifecycle .RESTART_ON_FAIL && testResult != TestResult .FAILURE ) {
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 ());
90
93
return ;
91
94
}
92
95
93
96
shutdownApp ();
94
97
}
95
98
99
+ @ Override
100
+ public void beforeTestFailed (Exception ex ) {
101
+ if (CURRENT_APP_CONFIGURATION .get ().getLifecycle () == Lifecycle .RESTART_ON_FAIL ) {
102
+ shutdownApp ();
103
+ }
104
+ }
105
+
96
106
private void shutdownApp () {
97
107
DriverService .close ();
98
108
PREVIOUS_APP_CONFIGURATION .set (null );
99
109
}
100
110
101
- private void restartApp () {
111
+ private void reinstallApp () {
102
112
shutdownApp ();
103
113
try {
104
114
DriverService .start (CURRENT_APP_CONFIGURATION .get ());
@@ -111,7 +121,7 @@ private void restartApp() {
111
121
PREVIOUS_APP_CONFIGURATION .set (CURRENT_APP_CONFIGURATION .get ());
112
122
}
113
123
114
- private boolean shouldRestartApp () {
124
+ private boolean shouldReinstallApp () {
115
125
// TODO: IsAppStartedCorrectly getter?
116
126
var previousConfiguration = PREVIOUS_APP_CONFIGURATION .get ();
117
127
var currentConfiguration = CURRENT_APP_CONFIGURATION .get ();
0 commit comments