diff --git a/lib/utils.js b/lib/utils.js index c17585f95..10c1597e1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -81,30 +81,32 @@ function parseCapsForInnerDriver (jsonwpCaps, w3cCapabilities, constraints={}, d } catch (err) { if (jsonwpCaps) { logger.warn(`Could not parse W3C capabilities: ${err.message}. Falling back to JSONWP protocol.`); + return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities}; } else { throw err; } - } finally { - desiredCaps = matchingW3CCaps; + } - // Create a new w3c capabilities payload that contains only the matching caps in `alwaysMatch` - processedW3CCapabilities = { - alwaysMatch: {...insertAppiumPrefixes(desiredCaps)}, - firstMatch: [{}], - }; + desiredCaps = matchingW3CCaps; - // If we found extraneuous keys in JSONWP caps, fall back to JSONWP - if (hasJSONWPCaps) { - let differingKeys = _.difference(_.keys(jsonwpCaps), _.keys(matchingW3CCaps)); - 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.`); - desiredCaps = jsonwpCaps; - processedW3CCapabilities = null; - } + // Create a new w3c capabilities payload that contains only the matching caps in `alwaysMatch` + processedW3CCapabilities = { + alwaysMatch: {...insertAppiumPrefixes(desiredCaps)}, + firstMatch: [{}], + }; + + // If we found extraneuous keys in JSONWP caps, fall back to JSONWP + if (hasJSONWPCaps) { + let differingKeys = _.difference(_.keys(jsonwpCaps), _.keys(matchingW3CCaps)); + 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.`); + desiredCaps = jsonwpCaps; + return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities: null}; } } } + return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities}; } diff --git a/test/driver-e2e-specs.js b/test/driver-e2e-specs.js index df55377a4..215445bee 100644 --- a/test/driver-e2e-specs.js +++ b/test/driver-e2e-specs.js @@ -105,9 +105,9 @@ describe('FakeDriver - via HTTP', function () { screenshotValue.should.equal('hahahanotreallyascreenshot'); // Now use that sessionID to call an arbitrary W3C-only endpoint that isn't implemented to see if it responds with correct error - const {statusCode, message} = await request.post({url: `${baseUrl}/${value.sessionId}/execute/async`, json: {script: '', args: ['a']}}).should.eventually.be.rejected; + const {statusCode, error} = await request.post({url: `${baseUrl}/${value.sessionId}/execute/async`, json: {script: '', args: ['a']}}).should.eventually.be.rejected; statusCode.should.equal(404); - message.should.match(/Method has not yet been implemented/); + error.value.message.should.match(/Method has not yet been implemented/); // End session await request.delete({url: `${baseUrl}/${value.sessionId}`}).should.eventually.be.resolved; @@ -121,9 +121,9 @@ describe('FakeDriver - via HTTP', function () { } }; - const {statusCode, message} = await request.post({url: baseUrl, json: badW3Ccaps}).should.eventually.be.rejected; + const {statusCode, error} = await request.post({url: baseUrl, json: badW3Ccaps}).should.eventually.be.rejected; statusCode.should.equal(400); - message.should.match(/can't be blank/); + error.value.message.should.match(/can't be blank/); }); it('should accept a combo of W3C and JSONWP capabilities but default to W3C', async function () { @@ -184,7 +184,8 @@ describe('FakeDriver - via HTTP', function () { } }, }; - const {message, statusCode} = await request.post({url: baseUrl, json: w3cCaps}).should.eventually.be.rejected; + const {error, statusCode} = await request.post({url: baseUrl, json: w3cCaps}).should.eventually.be.rejected; + const {message} = error.value; message.should.match(/BadAutomationName not part of/); statusCode.should.equal(400); });