Skip to content

Renamed restartApp to reinstallApp and fixed RESTART_ON_FAIL logic #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import solutions.bellatrix.core.configuration.ConfigurationService;
import solutions.bellatrix.core.plugins.Plugin;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;
import solutions.bellatrix.core.utilities.DebugInformation;
import solutions.bellatrix.core.utilities.PathNormalizer;
import solutions.bellatrix.web.configuration.WebSettings;
Expand Down Expand Up @@ -45,8 +46,8 @@ public class AppLifecyclePlugin extends Plugin {
public void preBeforeClass(Class type) {
if (ConfigurationService.get(WebSettings.class).getExecutionType() == "regular") {
CURRENT_APP_CONFIGURATION.set(getExecutionAppClassLevel(type));
if (shouldRestartApp()) {
restartApp();
if (shouldReinstallApp()) {
reinstallApp();
// TODO: maybe we can simplify and remove this parameter.
IS_APP_STARTED_DURING_PRE_BEFORE_CLASS.set(true);
} else {
Expand All @@ -72,33 +73,42 @@ public void preBeforeTest(TestResult testResult, Method memberInfo) {
CURRENT_APP_CONFIGURATION.get().setTestName(testFullName);

if (!IS_APP_STARTED_DURING_PRE_BEFORE_CLASS.get()) {
if (shouldRestartApp()) {
restartApp();
if (shouldReinstallApp()) {
reinstallApp();
}
}

IS_APP_STARTED_DURING_PRE_BEFORE_CLASS.set(false);
}

@Override
public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) {
public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.REUSE_IF_STARTED) {
return;
}

if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.RESTART_ON_FAIL && testResult != TestResult.FAILURE ) {
if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.RESTART_ON_FAIL && testResult == TestResult.SUCCESS ) {
DriverService.getWrappedAndroidDriver().terminateApp(CURRENT_APP_CONFIGURATION.get().getAppPackage());
DriverService.getWrappedAndroidDriver().activateApp(CURRENT_APP_CONFIGURATION.get().getAppPackage());
return;
}

shutdownApp();
}

@Override
public void beforeTestFailed(Exception ex) {
if (CURRENT_APP_CONFIGURATION.get().getLifecycle() == Lifecycle.RESTART_ON_FAIL) {
shutdownApp();
}
}

private void shutdownApp() {
DriverService.close();
PREVIOUS_APP_CONFIGURATION.set(null);
}

private void restartApp() {
private void reinstallApp() {
shutdownApp();
try {
DriverService.start(CURRENT_APP_CONFIGURATION.get());
Expand All @@ -111,7 +121,7 @@ private void restartApp() {
PREVIOUS_APP_CONFIGURATION.set(CURRENT_APP_CONFIGURATION.get());
}

private boolean shouldRestartApp() {
private boolean shouldReinstallApp() {
// TODO: IsAppStartedCorrectly getter?
var previousConfiguration = PREVIOUS_APP_CONFIGURATION.get();
var currentConfiguration = CURRENT_APP_CONFIGURATION.get();
Expand Down