diff --git a/lib/commands/session.js b/lib/commands/session.js index ea061bd08..32f1ea436 100644 --- a/lib/commands/session.js +++ b/lib/commands/session.js @@ -10,6 +10,7 @@ commands.createSession = async function (caps) { throw new errors.SessionNotCreatedError('Cannot create a new session ' + 'while one is in progress'); } + caps = fixCaps(caps, this.desiredCapConstraints); this.validateDesiredCaps(caps); this.sessionId = UUID.create().hex; this.caps = caps; @@ -59,4 +60,23 @@ commands.deleteSession = async function (/* sessionId */) { this.sessionId = null; }; +function fixCaps (originalCaps, desiredCapConstraints = {}) { + let caps = _.clone(originalCaps); + + // boolean capabilities can be passed in as strings 'false' and 'true' + // which we want to translate into boolean values + let booleanCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isBoolean === true)); + for (let cap of booleanCaps) { + let value = originalCaps[cap]; + if (_.isString(value)) { + value = value.toLowerCase(); + if (value === 'true' || value === 'false') { + log.warn(`Capability '${cap}' changed from string to boolean. This may cause unexpected behavior`); + caps[cap] = (value === 'true'); + } + } + } + return caps; +} + export default commands; diff --git a/lib/helpers.js b/lib/helpers.js index fb39639a2..d3da6d162 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -228,6 +228,7 @@ function getSwipeTouchDuration (waitGesture) { return duration; } + export default { configureApp, downloadApp, downloadFile, copyLocalZip, unzipApp, unzipFile, testZipArchive, isPackageOrBundle, getCoordDefault, getSwipeTouchDuration }; diff --git a/test/capability-specs.js b/test/capability-specs.js index e3799ccfe..13436ddbf 100644 --- a/test/capability-specs.js +++ b/test/capability-specs.js @@ -166,6 +166,9 @@ describe('Desired Capabilities', () => { 'noReset': 'false' }); logger.warn.callCount.should.be.above(0); + + let sessions = await d.getSessions(); + sessions[0].capabilities.noReset.should.eql(false); }); it('should allow a string "true"', async () => { @@ -175,6 +178,21 @@ describe('Desired Capabilities', () => { 'noReset': 'true' }); logger.warn.callCount.should.be.above(0); + + let sessions = await d.getSessions(); + sessions[0].capabilities.noReset.should.eql(true); + }); + + it('should allow a string "true" in string capabilities', async () => { + await d.createSession({ + 'platformName': 'iOS', + 'deviceName': 'Delorean', + 'language': 'true' + }); + logger.warn.callCount.should.equal(0); + + let sessions = await d.getSessions(); + sessions[0].capabilities.language.should.eql('true'); }); });