Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clear app if it already exists

Fix #280
  • Loading branch information...
commit f74334991c1e7a063cb6b92c3fdf3dba1f9f6990 1 parent 6cdfd14
bootstraponline bootstraponline authored
Showing with 29 additions and 19 deletions.
  1. +1 −19 app/android.js
  2. +28 −0 uiautomator/adb.js
20 app/android.js
View
@@ -44,25 +44,7 @@ var Android = function(opts) {
// Clear data, close app, then start app.
Android.prototype.fastReset = function(cb) {
- // list instruments with: adb shell pm list instrumentation
- // targetPackage + '.clean' / clean.apk.Clear
- var me = this;
- var clearCmd = me.adb.adbCmd + ' shell am instrument ' + me.appPackage + '.clean/clean.apk.Clean';
- logger.debug("Clear command: " + clearCmd);
- exec(clearCmd, {}, function(err, stdout, stderr) {
- if (err) {
- logger.warn(stderr);
- cb(err);
- } else {
- me.adb.startApp(function(err) {
- if (err) {
- cb(err);
- } else {
- cb(null);
- }
- });
- }
- });
+ this.adb.runFastReset(function(err) { if (err) return cb(err); return cb(null); });
};
Android.prototype.start = function(cb, onDie) {
28 uiautomator/adb.js
View
@@ -669,6 +669,28 @@ ADB.prototype.uninstallApp = function(cb) {
}
};
+ADB.prototype.runFastReset = function(cb) {
+ // list instruments with: adb shell pm list instrumentation
+ // targetPackage + '.clean' / clean.apk.Clear
+ var me = this;
+ var clearCmd = me.adbCmd + ' shell am instrument ' + me.appPackage + '.clean/clean.apk.Clean';
+ logger.debug("Clear command: " + clearCmd);
+ exec(clearCmd, {}, function(err, stdout, stderr) {
+ if (err) {
+ logger.warn(stderr);
+ cb(err);
+ } else {
+ me.startApp(function(err) {
+ if (err) {
+ cb(err);
+ } else {
+ cb(null);
+ }
+ });
+ }
+ });
+};
+
ADB.prototype.installApp = function(cb) {
var me = this;
var next = function() {
@@ -697,6 +719,12 @@ ADB.prototype.installApp = function(cb) {
} else { cb(null); }
},
function(cb) {
+ // App is already installed so reset it.
+ if (!installApp) {
+ me.runFastReset(function(err) { if (err) return cb(err); return cb(null); });
+ }
+ },
+ function(cb) {
if (installClean) {
me.debug("Installing clean apk");
me.installApk(me.cleanAPK, function(err) { if (err) return cb(err); return cb(null); });
Please sign in to comment.
Something went wrong with that request. Please try again.