diff --git a/lib/appium.js b/lib/appium.js index c39a56678e6..b17f7b691e1 100644 --- a/lib/appium.js +++ b/lib/appium.js @@ -98,7 +98,9 @@ Appium.prototype.start = function(desiredCaps, cb) { }; Appium.prototype.getDeviceType = function(desiredCaps) { - // yay for HACKS!! + + var errMsg = "A valid device type is required in the capabilities list"; + if (desiredCaps.device) { if (desiredCaps.device.toLowerCase().indexOf('iphone') !== -1) { return "ios"; @@ -108,45 +110,16 @@ Appium.prototype.getDeviceType = function(desiredCaps) { return "selendroid"; } else if (desiredCaps.device.toLowerCase().indexOf('firefox') !== -1) { return "firefoxos"; + } else if (desiredCaps.device.toLowerCase().indexOf('android') !== -1) { + return "android"; } else if (desiredCaps.device === "mock_ios") { return "mock_ios"; } else { - return "android"; - } - } else if (desiredCaps.app) { - if (desiredCaps.app.toLowerCase() === "safari") { - return "ios"; - } else if (desiredCaps.app.toLowerCase() === "iwebview") { - return "ios"; - } else if (desiredCaps.app.toLowerCase() === "chrome") { - return "android"; - } else if (desiredCaps.app.toLowerCase() === "chromium") { - return "android"; - } - } else if (desiredCaps.browserName) { - logger.warn("WARNING: use of browserName is deprecated. Please migrate " + - "your tests"); - if (desiredCaps.browserName[0].toLowerCase() === "i") { - return "ios"; - } else if (desiredCaps.browserName.toLowerCase() === "safari") { - return "ios"; - } else if (desiredCaps.browserName.toLowerCase() === "iwebview") { - return "ios"; - } else if (desiredCaps.browserName.toLowerCase() === "chrome") { - return "android"; - } else if (desiredCaps.browserName.toLowerCase() === "chromium") { - return "android"; - } else if (desiredCaps.browserName.toLowerCase().indexOf('selendroid') !== -1) { - return "selendroid"; - } else { - return "android"; + throw new Error(errMsg); } - } else if (desiredCaps["app-package"] || this.args.androidPackage) { - return "android"; - } else if (desiredCaps["app-activity"] || this.args.androidActivity) { - return "android"; } - return "ios"; + + throw new Error(errMsg); }; Appium.prototype.isMockIos = function() { @@ -200,7 +173,12 @@ Appium.prototype.configure = function(desiredCaps, cb) { if (hasAppInCaps) { app = desiredCaps.app; } - this.deviceType = this.getDeviceType(desiredCaps); + try { + this.deviceType = this.getDeviceType(desiredCaps); + } catch (e) { + logger.error(e); + return cb(e); + } if (this.isMockIos()) { return cb(); }