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 3d09840..e8fb56f 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.8" + "webdriver-installer": "^1.1.9" }, "peerDependencies": { "karma": "^6.2.0" @@ -927,20 +928,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1500,6 +1487,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 +2304,9 @@ } }, "node_modules/webdriver-installer": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.8.tgz", - "integrity": "sha512-Ptgz8VdhdzMPNDqVl7Z24n7vMIC+4wPM7C3HgU2Ikc70IXKqIUx6z+kooVs+ZKaUUvEhAhtxbs0kwqR5IERPvA==", + "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", @@ -3180,13 +3173,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "optional": true, - "peer": true - }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -3621,6 +3607,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 +4223,9 @@ } }, "webdriver-installer": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/webdriver-installer/-/webdriver-installer-1.1.8.tgz", - "integrity": "sha512-Ptgz8VdhdzMPNDqVl7Z24n7vMIC+4wPM7C3HgU2Ikc70IXKqIUx6z+kooVs+ZKaUUvEhAhtxbs0kwqR5IERPvA==", + "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 e03e756..62e5771 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.8" + "webdriver-installer": "^1.1.9" }, "peerDependencies": { "karma": "^6.2.0"