Merge pull request #2260 from sebv/relative-apppath

Relative apppath
This commit is contained in:
Jonathan Lipps
2014-04-04 11:46:30 -07:00
10 changed files with 147 additions and 88 deletions

View File

@@ -8,6 +8,7 @@ var logger = require('../../server/logger.js').get('appium')
, md5 = require('md5calculator')
, async = require('async')
, errors = require('../../server/errors.js')
, Device = require('../device.js')
, NotYetImplementedError = errors.NotYetImplementedError;
var logTypesSupported = {
@@ -43,20 +44,26 @@ androidCommon.configure = function (args, caps, cb) {
}
};
androidCommon.configureApp = function (args, caps, cb) {
this._deviceConfigureApp(args, caps, function (err) {
androidCommon.configureApp = function (cb) {
var _cb = cb;
cb = function (err) {
if (err) {
if (this.appIsPackageOrBundle(args.app)) {
// we have a package instead of app
this.args.androidPackage = args.app;
this.args.app = null;
logger.info("App is an Android package, will attempt to run on device");
return cb();
}
return cb(err);
err = new Error("Bad app: " + this.args.app + ". App paths need to be absolute, " +
" relative to the appium server install dir, URL to compressed file, " +
"or special app name. cause: " + err);
}
_cb(err);
};
if (this.appIsPackageOrBundle(this.args.app)) {
// we have a package instead of app
this.args.androidPackage = this.args.app;
this.args.app = null;
logger.info("App is an Android package, will attempt to run on device");
cb();
}.bind(this));
} else {
Device.prototype.configureApp.call(this, cb);
}
};
androidCommon.setAndroidArgs = function () {

View File

@@ -76,7 +76,6 @@ Android.prototype.init = function () {
};
Android.prototype._deviceConfigure = Device.prototype.configure;
Android.prototype._deviceConfigureApp = Device.prototype.configureApp;
Android.prototype.start = function (cb, onDie) {
this.launchCb = cb;

View File

@@ -60,7 +60,6 @@ Selendroid.prototype.init = function () {
_.extend(Selendroid.prototype, androidCommon);
Selendroid.prototype._deviceConfigure = Device.prototype.configure;
Selendroid.prototype._deviceConfigureApp = Device.prototype.configureApp;
Selendroid.prototype._setAndroidArgs = androidCommon.setAndroidArgs;
Selendroid.prototype.setAndroidArgs = function () {
this._setAndroidArgs();

View File

@@ -1,10 +1,10 @@
"use strict";
var fs = require('fs')
, path = require('path')
, _ = require('underscore')
, logger = require('../server/logger.js').get('appium')
, helpers = require('../helpers.js')
, isWindows = helpers.isWindows()
, copyLocalZip = helpers.copyLocalZip
, unzipApp = helpers.unzipApp
, downloadFile = helpers.downloadFile
@@ -46,17 +46,15 @@ Device.prototype.appString = function () {
};
Device.prototype.configureApp = function (cb) {
if (this.appIsLocal(this.args.app)) {
this.configureLocalApp(cb);
} else if (this.appIsDownloaded(this.args.app)) {
if (this.args.app.substring(0, 4).toLowerCase() === "http") {
this.configureDownloadedApp(cb);
} else {
cb(new Error("Bad app: " + this.args.app + ". Apps need to be absolute " +
"local path, URL to compressed file, or special app name"));
this.configureLocalApp(cb);
}
};
Device.prototype.configureLocalApp = function (cb) {
this.args.app = path.resolve(this.args.app);
var appPath = this.args.app;
var origin = this.capabilities.app ? "desired caps" : "command line";
var ext = appPath.substring(appPath.length - 4).toLowerCase();
@@ -84,19 +82,6 @@ Device.prototype.configureLocalApp = function (cb) {
}
};
Device.prototype.appIsLocal = function (app) {
return app[0] === "/" ||
(isWindows &&
app !== null &&
app.length > 2 &&
app[1] === ":" &&
app[2] === "\\");
};
Device.prototype.appIsDownloaded = function (app) {
return app.substring(0, 4).toLowerCase() === "http";
};
Device.prototype.appIsPackageOrBundle = function (app) {
return (/^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/).test(app);
};

View File

@@ -131,29 +131,33 @@ IOS.prototype.setIOSArgs = function () {
this.curOrientation = this.args.initialOrientation;
};
IOS.prototype._deviceConfigureApp = Device.prototype.configureApp;
IOS.prototype.configureApp = function (cb) {
this._deviceConfigureApp(function (err) {
var app = this.appString();
var _cb = cb;
cb = function (err) {
if (err) {
if (app.toLowerCase() === "iwebview") {
this.capabilities.iwebview = true;
this.args.app = path.resolve(__dirname,
"../../../build/WebViewApp/WebViewApp.app");
return this.configureLocalApp(cb);
} else if (app.toLowerCase() === "settings") {
return this.configurePreferences(cb);
} else if (this.appIsPackageOrBundle(app)) {
// we have a bundle ID
logger.info("App is an iOS bundle, will attempt to run as pre-existing");
this.args.bundleId = app;
this.args.app = null;
return cb();
}
return cb(err);
err = new Error("Bad app: " + this.args.app + ". App paths need to be absolute, " +
" relative to the appium server install dir, URL to compressed file, " +
" or special app name. cause: " + err);
}
_cb(err);
};
var app = this.appString();
if (app.toLowerCase() === "iwebview") {
this.capabilities.iwebview = true;
this.args.app = path.resolve(__dirname,
"../../../build/WebViewApp/WebViewApp.app");
Device.prototype.configureApp.call(this, cb);
} else if (app.toLowerCase() === "settings") {
this.configurePreferences(cb);
} else if (this.appIsPackageOrBundle(app)) {
// we have a bundle ID
logger.info("App is an iOS bundle, will attempt to run as pre-existing");
this.args.bundleId = app;
this.args.app = null;
cb();
}.bind(this));
} else {
Device.prototype.configureApp.call(this, cb);
}
};
IOS.prototype.configurePreferences = function (cb) {

View File

@@ -97,7 +97,7 @@ RemoteDebugger.prototype.disconnect = function () {
};
RemoteDebugger.prototype.setConnectionKey = function (cb) {
assert.ok(this.connId);
try { assert.ok(this.connId); } catch (err) { return cb(err); }
var setConnKey = messages.setConnectionKey(this.connId);
this.logger.info("Sending connection key");
this.send(setConnKey, function (simNameKey, simBuildKey) {
@@ -113,7 +113,7 @@ RemoteDebugger.prototype.setConnectionKey = function (cb) {
};
RemoteDebugger.prototype.selectApp = function (appIdKey, cb) {
assert.ok(this.connId);
try { assert.ok(this.connId); } catch (err) { return cb(err); }
this.appIdKey = appIdKey;
var connectToApp = messages.connectToApp(this.connId, this.appIdKey);
this.logger.info("Selecting app");
@@ -140,9 +140,12 @@ RemoteDebugger.prototype.selectPage = function (pageIdKey, cb, skipReadyCheck) {
if (typeof skipReadyCheck === "undefined") {
skipReadyCheck = false;
}
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
try {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
} catch (err) { return cb(err); }
this.pageIdKey = pageIdKey;
var setSenderKey = messages.setSenderKey(this.connId, this.appIdKey,
this.senderId, this.pageIdKey);
@@ -269,10 +272,12 @@ RemoteDebugger.prototype.execute = function (command, cb, override) {
}.bind(this));
} else {
if (this.debuggerType === this.debuggerTypeEnum.webinspector) {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
try {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
} catch (err) { return cb(err); }
}
this.logger.info("Sending javascript command");
var sendJSCommand = messages.sendJSCommand(command, this.appIdKey,
@@ -282,10 +287,13 @@ RemoteDebugger.prototype.execute = function (command, cb, override) {
};
RemoteDebugger.prototype.callFunction = function (objId, fn, args, cb) {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
try {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
} catch (err) { return cb(err); }
this.logger.info("Calling javascript function");
var callJSFunction = messages.callJSfunction(objId, fn, args, this.appIdKey,
this.connId, this.senderId, this.pageIdKey, this.debuggerType);
@@ -294,10 +302,12 @@ RemoteDebugger.prototype.callFunction = function (objId, fn, args, cb) {
RemoteDebugger.prototype.navToUrl = function (url, cb) {
if (this.debuggerType === this.debuggerTypeEnum.webinspector) {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
try {
assert.ok(this.connId);
assert.ok(this.appIdKey);
assert.ok(this.senderId);
assert.ok(this.pageIdKey);
} catch (err) { return cb(err); }
}
this.logger.info("Navigating to new URL: " + url);
var navToUrl = messages.setUrl(url, this.appIdKey, this.connId,

View File

@@ -1,6 +1,7 @@
"use strict";
var setup = require("../../common/setup-base")
var env = require('../../../helpers/env')
, setup = require("../../common/setup-base")
, desired = require("./desired")
, try3Times = require('../../../helpers/repeat').try3Times
, initSession = require('../../../helpers/session').initSession
@@ -9,7 +10,8 @@ var setup = require("../../common/setup-base")
, chai = require('chai')
, should = chai.should()
, spawn = require('child_process').spawn
, _ = require('underscore');
, _ = require('underscore')
, androidReset = require('../../../helpers/reset').androidReset;
describe("apidemo - basic -", function () {
@@ -235,12 +237,33 @@ describe("apidemo - basic -", function () {
describe('appium android', function () {
var session;
after(function () { session.tearDown(); });
if (env.FAST_TESTS) {
beforeEach(function (done) {
androidReset('com.example.android.apis', '.ApiDemos').nodeify(done);
});
}
afterEach(function () { session.tearDown(); });
it('should load an app with using absolute path', function (done) {
var appPath = path.resolve(desired.app);
session = initSession(_.defaults({'app': appPath}, desired));
session.setUp().nodeify(done);
});
it('should load an app with using relative path', function (done) {
var appPath = path.relative(process.cwd(), desired.app);
session = initSession(_.defaults({'app': appPath}, desired));
session.setUp().nodeify(done);
});
it('should load a zipped app via url', function (done) {
var appUrl = 'http://appium.s3.amazonaws.com/ApiDemos-debug.apk';
session = initSession(_.defaults({'app': appUrl}, desired));
session.setUp().nodeify(done);
});
});
});

View File

@@ -3,5 +3,6 @@
var getAppPath = require('../../../helpers/app').getAppPath;
module.exports = {
app: getAppPath('ApiDemos', 'android')
app: getAppPath('ApiDemos'),
device: 'Android'
};

View File

@@ -3,7 +3,8 @@
var env = require('../../../helpers/env')
, setup = require("../../common/setup-base")
, desired = require('./desired')
, path = require('path');
, path = require('path')
, _ = require('underscore');
describe('uicatalog - basic -', function () {
@@ -66,6 +67,45 @@ describe('uicatalog - basic -', function () {
});
});
describe('load app with relative path', function () {
var driver;
var appPath = path.relative(process.cwd(), desired.app);
setup(this, _.defaults({'app': appPath}, desired))
.then(function (d) { driver = d; });
it('should load with relative path', function (done) {
driver.elementByTagName('tableView')
.should.eventually.exist
.nodeify(done);
});
});
describe('load app with absolute path', function () {
var driver;
var appPath = path.resolve(process.cwd(), desired.app);
setup(this, _.defaults({'app': appPath}, desired))
.then(function (d) { driver = d; });
it('should load with relative path', function (done) {
driver.elementByTagName('tableView')
.should.eventually.exist
.nodeify(done);
});
});
describe('load zipped app with relative path', function () {
var driver;
var appZip = "assets/UICatalog6.0.app.zip";
setup(this, {app: appZip})
.then(function (d) { driver = d; });
it('should load a zipped app via path', function (done) {
driver.elementByTagName('tableView')
.should.eventually.exist
.nodeify(done);
});
});
describe('load zipped app via url', function () {
var driver;
var appUrl = 'http://appium.s3.amazonaws.com/UICatalog6.0.app.zip';

View File

@@ -1,24 +1,15 @@
"use strict";
var env = require('./env'),
path = require('path');
var env = require('./env');
module.exports.getAppPath = function (app, device) {
if (device && device[0] === "i") {
env.IOS = true;
env.ANDROID = false;
} else if (device && device.toLowerCase() === "android") {
env.ANDROID = true;
env.IOS = false;
}
module.exports.getAppPath = function (app) {
if (env.IOS) {
return path.resolve(__dirname, "../../sample-code/apps/" + app +
"/build/Release-iphonesimulator/" + app + ".app");
return "sample-code/apps/" + app +
"/build/Release-iphonesimulator/" + app + ".app";
}
if (env.ANDROID) {
return path.resolve(__dirname, "../../sample-code/apps/" + app +
"/bin/" + app + "-debug.apk");
return "sample-code/apps/" + app +
"/bin/" + app + "-debug.apk";
}
return app;
};