From d10a6e03c463d06fb6ce0908d9b67cb5db9079d3 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 7 Sep 2023 20:46:33 +0000 Subject: [PATCH] fix: Work around msedgedriver 115+ bug Specify the explicit path to microsoft-edge if found, to work around https://github.com/MicrosoftEdge/EdgeWebDriver/issues/102#issuecomment-1710724173 This also incorporates https://github.com/shaka-project/webdriver-installer/pull/35 to revert a previous workaround at that level. --- index.js | 40 ++++++++++++++++++++++++++++++---------- package-lock.json | 26 +++++++++++++++++++------- package.json | 3 ++- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 246a81e..c380f2d 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const wd = require('wd'); +const which = require('which'); const _ = require('lodash'); const {installWebDrivers} = require('webdriver-installer'); @@ -41,6 +42,18 @@ const PLATFORM_MAP = { 'linux': 'Linux', }; +function mergeOptions(base, custom) { + // _.mergeWith modifies the first argument, so clone the base structure first. + const output = _.cloneDeep(base); + return _.mergeWith(output, custom, + // Concatenate arrays instead of overwriting them. + (objValue, srcValue) => { + if (Array.isArray(objValue)) { + return objValue.concat(srcValue); + } + }); +} + // Subclasses must define these static members: // - BROWSER_NAME: browser name as presented to WebDriver // - LAUNCHER_NAME: launcher name as presented to Karma @@ -68,14 +81,9 @@ const LocalWebDriverBase = function(baseBrowserDecorator, args, logger) { log.debug('config:', JSON.stringify(config)); - const extraSpecs = _.mergeWith( + const extraSpecs = mergeOptions( this.constructor.EXTRA_WEBDRIVER_SPECS, - args.config, - (objValue, srcValue) => { - if (Array.isArray(objValue)) { - return objValue.concat(srcValue); - } - }); + args.config); log.debug('extraSpecs:', extraSpecs); // These names ("browser" and "spec") are needed for compatibility with @@ -288,23 +296,35 @@ const LocalWebDriverChromeHeadless = generateSubclass( // TODO: Add Chrome on android? +// If a binary is found with the name "microsoft-edge" in the PATH, specify +// that explicitly. This works around the following edgedriver bug: +// https://github.com/MicrosoftEdge/EdgeWebDriver/issues/102#issuecomment-1710724173 +const edgeOptions = {}; +const edgeBinary = which.sync('microsoft-edge'); +if (edgeBinary) { + edgeOptions['ms:edgeOptions'] = { + binary: edgeBinary, + }; +} + const LocalWebDriverEdge = generateSubclass( 'MSEdge', 'MSEdge', 'msedgedriver', - (port) => ['--port=' + port]); + (port) => ['--port=' + port], + edgeOptions); const LocalWebDriverEdgeHeadless = generateSubclass( 'MSEdge', 'MSEdgeHeadless', 'msedgedriver', (port) => ['--port=' + port], - { + mergeOptions(edgeOptions, { 'ms:edgeOptions': { args: [ '--headless', '--disable-gpu', ], }, - }); + })); const LocalWebDriverFirefox = generateSubclass( 'Firefox', 'Firefox', diff --git a/package-lock.json b/package-lock.json index 84116e2..595baa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,9 @@ "license": "Apache-2.0", "dependencies": { "lodash": "^4.17.21", + "node-which": "^1.0.0", "wd": "^1.14.0", - "webdriver-installer": "^1.1.7" + "webdriver-installer": "^1.1.9" }, "peerDependencies": { "karma": "^6.2.0" @@ -1500,6 +1501,12 @@ } } }, + "node_modules/node-which": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-which/-/node-which-1.0.0.tgz", + "integrity": "sha512-PVVbv6DyDc3VkTizcd/7Xchn3NDh+OUnQkrHxgumQ+2lwoWE36KuQClfAVjTwEh3T0jzb1WHrbgCol5HbBZqdQ==", + "deprecated": "please use 'which'" + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -2311,9 +2318,9 @@ } }, "node_modules/webdriver-installer": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.7.tgz", - "integrity": "sha512-/6mO+MDUyFcrBsM+5qxmt702KTFUFxNMJRzSMqRL6Eeajn9voNjRDyn4x2DB98XJWzy/x64hqDwzjIH+rGIP6w==", + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.9.tgz", + "integrity": "sha512-lWoCiOC9LvmGOgsTGCvu4opZxPBA76cPPbp93peSrO3djSLg5C6yDiyeWy+jN4uj3LHISZ5GTfjVOJmCE04OUQ==", "dependencies": { "node-fetch": "^2.6.7", "regedit": "^5.0.0", @@ -3621,6 +3628,11 @@ "whatwg-url": "^5.0.0" } }, + "node-which": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-which/-/node-which-1.0.0.tgz", + "integrity": "sha512-PVVbv6DyDc3VkTizcd/7Xchn3NDh+OUnQkrHxgumQ+2lwoWE36KuQClfAVjTwEh3T0jzb1WHrbgCol5HbBZqdQ==" + }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -4232,9 +4244,9 @@ } }, "webdriver-installer": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.7.tgz", - "integrity": "sha512-/6mO+MDUyFcrBsM+5qxmt702KTFUFxNMJRzSMqRL6Eeajn9voNjRDyn4x2DB98XJWzy/x64hqDwzjIH+rGIP6w==", + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.9.tgz", + "integrity": "sha512-lWoCiOC9LvmGOgsTGCvu4opZxPBA76cPPbp93peSrO3djSLg5C6yDiyeWy+jN4uj3LHISZ5GTfjVOJmCE04OUQ==", "requires": { "node-fetch": "^2.6.7", "regedit": "^5.0.0", diff --git a/package.json b/package.json index 4c1a761..f205a54 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,9 @@ "author": "Joey Parrish ", "dependencies": { "lodash": "^4.17.21", + "node-which": "^1.0.0", "wd": "^1.14.0", - "webdriver-installer": "^1.1.7" + "webdriver-installer": "^1.1.9" }, "peerDependencies": { "karma": "^6.2.0"