mirror of
https://github.com/appium/appium.git
synced 2026-10-26 02:29:38 +08:00
Parse number caps
This commit is contained in:
@@ -19,6 +19,11 @@ commands.createSession = async function (caps) {
|
||||
// merge caps onto opts so we don't need to worry about what's where
|
||||
Object.assign(this.opts, this.caps);
|
||||
|
||||
// deal with reset
|
||||
if (this.opts.noReset === true) this.opts.fullReset = false;
|
||||
if (this.opts.fullReset === true) this.opts.noReset = false;
|
||||
this.opts.fastReset = !this.opts.fullReset && !this.opts.noReset;
|
||||
this.opts.skipUninstall = this.opts.fastReset || this.opts.noReset;
|
||||
|
||||
// Prevents empty string caps so we don't need to test it everywhere
|
||||
if (typeof this.opts.app === 'string' && this.opts.app.trim() === '') {
|
||||
@@ -76,6 +81,21 @@ function fixCaps (originalCaps, desiredCapConstraints = {}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// int capabilities are often sent in as strings by frameworks
|
||||
let intCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
|
||||
for (let cap of intCaps) {
|
||||
let value = originalCaps[cap];
|
||||
if (_.isString(value)) {
|
||||
let newValue = parseInt(value, 10);
|
||||
if (value.indexOf('.') !== -1) {
|
||||
newValue = parseFloat(value);
|
||||
}
|
||||
log.warn(`Capability '${cap}' changed from string ('${value}') to integer (${newValue}). This may cause unexpected behavior`);
|
||||
caps[cap] = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,44 @@ describe('Desired Capabilities', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('number capabilities', () => {
|
||||
it('should allow a string "1"', async () => {
|
||||
await d.createSession({
|
||||
'platformName': 'iOS',
|
||||
'deviceName': 'Delorean',
|
||||
'newCommandTimeout': '1'
|
||||
});
|
||||
logger.warn.callCount.should.be.above(0);
|
||||
|
||||
let sessions = await d.getSessions();
|
||||
sessions[0].capabilities.newCommandTimeout.should.eql(1);
|
||||
});
|
||||
|
||||
it('should allow a string "1.1"', async () => {
|
||||
await d.createSession({
|
||||
'platformName': 'iOS',
|
||||
'deviceName': 'Delorean',
|
||||
'newCommandTimeout': '1.1'
|
||||
});
|
||||
logger.warn.callCount.should.be.above(0);
|
||||
|
||||
let sessions = await d.getSessions();
|
||||
sessions[0].capabilities.newCommandTimeout.should.eql(1.1);
|
||||
});
|
||||
|
||||
it('should allow a string "1" in string capabilities', async () => {
|
||||
await d.createSession({
|
||||
'platformName': 'iOS',
|
||||
'deviceName': 'Delorean',
|
||||
'language': '1'
|
||||
});
|
||||
logger.warn.callCount.should.equal(0);
|
||||
|
||||
let sessions = await d.getSessions();
|
||||
sessions[0].capabilities.language.should.eql('1');
|
||||
});
|
||||
});
|
||||
|
||||
it ('should error if objects in caps', async function () {
|
||||
try {
|
||||
await d.createSession({
|
||||
|
||||
Reference in New Issue
Block a user