Skip to content

Commit

Permalink
fix: Work around msedgedriver 115+ bug (#60)
Browse files Browse the repository at this point in the history
Specify the explicit path to microsoft-edge if found, to work around
MicrosoftEdge/EdgeWebDriver#102 (comment)

This also incorporates
shaka-project/webdriver-installer#35 to revert a
previous workaround at that level.
  • Loading branch information
joeyparrish authored Sep 7, 2023
1 parent 96caa28 commit 56a6688
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 39 deletions.
40 changes: 30 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
47 changes: 19 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"author": "Joey Parrish <[email protected]>",
"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"
Expand Down

0 comments on commit 56a6688

Please sign in to comment.