Skip to content

Commit 43ac77d

Browse files
ondrejbartasAndreyBelym
authored andcommitted
Add possibility to set chromeOptions by ENV variable (#56)
1 parent 0fc64d0 commit 43ac77d

2 files changed

Lines changed: 49 additions & 9 deletions

File tree

README.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Before using this plugin, save the BrowserStack username and access key to envir
1515
Project name and build name will be displayed in BrowserStack if you set the environment variables `BROWSERSTACK_PROJECT_NAME` and `BROWSERSTACK_BUILD_ID`.
1616

1717
If you have troubles starting multiple browsers at once, or get `browserstack-local` related errors like [#27](https://github.com/DevExpress/testcafe-browser-provider-browserstack/issues/27),
18-
try setting the `BROWSERSTACK_PARALLEL_RUNS` environment variable to the number of browsers you want to run simultaneously, or to 1 if you want to run just one browser.
18+
try setting the `BROWSERSTACK_PARALLEL_RUNS` environment variable to the number of browsers you want to run simultaneously, or to 1 if you want to run just one browser.
1919

2020
You can determine the available browser aliases by running
2121
```
@@ -45,29 +45,66 @@ Tip: you can skip version (`@53.0`) or/and OS name (`:Windows 10`).
4545
Proxy options can be passed via envrionment variables.
4646

4747
- `BROWSERSTACK_PROXY` - a string that specifies a proxy for the Browserstack local binary. It should have the following structure: `user:pass@proxyHostName:port`,
48-
- `BROWERSTACK_LOCAL_PROXY` - a string that specifies a proxy for the local web server. It should have the following structure: `user:pass@proxyHostName:port`,
48+
- `BROWERSTACK_LOCAL_PROXY` - a string that specifies a proxy for the local web server. It should have the following structure: `user:pass@proxyHostName:port`,
4949
- `BROWSERSTACK_FORCE_PROXY` - if it's not empty, forces all traffic of Browserstack local binary to go through the proxy,
5050
- `BROWSERSTACK_FORCE_LOCAL` - if it's not empty, forces all traffic of Browserstack local binary to go through the local machine
5151

52-
## Browserstack JS Testing and Browserstack Automate
52+
Example:
53+
```
54+
export BROWERSTACK_PROXY="user:p@ssw0rd@proxy.com:8080"
55+
export BROWERSTACK_LOCAL_PROXY="admin:12345678@192.168.0.2:8080"
56+
export BROWSERSTACK_FORCE_PROXY="1"
57+
export BROWSERSTACK_FORCE_LOCAL="1"
58+
testcafe browserstack:chrome test.js
59+
```
60+
61+
## Browserstack JS Testing and Browserstack Automate
5362
Browserstack offers two APIs for browser testing:
5463
- [Browserstack JS Testing](https://www.browserstack.com/javascript-testing-api)
5564
- [Browserstack Automate](https://www.browserstack.com/automate)
56-
57-
JS testing supports more types of devices (compare: [JS Testing devices](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing)
58-
vs [Automate devices](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate)),
59-
while Automate allows for much longer tests ([2 hours](https://www.browserstack.com/automate/timeouts) vs [30 minutes](https://github.com/browserstack/api#timeout300))
65+
66+
JS testing supports more types of devices (compare: [JS Testing devices](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing)
67+
vs [Automate devices](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate)),
68+
while Automate allows for much longer tests ([2 hours](https://www.browserstack.com/automate/timeouts) vs [30 minutes](https://github.com/browserstack/api#timeout300))
6069
and provides some additional features (like the window resizing functionality).
61-
62-
TestCafe uses the JS Testing API by default. In order to use Browserstack Automate,
70+
71+
TestCafe uses the JS Testing API by default. In order to use Browserstack Automate,
6372
set the `BROWSERSTACK_USE_AUTOMATE` environment variable to `1`.
6473

74+
Example:
75+
```
76+
export BROWSERSTACK_USE_AUTOMATE="1"
77+
testcafe browserstack:chrome test.js
78+
```
79+
6580
## Setting display resolution
6681

6782
To set the display resolution, use the `BROWSERSTACK_DISPLAY_RESOLUTION` environment variable.
6883
Valid resolutions can be found [here](https://github.com/browserstack/api#resolution).
6984

7085
Remember that this only sets the display resolution and does not resize the browser window. You'll still need to use TestCafe's [window resizing API](https://devexpress.github.io/testcafe/documentation/test-api/actions/resize-window.html) to do so.
7186

87+
Example:
88+
```
89+
export BROWSERSTACK_DISPLAY_RESOLUTION="1024x768"
90+
testcafe browserstack:chrome test.js
91+
```
92+
93+
## Specyfing Chrome Command Line Arguments
94+
95+
To set [Chrome command line arguments](https://peter.sh/experiments/chromium-command-line-switches/), use the `BROWSERSTACK_CHROME_ARGS` environment variable. You can specify multiple arguments by joining them with the space symbol. This option works only if the [Browserstack Automate API is enabled](https://github.com/ondrejbartas/testcafe-browser-provider-browserstack/#browserstack-js-testing-and-browserstack-automate).
96+
97+
Examples:
98+
```
99+
export BROWSERSTACK_USE_AUTOMATE="1"
100+
export BROWSERSTACK_CHROME_ARGS="--autoplay-policy=no-user-gesture-required"
101+
testcafe browserstack:chrome test.js
102+
```
103+
```
104+
export BROWSERSTACK_USE_AUTOMATE="1"
105+
export BROWSERSTACK_CHROME_ARGS="--start-maximized --autoplay-policy=no-user-gesture-required"
106+
testcafe browserstack:chrome test.js
107+
```
108+
72109
## Author
73110
Developer Express Inc. (https://devexpress.com)

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export default {
177177
capabilities.local = true;
178178
}
179179

180+
if (browserName.indexOf('chrome') !== -1 && process.env['BROWSERSTACK_CHROME_ARGS'] && process.env['BROWSERSTACK_CHROME_ARGS'].length > 0)
181+
capabilities.chromeOptions = { args: [process.env['BROWSERSTACK_CHROME_ARGS']] };
182+
180183
await this.backend.openBrowser(id, pageUrl, capabilities);
181184

182185
this.setUserAgentMetaInfo(id, this.backend.getSessionUrl(id));

0 commit comments

Comments
 (0)