Write defaultCapabilities into firstMatch instead of alwaysMatch only if it is not overriden
Partially addresses protocol setting issue in
MODIFY
lib/utils.js
lib/utils.js
@@ -61,22 +61,38 @@ function parseCapsForInnerDriver (jsonwpCapabilities, w3cCapabilities, constrain
const {W3C, MJSONWP} = BaseDriver.DRIVER_PROTOCOL;
- // Make copies of the capabilities that include the default capabilities
+ // Make sure we don't mutate the original arguments
+ jsonwpCapabilities = _.cloneDeep(jsonwpCapabilities);
+ w3cCapabilities = _.cloneDeep(w3cCapabilities);
+ defaultCapabilities = _.cloneDeep(defaultCapabilities);
+
+ if (!_.isEmpty(defaultCapabilities)) {
if (hasW3CCaps) {
- w3cCapabilities = {
- ...w3cCapabilities,
- alwaysMatch: {
- ...defaultCapabilities,
- ...w3cCapabilities.alwaysMatch,
- },
- };
+ const {firstMatch = [], alwaysMatch = {}} = w3cCapabilities;
+ for (const [defaultCapKey, defaultCapValue] of _.toPairs(defaultCapabilities)) {
+ let isCapAlreadySet = false;
+ for (const firstMatchEntry of firstMatch) {
+ if (_.has(removeW3CPrefixes(firstMatchEntry), removeW3CPrefix(defaultCapKey))) {
+ isCapAlreadySet = true;
+ break;
+ }
+ }
+ isCapAlreadySet = isCapAlreadySet || _.has(removeW3CPrefixes(alwaysMatch), removeW3CPrefix(defaultCapKey));
+ if (isCapAlreadySet) {
+ continue;
}
+ // Only add the default capability if it is not overridden
+ if (_.isEmpty(firstMatch)) {
+ w3cCapabilities.firstMatch = [{defaultCapKey: defaultCapValue}];
+ } else {
+ firstMatch[0][defaultCapKey] = defaultCapValue;
+ }
+ }
+ }
if (hasJSONWPCaps) {
- jsonwpCapabilities = {
- ...defaultCapabilities,
- ...jsonwpCapabilities,
- };
+ jsonwpCapabilities = Object.assign({}, removeW3CPrefixes(defaultCapabilities), jsonwpCapabilities);
+ }
}
// Get MJSONWP caps
@@ -220,13 +236,16 @@ function removeW3CPrefixes (caps) {
const fixedCaps = {};
for (let [name, value] of _.toPairs(caps)) {
- const colonPos = name.indexOf(':');
- const key = colonPos > 0 ? name.substring(colonPos + 1) : name;
- fixedCaps[key] = value;
+ fixedCaps[removeW3CPrefix(name)] = value;
}
return fixedCaps;
}
+function removeW3CPrefix (key) {
+ const colonPos = key.indexOf(':');
+ return colonPos > 0 && key.length > colonPos ? key.substring(colonPos + 1) : key;
+}
+
function getPackageVersion (pkgName) {
const pkgInfo = require(`${pkgName}/package.json`) || {};
return pkgInfo.version;

Write defaultCapabilities into firstMatch instead of alwaysMatch only if it is not overriden (#11303)

Partially addresses protocol setting issue in #11300