Remove unnecessary 'finally' block (#10076)

* Shouldn't have had finally block because then it does two checks to fall back to MJSONWP
* Also fixed outdated tests
This commit is contained in:
Dan Graham
2018-01-25 12:45:02 -08:00
committed by GitHub
parent 050db9880a
commit 35135a6ee5
2 changed files with 24 additions and 21 deletions
+18 -16
View File
@@ -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};
}
+6 -5
View File
@@ -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);
});