Merge pull request #45 from appium/isaac-caps

Move fix caps function from appium driver
This commit is contained in:
Isaac A. Murchie
2016-03-16 15:20:38 -07:00
3 changed files with 39 additions and 0 deletions
+20
View File
@@ -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;
+1
View File
@@ -228,6 +228,7 @@ function getSwipeTouchDuration (waitGesture) {
return duration;
}
export default { configureApp, downloadApp, downloadFile, copyLocalZip,
unzipApp, unzipFile, testZipArchive, isPackageOrBundle,
getCoordDefault, getSwipeTouchDuration };
+18
View File
@@ -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');
});
});