From ecc314e2df805d9ebac9a0f88df4f55d2a8fd921 Mon Sep 17 00:00:00 2001 From: Jonah Stiennon Date: Thu, 12 Jun 2014 15:36:09 -0700 Subject: [PATCH] deviceName is required, unrecognized caps get logged to console. fixes #2765 --- lib/appium.js | 5 ++--- lib/server/capabilities.js | 33 +++++++++++++++++++++++++++++++-- test/unit/queue-specs.js | 4 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/appium.js b/lib/appium.js index 432531ba5..84d62cfd2 100644 --- a/lib/appium.js +++ b/lib/appium.js @@ -112,6 +112,7 @@ Appium.prototype.start = function (desiredCaps, cb) { }; Appium.prototype.getDeviceType = function (args, caps) { + // TODO: 'deviceName' and 'platformName' caps are now required, so the majority of this code could be removed var type = this.getDeviceFromMJSONWP(args, caps) || this.getDeviceTypeFromArgsOrNamedApp(args, caps) || this.getDeviceTypeFromAppOrPackage(args, caps); @@ -252,9 +253,7 @@ Appium.prototype.configure = function (args, desiredCaps, cb) { try { deviceType = this.getDeviceType(args, desiredCaps); - if (args.enforceStrictCaps) { - desiredCaps.checkStrictValidity(deviceType); - } + desiredCaps.checkValidity(deviceType, args.enforceStrictCaps); } catch (e) { logger.error(e.message); return cb(e); diff --git a/lib/server/capabilities.js b/lib/server/capabilities.js index fd30f942f..4203fa1ff 100644 --- a/lib/server/capabilities.js +++ b/lib/server/capabilities.js @@ -15,11 +15,16 @@ var okObjects = [ var requiredCaps = [ 'platformName' +, 'deviceName' +]; + +var strictRequiredCaps = [ + 'platformName' , 'platformVersion' , 'deviceName' ]; -var generalCaps = requiredCaps.concat([ +var generalCaps = strictRequiredCaps.concat([ 'automationName' , 'app' , 'browserName' @@ -98,6 +103,30 @@ Capabilities.prototype.setDesired = function (caps) { }, this); }; +Capabilities.prototype.checkValidity = function (deviceType, strictMode) { + if (strictMode) { + this.checkStrictValidity(deviceType); + } else { + + var capsUsed = _.keys(this.desired); + var forgottenRequiredCaps = _.difference(requiredCaps, capsUsed); + if (forgottenRequiredCaps.length) { + throw new Error('The following desired capabilities are required, but were not provided: ' + + forgottenRequiredCaps.join(', ')); + } + + // log a message about caps which are passed in and not recognized by appium + var allValidCaps = [].concat(generalCaps, androidCaps, iosCaps); + var unknownCaps = _.difference(capsUsed, allValidCaps); + if (unknownCaps.length > 0) { + logger.info('The following desired capabilities were provided, but not recognized by appium.' + + ' They will be passed on to any other services running on this server. : ' + + unknownCaps.join(', ')); + } + + } +}; + Capabilities.prototype.checkStrictValidity = function (deviceType) { if (_.contains(["firefoxos", "selendroid"], deviceType)) { logger.debug("Not checking cap validity because we're proxying all caps " + @@ -117,7 +146,7 @@ Capabilities.prototype.checkStrictValidity = function (deviceType) { JSON.stringify(unknownCaps) + ". Please remove unknown caps"); } - var forgottenRequiredCaps = _.difference(requiredCaps, capsUsed); + var forgottenRequiredCaps = _.difference(strictRequiredCaps, capsUsed); if (forgottenRequiredCaps.length > 0) { return e("Appium requires the following caps to be passed in: " + JSON.stringify(forgottenRequiredCaps)); diff --git a/test/unit/queue-specs.js b/test/unit/queue-specs.js index 43b10208a..72aa075b0 100644 --- a/test/unit/queue-specs.js +++ b/test/unit/queue-specs.js @@ -67,7 +67,7 @@ describe('Appium', function () { var loop = function (num) { if (num > 9) return; - appium.start({app: "/path/to/fake.app", device: "iPhone"}, function (err) { + appium.start({app: "/path/to/fake.app", deviceName: "iPhone", platformName: "iOS"}, function (err) { var n = num; if (n === 0) { should.not.exist(err); @@ -97,7 +97,7 @@ describe('Appium with clobber', function () { describe('#start', function () { it('should clobber existing sessions', function (done) { var numSessions = 9 - , dc = {app: "/path/to/fake.app", device: "iPhone"}; + , dc = {app: "/path/to/fake.app", deviceName: "iPhone", platformName: 'iOS'}; var loop = function (num) { if (num > numSessions) return; appium.start(dc, function () {