Merge pull request #1520 from jlipps/master

allow alternative type of clear through fastClear: false cap
This commit is contained in:
bootstraponline
2013-11-21 13:35:29 -08:00
5 changed files with 66 additions and 4 deletions

View File

@@ -564,6 +564,7 @@ Appium.prototype.initDevice = function() {
, appDeviceReadyTimeout: this.args.androidDeviceReadyTimeout
, reset: !this.args.noReset
, fastReset: this.fastReset
, fastClear: this.desiredCapabilities.fastClear
, useKeystore: this.args.useKeystore
, keystorePath: this.args.keystorePath
, keystorePassword: this.args.keystorePassword

View File

@@ -80,6 +80,54 @@ androidCommon.prepareActiveDevice = function(cb) {
}.bind(this));
};
androidCommon.resetApp = function(cb) {
if (this.fastClear) {
logger.info("Running fastClear");
this.adb.stopAndClear(this.appPackage, cb);
} else {
logger.info("Running old fashion clear (reinstall)");
this.remoteApkExists(function(err, remoteApk) {
if (err) return cb(err);
if (!remoteApk) {
return cb(new Error("Can't run clear if remote apk doesn't exist"));
}
this.adb.forceStop(this.appPackage, function(err) {
if (err) return cb(err);
this.adb.uninstallApk(this.appPackage, function(err) {
if (err) return cb(err);
this.adb.installRemote(remoteApk, cb);
}.bind(this));
}.bind(this));
}.bind(this));
}
};
androidCommon.getRemoteApk = function(cb) {
var next = function() {
cb(null, this.remoteTempPath() + this.appMd5Hash + '.apk', this.appMd5Hash);
}.bind(this);
if (this.appMd5Hash) {
next();
} else {
this.getAppMd5(function(err, md5Hash) {
if (err) return cb(err);
this.appMd5Hash = md5Hash;
next();
}.bind(this));
}
};
androidCommon.remoteApkExists = function(cb) {
this.getRemoteApk(function(err, remoteApk) {
if (err) return cb(err);
this.adb.shell("ls " + remoteApk, function(err, stdout) {
if (err) return cb(err);
cb(null, stdout.trim());
});
}.bind(this));
};
androidCommon.installApp = function(cb) {
if (this.apkPath === null) {
logger.info("Skipping install since we launched with a package instead " +
@@ -89,14 +137,13 @@ androidCommon.installApp = function(cb) {
this.adb.isAppInstalled(this.appPackage, function(err, installed) {
if (installed && this.opts.fastReset) {
this.adb.stopAndClear(this.appPackage, cb);
this.resetApp(cb);
} else if (!installed) {
this.adb.checkAndSignApk(this.apkPath, this.appPackage, function(err) {
if (err) return cb(err);
this.adb.mkdir(this.remoteTempPath(), function(err) {
if (err) return cb(err);
this.getAppMd5(function(err, md5Hash) {
var remoteApk = this.remoteTempPath() + md5Hash + '.apk';
this.getRemoteApk(function(err, remoteApk, md5Hash) {
if (err) return cb(err);
this.removeTempApks([md5Hash], function(err, appExists) {
if (err) return cb(err);

View File

@@ -610,7 +610,7 @@ androidController.deleteCookies = function(cb) {
androidController.fastReset = function(cb) {
async.series([
function(cb) { this.adb.stopAndClear(this.appPackage, cb); }.bind(this),
this.resetApp.bind(this),
this.waitForActivityToStop.bind(this),
this.startApp.bind(this)
], cb);

View File

@@ -25,6 +25,7 @@ var Android = function(opts) {
Android.prototype.initialize = function(opts) {
this.compressXml = opts.compressXml;
this.skipUninstall = opts.fastReset || !opts.reset;
this.fastClear = opts.fastClear !== false;
this.rest = opts.rest;
this.webSocket = opts.webSocket;
opts.systemPort = opts.systemPort || 4724;
@@ -34,6 +35,7 @@ Android.prototype.initialize = function(opts) {
this.udid = opts.udid;
this.appPackage = opts.appPackage;
this.appActivity = opts.appActivity;
this.appMd5Hash = null;
this.appWaitActivity = opts.appWaitActivity || opts.appActivity;
this.avdName = opts.avdName || null;
this.appDeviceReadyTimeout = opts.appDeviceReadyTimeout;

View File

@@ -115,6 +115,18 @@ describeWd('basic', function(h) {
});
});
describeWd('without fastClear', function(h) {
it('should still be able to reset', function(done) {
h.driver.execute('mobile: reset', function(err) {
should.not.exist(err);
h.driver.getWindowSize(function(err) {
should.not.exist(err);
done();
});
});
});
}, null, null, null, {fastClear: false});
describeWd2('activity style: no period', function(h) {
it('should should still find activity', function(done) {
done();