Appium Android Full Reset Fails

I’m trying to perform a full reset of the app during the test run and continuously hitting on the Appium reset error - it seems like the driver was trying to perform uninstall twice. Since the app was already uninstalled the second uninstall command would fail - I was getting the error
Unhandled error: TypeError: Cannot read property 'waitForNotActivity' of null

Log:

info: → POST /wd/hub/session/260f849f-7726-4a0c-80b5-ff6da1b43737/appium/app/reset {}
info: [debug] Resetting app mid-session
info: [debug] Running device specific reset
info: [debug] Running old fashion reset (reinstall)
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell “ls /data/local/tmp/041589ebaf2e1275ca1c9a3101507317.apk”
info: [debug] Uninstalling ca.capitalone.enterprisemobilebanking.auto
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell “am force-stop ca.capitalone.enterprisemobilebanking.auto”
2015-12-30 15:33:36.597 Verbose logging enabled
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall ca.capitalone.enterprisemobilebanking.auto
2015-12-30 15:33:37.296:INFO::Logging to STDERR via wiremock.org.mortbay.log.StdErrLog
2015-12-30 15:33:37.299 Verbose logging enabled
info: [debug] App was uninstalled
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-> 5554 shell “pm install -r /data/local/tmp/041589ebaf2e1275ca1c9a3101507317.apk”
info: [debug] Didn’t get a new command in 60 secs, shutting down…
info: Shutting down appium session
info: [debug] Removing app from device
info: [debug] Uninstalling ca.capitalone.enterprisemobilebanking.auto
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell “am force-stop ca.capitalone.enterprisemobilebanking.auto”
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall ca.capitalone.enterprisemobilebanking.auto
error: Error: Command failed: /bin/sh -c /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall ca.capitalone.enterprisemobilebanking.auto

at ChildProcess.exithandler (child_process.js:203:12)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

warn: Error: Command failed: /bin/sh -c /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 uninstall ca.capitalone.enterprisemobilebanking.auto

at ChildProcess.exithandler (child_process.js:203:12)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

info: [debug] Pressing the HOME button
info: [debug] executing cmd: /Users/gmo162/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell “input keyevent 3”
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“shutdown”}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:“OK, shutting down”}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 519.45
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in
error: Unhandled error: TypeError: Cannot read property ‘waitForNotActivity’ of null
at [object Object].Android.waitForActivityToStop (/usr/local/lib/node_modules/appium/lib/devices/android/android.js:566:11)
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:607:21
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:246:17
at iterate (/usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:146:13)
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:157:25
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:248:21
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:612:34
at /usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:1360:5
at [object Object]. (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:180:9)
at ChildProcess.exithandler (child_process.js:194:7)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) context: [POST /wd/hub/session/260f849f-7726-4a0c-80b5-ff6da1b43737/appium/app/reset {}]

@vkyt : You have called driver.resetApp() and also full-reset , So app will be uninstalled two times.
After resetApp(), app is first unintsalled and again reinstalled but in your case app was unable to reinstall so full-reset tried to uninstall the app after completion of execution, thats why its throwing an error as uninstalling the app which was not at all installed.

To avoid/solve this issue workaround i would like to suggest is either do not use resetApp() or use --no-reset flag instead of full-reset.

Thanks for your kind reply! But the test case needs to have the app as a fresh install to validate a few screens that would only be valid for a fresh-install. This is part of a regression test suite and I don’t want to rely on this test case being the first one executed - that’s why I’m specifically calling driver reset.

In my Server Capability, I’m using fullReset=true and in the test case I’m calling driver.reset. Are you saying that this is the reason why I’m getting the uninstall-reinstall twice? Would it work if I call driver.reset but change full reset to false?

@vkyt Yeah ! Do not use fullReset=true, set --no-reset flag.

As your driver.resetApp is failing to reinstall the app sometimes, check the validation isApp installed or not, if not use driver.installApp() function.