add packageAndLaunchActivity support for selendroid

also convert our tests to use this by default so that it's tested
also move it to after prepareDevice so we make sure to run adb commands
with the appropriate device id etc
fix #2083, cc @bootstraponline
This commit is contained in:
Jonathan Lipps
2014-03-17 15:15:48 -07:00
parent f14c5c9108
commit 482d24e0e1
6 changed files with 25 additions and 29 deletions

View File

@@ -555,6 +555,19 @@ androidCommon.unlockScreen = function (cb) {
}.bind(this));
};
androidCommon.packageAndLaunchActivityFromManifest = function (cb) {
if (!this.args.app) return cb(); // apk must be local.
if (this.args.appPackage && this.args.appActivity) return cb();
this.adb.packageAndLaunchActivityFromManifest(this.args.app, function (err, pkg, act) {
if (pkg && !this.args.appPackage) this.args.appPackage = pkg;
if (act && !this.args.appActivity) this.args.appActivity = act;
if (!this.args.appWaitPackage) this.args.appWaitPackage = this.args.appPackage;
if (!this.args.appWaitActivity) this.args.appWaitActivity = this.args.appActivity;
cb();
}.bind(this));
};
androidCommon.getLog = function (logType, cb) {
// Check if passed logType is supported
if (!_.has(logTypesSupported, logType)) {

View File

@@ -89,8 +89,8 @@ Android.prototype.start = function (cb, onDie) {
logger.debug("Using fast reset? " + this.args.fastReset);
async.series([
this.packageAndLaunchActivityFromManifest.bind(this),
this.prepareDevice.bind(this),
this.packageAndLaunchActivityFromManifest.bind(this),
this.checkApiLevel.bind(this),
this.pushStrings.bind(this),
this.processFromManifest.bind(this),
@@ -281,17 +281,6 @@ Android.prototype.processFromManifest = function (cb) {
}
};
Android.prototype.packageAndLaunchActivityFromManifest = function (cb) {
if (!this.args.app) return cb(); // apk must be local.
if (this.args.appPackage && this.args.appActivity) return cb();
this.adb.packageAndLaunchActivityFromManifest(this.args.app, function (err, pkg, act) {
if (pkg && !this.args.appPackage) this.args.appPackage = pkg;
if (act && !this.args.appActivity) this.args.appActivity = act;
cb();
}.bind(this));
};
Android.prototype.pushStrings = function (cb) {
var remotePath = '/data/local/tmp';
var stringsJson = 'strings.json';

View File

@@ -73,11 +73,12 @@ Selendroid.prototype.start = function (cb) {
this.adb = new ADB(this.args);
var modServerExists = false
, modAppPkg = this.args.appPackage + '.selendroid';
this.selendroidServerPath = path.resolve(getTempPath(),
'selendroid.' + this.args.appPackage + '.apk');
, modAppPkg = null;
var checkModServerExists = function (cb) {
this.selendroidServerPath = path.resolve(getTempPath(),
'selendroid.' + this.args.appPackage + '.apk');
modAppPkg = this.args.appPackage + '.selendroid';
fs.stat(this.selendroidServerPath, function (err) {
modServerExists = !err;
cb();
@@ -122,6 +123,7 @@ Selendroid.prototype.start = function (cb) {
async.series([
this.ensureServerExists.bind(this),
this.prepareDevice.bind(this),
this.packageAndLaunchActivityFromManifest.bind(this),
checkModServerExists,
conditionalUninstallSelendroid,
conditionalInsertManifest,

View File

@@ -11,4 +11,3 @@ Here's a list of things that aren't tested in this suite:
* setting locale
* --avd / avdName
* safari ipad
* auto-app/pkg detection on android

View File

@@ -4,7 +4,5 @@ var getAppPath = require('../../../helpers/app').getAppPath;
module.exports = {
app: getAppPath('ApiDemos', 'android'),
device: 'Android',
'app-package': 'com.example.android.apis',
'app-activity': '.ApiDemos'
device: 'Android'
};

View File

@@ -8,9 +8,7 @@ var setup = require("../common/setup-base")
, _ = require('underscore');
var desired = {
app: path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk"),
'app-package': 'com.example.android.apis',
'app-activity': '.ApiDemos'
app: path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk")
};
// , appAct2 = "ApiDemos"
@@ -21,8 +19,7 @@ describe('selendroid - basic -', function () {
describe('api', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
// todo: issue with find
it('should find and click an element @skip-selendroid-all', function (done) {
it('should find and click an element', function (done) {
// selendroid appears to have some issues with implicit waits
// hence the timeouts
driver
@@ -76,7 +73,7 @@ describe('selendroid - basic -', function () {
it('should be able to uninstall the app', function (done) {
driver
.execute("mobile: removeApp", [{bundleId: desired['app-package']}])
.execute("mobile: removeApp", [{bundleId: "com.example.android.apis"}])
.nodeify(done);
});
});
@@ -100,8 +97,7 @@ describe('selendroid - basic -', function () {
});
});
// TODO: way too flaky
describe('command timeouts @skip-selendroid-all', function () {
describe('command timeouts', function () {
var driver;
setup(this, _.defaults({newCommandTimeout: 3}, desired))
.then(function (d) { driver = d; });
@@ -115,8 +111,7 @@ describe('selendroid - basic -', function () {
});
});
// TODO: issue with find
describe('command timeouts @skip-selendroid-all', function () {
describe('command timeouts', function () {
var driver;
setup(this, _.defaults({newCommandTimeout: 7}, desired))
.then(function (d) { driver = d; });