Skip to content

Commit f4bb1e4

Browse files
authored
feat: Add Opera support (#97)
Close #73
1 parent 93c4838 commit f4bb1e4

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,62 @@ const LocalWebDriverFirefoxHeadless = generateSubclass(
385385
},
386386
});
387387

388+
// Opera binary detection
389+
const operaOptions = {};
390+
let operaBinary = which.sync('opera', {nothrow: true});
391+
392+
const operaPaths = {
393+
darwin: [
394+
'/Applications/Opera.app/Contents/MacOS/Opera',
395+
'/Applications/Opera Stable.app/Contents/MacOS/Opera',
396+
],
397+
win32: [
398+
'C:\\Program Files\\Opera\\opera.exe',
399+
'C:\\Program Files (x86)\\Opera\\opera.exe',
400+
`C:\\Users\\${os.userInfo().username}\\AppData\\Local\\Programs\\Opera\\opera.exe`,
401+
],
402+
linux: [
403+
'/snap/bin/opera',
404+
'/usr/bin/opera',
405+
],
406+
};
407+
408+
if (!operaBinary && operaPaths[os.platform()]) {
409+
for (const p of operaPaths[os.platform()]) {
410+
if (fs.existsSync(p)) {
411+
operaBinary = p;
412+
break;
413+
}
414+
}
415+
}
416+
417+
if (operaBinary) {
418+
operaOptions['goog:chromeOptions'] = {
419+
binary: operaBinary,
420+
};
421+
}
422+
423+
const LocalWebDriverOpera = generateSubclass(
424+
'Opera', 'Opera',
425+
'operadriver',
426+
(port) => ['--port=' + port],
427+
operaOptions);
428+
429+
const LocalWebDriverOperaHeadless = generateSubclass(
430+
'Opera', 'OperaHeadless',
431+
'operadriver',
432+
(port) => ['--port=' + port],
433+
mergeOptions(operaOptions, {
434+
'goog:chromeOptions': {
435+
args: [
436+
'--headless',
437+
'--no-sandbox',
438+
'--disable-gpu',
439+
'--disable-dev-shm-usage',
440+
],
441+
},
442+
}));
443+
388444
const LocalWebDriverSafari = generateSafariDriver('Safari');
389445

390446
const LocalWebDriverSafariIOS = generateSafariDriver('SafariIOS', 'iPhone');
@@ -407,6 +463,8 @@ module.exports = {
407463
'launcher:EdgeHeadless': ['type', LocalWebDriverEdgeHeadless],
408464
'launcher:Firefox': ['type', LocalWebDriverFirefox],
409465
'launcher:FirefoxHeadless': ['type', LocalWebDriverFirefoxHeadless],
466+
'launcher:Opera': ['type', LocalWebDriverOpera],
467+
'launcher:OperaHeadless': ['type', LocalWebDriverOperaHeadless],
410468
};
411469

412470
// Safari is only supported on Mac.

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
"karma-launcher",
1313
"chrome",
1414
"firefox",
15+
"opera",
1516
"safari",
1617
"webdriver"
1718
],
1819
"author": "Joey Parrish <joeyparrish@google.com>",
1920
"dependencies": {
2021
"lodash": "^4.17.21",
2122
"wd": "^1.14.0",
22-
"webdriver-installer": "^1.2.1",
23+
"webdriver-installer": "^1.3.0",
2324
"which": "^4.0.0"
2425
},
2526
"peerDependencies": {

0 commit comments

Comments
 (0)