From 853acb3d9848361a86b9d3246fada138f07434ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgars=20Egl=C4=ABtis?= <37242620+eglitise@users.noreply.github.com> Date: Tue, 4 Apr 2023 23:43:11 +0300 Subject: [PATCH] feat: add shouldTerminateApp capability (#591) --- README.md | 5 +++-- lib/desired-caps.js | 3 +++ lib/driver.js | 5 ++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ca4b72f9..6312b8133 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ appium:intentCategory | Set an optional intent category to be applied when start appium:intentAction | Set an optional intent action to be applied when starting the given appActivity by [Activity Manager](https://developer.android.com/studio/command-line/adb#am). Dfaults to `android.intent.action.MAIN`. Please use [mobile:startActivity](#mobile-startactivity) in case you don't set an explicit value. appium:intentFlags | Set an optional intent flags to be applied when starting the given appActivity by [Activity Manager](https://developer.android.com/studio/command-line/adb#am). Defaults to `0x10200000` (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flags). Please use [mobile:startActivity](#mobile-startactivity) in case you don't set an explicit value. appium:optionalIntentArguments | Set an optional intent arguments to be applied when starting the given appActivity by [Activity Manager](https://developer.android.com/studio/command-line/adb#am) -appium:dontStopAppOnReset | Set it to `true` if you don't want the application to be restarted if it was already running. If `appium:noReset` is falsy, then the app under test is going to be restarted if either this capability is falsy (the default behavior) or `appium:forceAppLaunch` is set to `true`. -appium:forceAppLaunch | Set it to `true` if you want the application under test to be always forcefully restarted on session startup even if `appium:noReset` is `true`, and the app was already running. If `noReset` is falsy, then the app under test is going to be restarted if either this capability set to `true` or `appium:dontStopAppOnReset` is falsy (the default behavior). Available since driver version 2.12 +appium:dontStopAppOnReset | Set it to `true` if you don't want the application to be restarted if it was already running. If `appium:noReset` is falsy, then the app under test is going to be restarted if either this capability is falsy (the default behavior) or `appium:forceAppLaunch` is set to `true`. `false` by default +appium:forceAppLaunch | Set it to `true` if you want the application under test to be always forcefully restarted on session startup even if `appium:noReset` is `true`, and the app was already running. If `noReset` is falsy, then the app under test is going to be restarted if either this capability set to `true` or `appium:dontStopAppOnReset` is falsy (the default behavior). `false` by default. Available since driver version 2.12 +appium:shouldTerminateApp | Set it to `true` if you want the application under test to be always terminated on session end even if `appium:noReset` is `true`. If `noReset` is falsy, then the app under test is going to be terminated if `appium:dontStopAppOnReset` is also falsy (the default behavior). `false` by default appium:autoLaunch | Whether to launch the application under test automatically (`true`, the default value) after a test starts appium:autoGrantPermissions | Whether to grant all the requested application permissions automatically when a test starts(`true`). The targetSdkVersion in the application manifest must be greater or equal to 23 and the Android version on the device under test must be greater or equal to Android 6 (API level 23) to grant permissions. Applications whose targetSdkVersion is lower than or equal to 22 must be reinstalled to grant permissions, for example, by setting the `appium:fullReset` capability as `true` for Android 6+ devices. If your app needs some special security permissions, like access to notifications or media recording, consider using [mobile: changePermissions](#mobile-changepermissions) extension with `appops` target. `false` by default appium:otherApps | Allows to set one or more comma-separated paths to Android packages that are going to be installed along with the main application under test. This might be useful if the tested app has dependencies diff --git a/lib/desired-caps.js b/lib/desired-caps.js index 65d451a0f..c46083eea 100644 --- a/lib/desired-caps.js +++ b/lib/desired-caps.js @@ -55,6 +55,9 @@ let uiautomatorCapConstraints = { }, forceAppLaunch: { isBoolean: true + }, + shouldTerminateApp: { + isBoolean: true } }; diff --git a/lib/driver.js b/lib/driver.js index e3ee6022d..527c23760 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -658,9 +658,8 @@ class AndroidUiautomator2Driver extends BaseDriver { } } if (this.opts.appPackage) { - if (!this.isChromeSession - && !this.opts.dontStopAppOnReset - && !this.opts.noReset) { + if (!this.isChromeSession && ((!this.opts.dontStopAppOnReset && !this.opts.noReset) + || (this.opts.noReset && this.opts.shouldTerminateApp))) { try { await this.adb.forceStop(this.opts.appPackage); } catch (err) {