From fcfefd02c7b7cca6ca9f0535f576a3dd8beb12ad Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 6 Sep 2018 07:11:16 +0200 Subject: [PATCH] Fix the key name for the default capability (#11316) * Fix the key name for the default capability * Add a unit test for default caps --- lib/utils.js | 2 +- test/utils-specs.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index cc3075edaf7..5ffdf20d2ec 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -84,7 +84,7 @@ function parseCapsForInnerDriver (jsonwpCapabilities, w3cCapabilities, constrain // Only add the default capability if it is not overridden if (_.isEmpty(firstMatch)) { - w3cCapabilities.firstMatch = [{defaultCapKey: defaultCapValue}]; + w3cCapabilities.firstMatch = [{[defaultCapKey]: defaultCapValue}]; } else { firstMatch[0][defaultCapKey] = defaultCapValue; } diff --git a/test/utils-specs.js b/test/utils-specs.js index 843a7328d2d..55eb95b63d1 100644 --- a/test/utils-specs.js +++ b/test/utils-specs.js @@ -37,6 +37,22 @@ describe('utils', function () { processedJsonwpCapabilities.should.deep.equal({foo: 'bar', ...BASE_CAPS}); processedW3CCapabilities.alwaysMatch.should.deep.equal({'appium:foo': 'bar', ...insertAppiumPrefixes(BASE_CAPS)}); }); + it('should rewrite default capabilities in results', function () { + const baseCapsWithDefault = Object.assign({}, BASE_CAPS, { + foo: 'baz', + 'appium:foo2': 'baz2', + }); + const w3cCapsWithDefault = _.cloneDeep(W3C_CAPS); + w3cCapsWithDefault.alwaysMatch.foo = 'baz'; + w3cCapsWithDefault.alwaysMatch.foo2 = 'baz2'; + let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(baseCapsWithDefault, w3cCapsWithDefault, {}, { + foo: 'bar', + 'appium:foo2': 'bar2', + }); + desiredCaps.should.deep.equal({foo: 'baz', foo2: 'baz2', ...BASE_CAPS}); + processedJsonwpCapabilities.should.deep.equal({foo: 'baz', foo2: 'baz2', ...BASE_CAPS}); + processedW3CCapabilities.alwaysMatch.should.deep.equal({'appium:foo': 'baz', 'appium:foo2': 'baz2', ...insertAppiumPrefixes(BASE_CAPS)}); + }); it('should reject if W3C caps are not passing constraints', function () { const err = parseCapsForInnerDriver(undefined, W3C_CAPS, {hello: {presence: true}}).error; err.message.should.match(/'hello' can't be blank/);