Skip to content

Commit

Permalink
fix websocket bug and make sure named apps clobber device in caps
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Mar 4, 2014
1 parent e4e1936 commit 7adcac3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
22 changes: 14 additions & 8 deletions lib/appium.js
Expand Up @@ -25,7 +25,7 @@ var Appium = function (args) {
this.args = args;
this.serverArgs = _.clone(args);
this.rest = null;
this.args.webSocket = null;
this.webSocket = null;
this.deviceType = null;
this.device = null;
this.sessionId = null;
Expand All @@ -49,7 +49,7 @@ Appium.prototype.attachTo = function (rest) {
};

Appium.prototype.attachSocket = function (webSocket) {
this.args.webSocket = webSocket;
this.webSocket = webSocket;
};

Appium.prototype.registerConfig = function (configObj) {
Expand Down Expand Up @@ -77,6 +77,7 @@ Appium.prototype.preLaunch = function (cb) {

Appium.prototype.start = function (desiredCaps, cb) {
this.desiredCapabilities = desiredCaps;
this.args.webSocket = this.webSocket; // allow to persist over many sessions
if (this.sessionId === null || this.sessionOverride) {
this.configure(this.args, desiredCaps, function (err) {
if (err) {
Expand All @@ -94,6 +95,7 @@ Appium.prototype.start = function (desiredCaps, cb) {

Appium.prototype.getDeviceType = function (args, caps) {
var type = this.getDeviceTypeFromArgs(args) ||
this.getDeviceTypeFromNamedApp(args.app || caps.app) ||
this.getDeviceTypeFromDeviceCap(caps.device) ||
this.getDeviceTypeFromApp(args.app || caps.app) ||
this.getDeviceTypeFromPackage(args.androidPackage ||
Expand All @@ -120,12 +122,8 @@ Appium.prototype.getDeviceTypeFromDeviceCap = function (device) {
}
};

Appium.prototype.getDeviceTypeFromApp = function (app) {
if (/\.app$/.test(app) || /\.app\.zip$/.test(app)) {
return DT_IOS;
} else if (/\.apk$/.test(app) || /\.apk\.zip$/.test(app)) {
return DT_ANDROID;
} else if ((app && app.toLowerCase() === "safari")) {
Appium.prototype.getDeviceTypeFromNamedApp = function (app) {
if ((app && app.toLowerCase() === "safari")) {
return DT_SAFARI;
} else if ((app && app.toLowerCase() === "settings")) {
return DT_IOS;
Expand All @@ -134,6 +132,14 @@ Appium.prototype.getDeviceTypeFromApp = function (app) {
}
};

Appium.prototype.getDeviceTypeFromApp = function (app) {
if (/\.app$/.test(app) || /\.app\.zip$/.test(app)) {
return DT_IOS;
} else if (/\.apk$/.test(app) || /\.apk\.zip$/.test(app)) {
return DT_ANDROID;
}
};

Appium.prototype.getDeviceTypeFromPackage = function (pkg) {
var chromePkgs = [
"com.android.chrome"
Expand Down
2 changes: 1 addition & 1 deletion lib/devices/android/uiautomator.js
Expand Up @@ -205,7 +205,7 @@ UiAutomator.prototype.handleBootstrapOutput = function (output) {
logger.info(log);
}
}
}, this);
}.bind(this));
};

UiAutomator.prototype.errorStreamHandler = function (output) {
Expand Down
1 change: 1 addition & 0 deletions test/functional/android/chrome-specs.js
@@ -1,5 +1,6 @@
"use strict";

process.env.DEVICE = process.env.DEVICE || "android";
describe("chrome", function () {
require('../common/webview-base')('chromium');
});
1 change: 1 addition & 0 deletions test/unit/configuration-specs.js
Expand Up @@ -27,6 +27,7 @@ describe('Appium', function () {
, [{}, {app: 'settings'}, 'ios']
, [{}, {app: 'chrome'}, 'chrome']
, [{}, {app: 'chromium'}, 'chrome']
, [{}, {app: 'chromium', device: 'android'}, 'chrome']
, [{}, {app: 'browser'}, 'chrome']
, [{}, {app: 'http://www.site.com/my.app.zip'}, 'ios']
, [{}, {app: 'http://www.site.com/my.apk.zip'}, 'android']
Expand Down

0 comments on commit 7adcac3

Please sign in to comment.