diff --git a/lib/android-helpers.js b/lib/android-helpers.js index 1bd8e06e..02b5316e 100644 --- a/lib/android-helpers.js +++ b/lib/android-helpers.js @@ -309,8 +309,10 @@ helpers.installApk = async function (adb, opts = {}) { * @param {Object} opts Opts defined in driver.js */ helpers.installOtherApks = async function (otherApps, adb, opts) { - let {androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT, - autoGrantPermissions} = opts; + let { + androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT, + autoGrantPermissions + } = opts; // Install all of the APK's asynchronously await B.all(otherApps.map((otherApp) => { @@ -318,7 +320,7 @@ helpers.installOtherApks = async function (otherApps, adb, opts) { return adb.install(otherApp, { grantPermissions: autoGrantPermissions, timeout: androidInstallTimeout, - "-r": true, + replace: true, }); })); }; @@ -584,21 +586,22 @@ helpers.removeAllSessionWebSocketHandlers = async function (server, sessionId) { } }; -helpers.parseArray = function (cap) { - // If it's a string, try parsing as an object/array - if (_.isString(cap)) { - let parsedCaps; - try { - parsedCaps = JSON.parse(cap); - } catch (ign) { } +/** + * Takes a desired capability and tries to JSON.parse it as an array, + * and either returns the parsed array or a singleton array. + * + * @param {any} cap A desired capability + */ +helpers.parseArray = function (cap) { + let parsedCaps; + try { + parsedCaps = JSON.parse(cap); + } catch (ign) { } - if (_.isArray(parsedCaps)) { - return parsedCaps; - } else if (_.isPlainObject(parsedCaps)) { - throw new Error(`must provide a string or JSON array; received ${cap}`); - } else { - return [cap]; - } + if (_.isArray(parsedCaps)) { + return parsedCaps; + } else if (_.isString(cap)) { + return [cap]; } throw new Error(`must provide a string or JSON Array; received ${cap}`); diff --git a/test/unit/android-helper-specs.js b/test/unit/android-helper-specs.js index 588a1a21..cdd7e4a6 100644 --- a/test/unit/android-helper-specs.js +++ b/test/unit/android-helper-specs.js @@ -394,9 +394,9 @@ describe('Android Helpers', function () { })); describe('installOtherApks', withMocks({adb, fs, helpers}, function (mocks) { const opts = { - app : 'local', - appPackage : 'pkg', - androidInstallTimeout : 90000 + app: 'local', + appPackage: 'pkg', + androidInstallTimeout: 90000 }; const fakeApk = '/path/to/fake/app.apk'; @@ -405,7 +405,7 @@ describe('Android Helpers', function () { const expectedADBInstallOpts = { grantPermissions: undefined, timeout: opts.androidInstallTimeout, - "-r": true, + replace: true, }; it('should not call adb.install if otherApps is empty', async function () { @@ -695,9 +695,5 @@ describe('Android Helpers', function () { it('should parse a simple string to one item array', function () { helpers.parseArray('abc').should.eql(['abc']); }); - it('should reject if an Object is provided', function () { - (() => helpers.parseArray('{"hello": "world"}')).should.throw(/s/); - //(() => helpers.parseArray('{"hello": "world"}'))().should.throw(/must provide a/); - }); }); });