deviceName is required, unrecognized caps get logged to console. fixes #2765

This commit is contained in:
Jonah Stiennon
2014-06-12 15:36:09 -07:00
parent ed96277cff
commit ecc314e2df
3 changed files with 35 additions and 7 deletions

View File

@@ -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);

View File

@@ -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));

View File

@@ -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 () {