You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/api/plugins/browser-launch-api.md
+74-18Lines changed: 74 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,19 @@
2
2
title: Browser Launch API
3
3
---
4
4
5
-
Before Cypress launches a browser, it gives you the opportunity to modify the browser preferences, install extensions, add and remove command-line arguments, and modify other options from your [pluginsFile](/guides/tooling/plugins-guide).
5
+
Before Cypress launches a browser, it gives you the opportunity to modify the
6
+
browser preferences, install extensions, add and remove command-line arguments,
7
+
and modify other options from your [pluginsFile](/guides/tooling/plugins-guide).
6
8
7
9
## Syntax
8
10
9
11
<Alerttype="warning">
10
12
11
-
⚠️ This code is part of the [plugins file](/guides/core-concepts/writing-and-organizing-tests.html#Plugin-files) and thus executes in the Node environment. You cannot call `Cypress` or `cy` commands in this file, but you do have the direct access to the file system and the rest of the operating system.
@@ -49,11 +56,16 @@ Options that can be modified to control how the browser is launched, with the fo
49
56
50
57
### Modify browser launch arguments, preferences, and extensions
51
58
52
-
Using your [pluginsFile](/guides/tooling/plugins-guide) you can tap into the `before:browser:launch` event and modify how Cypress launches the browser (e.g. modify arguments, user preferences, and extensions).
59
+
Using your [pluginsFile](/guides/tooling/plugins-guide) you can tap into the
60
+
`before:browser:launch` event and modify how Cypress launches the browser (e.g.
61
+
modify arguments, user preferences, and extensions).
53
62
54
-
This event will yield you the `browser` object, which gives you information about the browser, and the `launchOptions` object, which allows you to modify how the browser is launched.
63
+
This event will yield you the `browser` object, which gives you information
64
+
about the browser, and the `launchOptions` object, which allows you to modify
65
+
how the browser is launched.
55
66
56
-
The returned `launchOptions` object will become the new launch options for the browser.
67
+
The returned `launchOptions` object will become the new launch options for the
68
+
browser.
57
69
58
70
#### Modify browser launch arguments:
59
71
@@ -114,7 +126,8 @@ Here are preferences available for the currently supported browsers:
Cypress Test Runner is an Electron application, and its behavior (and the behavior of the bundled-in Electron browser) can be customized using command line switches. The supported switches depend on the Electron version, see [Electron documentation](https://www.electronjs.org/docs/api/command-line-switches).
165
+
Cypress Test Runner is an Electron application, and its behavior (and the
166
+
behavior of the bundled-in Electron browser) can be customized using command
167
+
line switches. The supported switches depend on the Electron version, see
You can pass Electron-specific launch arguments using the `ELECTRON_EXTRA_LAUNCH_ARGS` environment variable. For example, to disable HTTP browser cache and ignore certificate errors, you can set the environment variables before running Cypress like below:
170
+
You can pass Electron-specific launch arguments using the
171
+
`ELECTRON_EXTRA_LAUNCH_ARGS` environment variable. For example, to disable HTTP
172
+
browser cache and ignore certificate errors, you can set the environment
set ELECTRON_EXTRA_LAUNCH_ARGS=--disable-http-cache --lang=es
166
185
```
167
186
168
-
Cypress already sets some the Electron command line switches internally. See file [packages/server/lib/environment.js](https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/environment.js). There is no way to see all currently set switches after Electron's launch.
187
+
Cypress already sets some the Electron command line switches internally. See
There is no way to see all currently set switches after Electron's launch.
169
191
170
192
### See all Chrome browser switches
171
193
172
-
If you are running Cypress tests using a Chromium-based browser, you can see ALL currently set command line switches and the browser version information by opening a new tab and typing `chrome://version` url.
194
+
If you are running Cypress tests using a Chromium-based browser, you can see ALL
195
+
currently set command line switches and the browser version information by
196
+
opening a new tab and typing `chrome://version` url.
173
197
174
198
<DocsImagesrc="/img/api/chrome-switches.png"alt="See all Chrome switches" ></DocsImage>
175
199
176
200
## Examples
177
201
178
202
### Set screen size when running headless
179
203
180
-
When a browser runs headless, there is no physical display. You can override the default screen size of 1920x1080 when running headless as shown below. This will affect the size of screenshots and videos taken during the run.
204
+
When a browser runs headless, there is no physical display. You can override the
205
+
default screen size of 1280x720 when running headless as shown below. This will
206
+
affect the size of screenshots and videos taken during the run.
181
207
182
208
<Alerttype="warning">
183
209
184
-
This setting changes the display size of the screen and does not affect the `viewportWidth` and `viewportHeight` set in the [configuration](/guides/references/configuration). The `viewportWidth` and `viewportHeight` only affect the size of the application under test displayed inside the Test Runner. Read the blog post [Generate High-Resolution Videos and Screenshots](https://www.cypress.io/blog/2021/03/01/generate-high-resolution-videos-and-screenshots/) for details.
210
+
This setting changes the display size of the screen and does not affect the
211
+
`viewportWidth` and `viewportHeight` set in the
212
+
[configuration](/guides/references/configuration). The `viewportWidth` and
213
+
`viewportHeight` only affect the size of the application under test displayed
214
+
inside the Test Runner. Read the blog post
215
+
[Generate High-Resolution Videos and Screenshots](https://www.cypress.io/blog/2021/03/01/generate-high-resolution-videos-and-screenshots/)
By default, Cypress passes the Chrome command line switch to enable a fake video for a media stream. This is to better enable testing webcam functionality without having to have the necessary hardware to test.
295
+
By default, Cypress passes the Chrome command line switch to enable a fake video
296
+
for a media stream. This is to better enable testing webcam functionality
297
+
without having to have the necessary hardware to test.
246
298
247
299
<DocsImagesrc="/img/api/browser-launch-fake-video.gif"alt="Enable fake video for testing" ></DocsImage>
248
300
249
-
You can however send your own video file for testing by passing a Chrome command line switch pointing to a video file.
301
+
You can however send your own video file for testing by passing a Chrome command
Copy file name to clipboardExpand all lines: content/guides/continuous-integration/introduction.md
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -453,6 +453,16 @@ Cypress internally passes these Xvfb arguments, but if you are spawning your own
453
453
454
454
</Alert>
455
455
456
+
### Running headless tests without Xvfb
457
+
458
+
Chromium based browsers and Firefox can spawn without Xvfb when run via the `--headless` flag. If you're testing against either of those browsers using the `--browser` flag, you can opt out of Cypress spawning an X11 server by setting the environment variable [`ELECTRON_RUN_AS_NODE=1`](https://www.electronjs.org/docs/api/environment-variables#electron_run_as_node).
459
+
460
+
<Alert type="warning">
461
+
462
+
Electron cannot be run without an X11 server. Cypress's default browser is Electron and won't be able to launch if you set this environment variable. Likewise, Cypress's interactive mode (running via `cypress open`) is run via Electron and cannot be opened without an X11 server.
463
+
464
+
</Alert>
465
+
456
466
### Colors
457
467
458
468
If you want colors to be disabled, you can pass the `NO_COLOR` environment variable to disable colors. You may want to do this if ASCII characters or colors are not properly formatted in your CI.
0 commit comments