Skip to content

Commit

Permalink
Move common caps verification to helpers module (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykola Mokhnach committed Jun 22, 2018
1 parent 7622b9e commit 20c9e4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
18 changes: 18 additions & 0 deletions lib/android-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,24 @@ helpers.parseArray = function (cap) {
throw new Error(`must provide a string or JSON Array; received ${cap}`);
};

helpers.validateDesiredCaps = function (caps) {
// make sure that the capabilities have one of `app`, `appPackage` or `browser`
if ((!caps.browserName || !this.isChromeBrowser(caps.browserName)) && !caps.app && !caps.appPackage) {
logger.errorAndThrow('The desired capabilities must include either an app, appPackage or browserName');
}
if (caps.browserName) {
if (caps.app) {
// warn if the capabilities have both `app` and `browser, although this is common with selenium grid
logger.warn('The desired capabilities should generally not include both an app and a browserName');
}
if (caps.appPackage) {
logger.errorAndThrow(`The desired capabilities must include either 'appPackage' or 'browserName'`);
}
}

return true;
};

helpers.bootstrap = Bootstrap;
helpers.unlocker = unlocker;

Expand Down
18 changes: 3 additions & 15 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,10 @@ class AndroidDriver extends BaseDriver {
}

validateDesiredCaps (caps) {
// check with the base class, and return if it fails
let res = super.validateDesiredCaps(caps);
if (!res) return res; // eslint-disable-line curly

// make sure that the capabilities have one of `app`, `appPackage` or `browser`
if ((!caps.browserName || !helpers.isChromeBrowser(caps.browserName)) &&
!caps.app && !caps.appPackage) {
let msg = 'The desired capabilities must include either an app, appPackage or browserName';
log.errorAndThrow(msg);
}
// warn if the capabilities have both `app` and `browser, although this
// is common with selenium grid
if (caps.browserName && caps.app) {
let msg = 'The desired capabilities should generally not include both an app and a browserName';
log.warn(msg);
if (!super.validateDesiredCaps(caps)) {
return false;
}
return helpers.validateDesiredCaps(caps);
}

proxyActive (sessionId) {
Expand Down

0 comments on commit 20c9e4a

Please sign in to comment.