From 4786efb85c96ff7dda6c2dfe6ba615fff7479748 Mon Sep 17 00:00:00 2001 From: Jonathan Xi Date: Thu, 22 Aug 2019 01:51:05 +0800 Subject: [PATCH] Let v4 support w3c drivers * Add w3c capabilities to the session command to let w3c drivers work correctly. --- lib/protocol/init.js | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/protocol/init.js b/lib/protocol/init.js index b0706dcd..cab1d488 100644 --- a/lib/protocol/init.js +++ b/lib/protocol/init.js @@ -56,10 +56,40 @@ export default function init (desiredCapabilities = {}) { } }) - return this.requestHandler.create({ - path: '/session', - method: 'POST' - }, { - desiredCapabilities: this.desiredCapabilities - }) + const jsonwpCaps = this.desiredCapabilities; + const w3cCapKeys = [ + "browserName", + "browserVersion", + "platformName", + "acceptInsecureCerts", + "pageLoadStrategy", + "proxy", + "setWindowRect", + "timeouts", + "strictFileInteractability", + "unhandledPromptBehavior", + "goog:chromeOptions", + "moz:firefoxOptions" + ]; + const w3cCapsAlwaysMatch = {}; + w3cCapKeys.forEach(key => { + if (jsonwpCaps[key]) { + w3cCapsAlwaysMatch[key] = jsonwpCaps[key]; + } + }); + const w3cCaps = { + alwaysMatch: w3cCapsAlwaysMatch, + firstMatch: [{}] + }; + + return this.requestHandler.create( + { + path: "/session", + method: "POST" + }, + { + desiredCapabilities: jsonwpCaps, + capabilities: w3cCaps + } + ); }