Remove prefixes from MJSONWP capabilities if W3C protocol cannot be enabled
MODIFY
lib/utils.js
lib/utils.js
@@ -82,20 +82,21 @@ function parseCapsForInnerDriver (jsonwpCaps, w3cCapabilities, constraints={}, d
protocol = W3C;
// Call the process capabilities algorithm to find matching caps on the W3C
// (see: https://github.com/jlipps/simple-wd-spec#processing-capabilities)
- let matchingW3CCaps;
try {
- matchingW3CCaps = processCapabilities(w3cCapabilities, constraints, true);
+ desiredCaps = processCapabilities(w3cCapabilities, constraints, true);
} catch (err) {
if (jsonwpCaps) {
logger.warn(`Could not parse W3C capabilities: ${err.message}. Falling back to JSONWP protocol.`);
- protocol = MJSONWP;
- } else {
- error = err;
+ return {
+ desiredCaps: removeW3CPrefixes(desiredCaps),
+ processedJsonwpCapabilities: removeW3CPrefixes(processedJsonwpCapabilities),
+ processedW3CCapabilities: null,
+ protocol: MJSONWP,
+ };
}
+ error = err;
}
- desiredCaps = matchingW3CCaps;
-
// Create a new w3c capabilities payload that contains only the matching caps in `alwaysMatch`
processedW3CCapabilities = {
alwaysMatch: {...insertAppiumPrefixes(desiredCaps)},
@@ -104,7 +105,7 @@ function parseCapsForInnerDriver (jsonwpCaps, w3cCapabilities, constraints={}, d
// If we found extraneuous keys in JSONWP caps, fall back to JSONWP
if (hasJSONWPCaps) {
- let differingKeys = _.difference(_.keys(jsonwpCaps), _.keys(matchingW3CCaps));
+ let differingKeys = _.difference(_.keys(jsonwpCaps), _.keys(desiredCaps));
if (!_.isEmpty(differingKeys)) {
logger.warn(`The following capabilities were provided in the JSONWP desired capabilities that are missing ` +
`in W3C capabilities: ${JSON.stringify(differingKeys)}. Falling back to JSONWP protocol.`);
@@ -149,6 +150,20 @@ function insertAppiumPrefixes (caps) {
return prefixedCaps;
}
+function removeW3CPrefixes (caps) {
+ if (!_.isPlainObject(caps)) {
+ return 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;
+ }
+ return fixedCaps;
+}
+
const rootDir = findRoot(__dirname);
export { inspectObject, parseCapsForInnerDriver, insertAppiumPrefixes, rootDir };

Remove prefixes from MJSONWP capabilities if W3C protocol cannot be enabled (#10948)