Skip to content

Commit fe47054

Browse files
authored
Added ablility to set headless mode for webdriver with firefox too (#14)
1 parent b6a5351 commit fe47054

File tree

6 files changed

+437
-436
lines changed

6 files changed

+437
-436
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ exports.config = {
4545
```
4646

4747
* For Puppeteer, TestCafe, Nigthmare, Playwright: it enables `show: true`.
48-
* For WebDriver with Chrome browser: it adds `--headless` option to chrome options inside `desiredCapabilities`.
48+
* For WebDriver with Chrome or Firefox browser: it adds `--headless` option to chrome/firefox options inside `desiredCapabilities`.
4949

5050
### setHeadedWhen
5151

@@ -80,7 +80,7 @@ exports.config = {
8080
helpers: {
8181
WebDriver: {
8282
// standard config goes here
83-
}
83+
},
8484
// or Puppeteer
8585
// or TestCafe,
8686
REST: {

hooks/setHeadedWhen.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module.exports = function(when) {
55

66
config.addHook(cfg => {
77
if (!cfg.helpers) return;
8-
if (cfg.helpers.Puppeteer) {
8+
if (cfg.helpers.Puppeteer) {
99
cfg.helpers.Puppeteer.show = true;
1010
}
1111
if (cfg.helpers.Playwright) {
1212
cfg.helpers.Playwright.show = true;
13-
}
13+
}
1414
if (cfg.helpers.Nightmare) {
1515
cfg.helpers.Nightmare.show = true;
1616
}
@@ -20,21 +20,38 @@ module.exports = function(when) {
2020
if (cfg.helpers.WebDriver) {
2121
if (cfg.helpers.WebDriver.browser === 'chrome') {
2222
if (
23-
cfg.helpers.WebDriver.desiredCapabilities &&
23+
cfg.helpers.WebDriver.desiredCapabilities &&
2424
cfg.helpers.WebDriver.desiredCapabilities.chromeOptions &&
2525
cfg.helpers.WebDriver.desiredCapabilities.chromeOptions.args
2626
) {
2727
const args = cfg.helpers.WebDriver.desiredCapabilities.chromeOptions.args;
2828
cfg.helpers.WebDriver.desiredCapabilities.chromeOptions.args = args.filter(key => key !== '--headless')
2929
}
3030
if (
31-
cfg.helpers.WebDriver.capabilities &&
31+
cfg.helpers.WebDriver.capabilities &&
3232
cfg.helpers.WebDriver.capabilities.chromeOptions &&
3333
cfg.helpers.WebDriver.capabilities.chromeOptions.args
3434
) {
3535
const args = cfg.helpers.WebDriver.capabilities.chromeOptions.args;
3636
cfg.helpers.WebDriver.capabilities.chromeOptions.args = args.filter(key => key !== '--headless')
3737
}
38+
} else if (cfg.helpers.WebDriver.browser === 'firefox') {
39+
if (
40+
cfg.helpers.WebDriver.desiredCapabilities &&
41+
cfg.helpers.WebDriver.desiredCapabilities.firefoxOptions &&
42+
cfg.helpers.WebDriver.desiredCapabilities.firefoxOptions.args
43+
) {
44+
const args = cfg.helpers.WebDriver.desiredCapabilities.firefoxOptions.args;
45+
cfg.helpers.WebDriver.desiredCapabilities.firefoxOptions.args = args.filter(key => key !== '--headless')
46+
}
47+
if (
48+
cfg.helpers.WebDriver.capabilities &&
49+
cfg.helpers.WebDriver.capabilities.firefoxOptions &&
50+
cfg.helpers.WebDriver.capabilities.firefoxOptions.args
51+
) {
52+
const args = cfg.helpers.WebDriver.capabilities.firefoxOptions.args;
53+
cfg.helpers.WebDriver.capabilities.firefoxOptions.args = args.filter(key => key !== '--headless')
54+
}
3855

3956
}
4057
}

hooks/setHeadlessWhen.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function(when) {
1111
}
1212
if (cfg.helpers.Playwright) {
1313
cfg.helpers.Playwright.show = false;
14-
}
14+
}
1515
if (cfg.helpers.Nightmare) {
1616
cfg.helpers.Nightmare.show = false;
1717
}
@@ -25,7 +25,7 @@ module.exports = function(when) {
2525
cfg.helpers.WebDriver.desiredCapabilities || {},
2626
{
2727
chromeOptions: {
28-
args: [
28+
args: [
2929
"--headless",
3030
// Use --disable-gpu to avoid an error from a missing Mesa library, as per
3131
// https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
@@ -34,6 +34,17 @@ module.exports = function(when) {
3434
}
3535
}
3636
)
37+
} else if (cfg.helpers.WebDriver.browser === 'firefox') {
38+
cfg.helpers.WebDriver.desiredCapabilities = merge(
39+
cfg.helpers.WebDriver.desiredCapabilities || {},
40+
{
41+
firefoxOptions: {
42+
args: [
43+
"--headless",
44+
]
45+
}
46+
}
47+
)
3748
}
3849
}
3950
});

0 commit comments

Comments
 (0)