Skip to content

Commit

Permalink
Fix the key name for the default capability (#11316)
Browse files Browse the repository at this point in the history
* Fix the key name for the default capability

* Add a unit test for default caps
  • Loading branch information
Mykola Mokhnach committed Sep 6, 2018
1 parent e996b30 commit fcfefd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions test/utils-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down

0 comments on commit fcfefd0

Please sign in to comment.