Allow numbers-as-strings while performing capabilities verification
MODIFY
lib/basedriver/commands/session.js
lib/basedriver/commands/session.js
@@ -132,9 +132,10 @@ function fixCaps (originalCaps, desiredCapConstraints = {}) {
let intCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
for (let cap of intCaps) {
let value = originalCaps[cap];
- if (_.isString(value)) {
+ if (_.isString(value) && !isNaN(value)) {
+ value = value.trim();
let newValue = parseInt(value, 10);
- if (value.indexOf('.') !== -1) {
+ if (value !== `${newValue}`) {
newValue = parseFloat(value);
}
log.warn(`Capability '${cap}' changed from string ('${value}') to integer (${newValue}). This may cause unexpected behavior`);

MODIFY
lib/basedriver/desired-caps.js
lib/basedriver/desired-caps.js
@@ -74,6 +74,12 @@ validator.validators.isNumber = function (value) {
return null;
}
+ // allow a string value
+ if (typeof value === 'string' && !isNaN(value)) {
+ log.warn('Number capability passed in as string. Functionality may be compromised.');
+ return null;
+ }
+
return 'must be of type number';
};
validator.validators.isBoolean = function (value) {
@@ -82,9 +88,7 @@ validator.validators.isBoolean = function (value) {
}
// allow a string value
- if (typeof value === 'string' &&
- ((value.toLowerCase() === 'true' || value.toLowerCase() === 'false') ||
- (value === ''))) {
+ if (typeof value === 'string' && ['true', 'false', ''].includes(value)) {
log.warn('Boolean capability passed in as string. Functionality may be compromised.');
return null;
}

Allow numbers-as-strings while performing capabilities verification (#264)