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
Broadly, configuration on CI involves **ensuring system dependencies** are in place, **installing Playwright and browsers** (typically with `npm install`), and **running tests** (typically with `npm test`). Windows and macOS build agents do not require any additional system dependencies. Linux build agents can require additional dependencies, depending on the Linux distribution.
@@ -37,7 +37,7 @@ We run [our tests](/.github/workflows/tests.yml) on GitHub Actions, across a mat
37
37
38
38
We have a [pre-built Docker image](docker/README.md) which can either be used directly, or as a reference to update your existing Docker definitions.
39
39
40
-
#### Tips
40
+
Suggested configuration
41
41
1. By default, Docker runs a container with a `/dev/shm` shared memory space 64MB.
42
42
This is [typically too small](https://github.com/c0b/chrome-in-docker/issues/1) for Chromium
43
43
and will cause Chromium to crash when rendering large pages. To fix, run the container with
@@ -72,9 +72,14 @@ For Linux agents, refer to [our Docker setup](docker/README.md) to see additiona
72
72
73
73
We run our tests on Travis CI over a Linux agent (Ubuntu 18.04). Use our [Travis configuration](/.travis.yml) to see list of additional dependencies to be installed.
74
74
75
-
#### Tips
76
-
- [User namespace cloning](http://man7.org/linux/man-pages/man7/user_namespaces.7.html) should be enabled to support proper sandboxing
77
-
- [xvfb](https://en.wikipedia.org/wiki/Xvfb) should be launched in order to run Chromium in non-headless mode (e.g. to test Chrome Extensions)
1. [xvfb](https://en.wikipedia.org/wiki/Xvfb) should be launched in order to run
79
+
Chromium in non-headless mode (e.g. to test Chrome Extensions)
80
+
1. If your project does not have `package-lock.json`, Travis would be auto-caching
81
+
`node_modules`directory. If you run `npm install` (instead of `npm ci`), it is
82
+
possible that the browser binaries are not downloaded. Fix this with [these steps](#exception-nodemodules-are-cached) outlined below.
78
83
79
84
To sum up, your `.travis.yml` might look like this:
80
85
@@ -84,6 +89,8 @@ dist: bionic
84
89
addons:
85
90
apt:
86
91
packages:
92
+
# This is required to run chromium
93
+
- libgbm1
87
94
# These are required to run webkit
88
95
- libwoff1
89
96
- libopus0
@@ -100,8 +107,8 @@ addons:
100
107
- libnotify4
101
108
- libxslt1.1
102
109
- libvpx5
103
-
# This is required to run chromium
104
-
- libgbm1
110
+
# For headful execution
111
+
- xvfb
105
112
106
113
# allow headful tests
107
114
before_install:
@@ -139,20 +146,50 @@ We run our tests on CircleCI, with our [pre-built Docker image](docker/README.md
139
146
140
147
We run our tests on Windows agents in AppVeyor. Use our [AppVeyor configuration](/.appveyor.yml) to create your own.
141
148
142
-
## Debugging browser launches
149
+
## Caching browsers
143
150
144
-
Playwright supports the `DEBUG` environment variable to output debug logs during execution. Setting it to `pw:browser*` is helpful while debugging `Error: Failed to launch browser` errors.
151
+
By default, Playwright downloads browser binaries when the Playwright NPM package
152
+
is installed. The NPM packages have a `postinstall` hook that downloads the browser
153
+
binaries. This behavior can be [customized with environment variables](installation.md).
145
154
146
-
```
147
-
DEBUG=pw:browser* npm run test
148
-
```
155
+
Caching browsers on CI is **strictly optional**: The `postinstall` hooks should
156
+
execute and download the browser binaries on every run.
149
157
150
-
## Caching browsers
158
+
#### Exception: `node_modules` are cached
151
159
152
-
By default, Playwright installs browser binaries in the following directories. This behavior can be [customized with environment variables](installation.md).
160
+
Most CI providers cache the [npm-cache](https://docs.npmjs.com/cli-commands/cache.html)
161
+
directory (located at `$HOME/.npm`). If your CI pipelines caches the `node_modules`
162
+
directory and you run `npm install` (instead of `npm ci`), the default configuration
163
+
**will not work**. This is because the `npm install` step will find the NPM
164
+
package on disk, and not execute the `postinstall` step.
165
+
166
+
> Travis CI automatically caches `node_modules` if your repo does not have a
167
+
`package-lock.json`file.
168
+
169
+
This behavior can be fixed with one of the following approaches:
170
+
1. Move to caching `$HOME/.npm` or the npm-cache directory. (This is the default
171
+
behavior in most CI providers.)
172
+
1. Set `PLAYWRIGHT_BROWSERS_PATH=0` as the environment variable before running
173
+
`npm install`. This will download the browser binaries in the `node_modules`
174
+
directory and cache them with the package code. See [installation docs](installation.md).
175
+
1. Cache the browser binaries, with the steps below.
176
+
177
+
#### Directories to cache
178
+
179
+
With the default behavior, Playwright downloads the browser binaries in the following
180
+
directories:
153
181
154
182
- `%USERPROFILE%\AppData\Local\ms-playwright`on Windows
155
183
- `~/Library/Caches/ms-playwright`on MacOS
156
184
- `~/.cache/ms-playwright`on Linux
157
185
158
-
These locations are not covered by typical CI configurations, which cache the project `node_modules` or the [npm-cache directory](https://docs.npmjs.com/cli-commands/cache.html). To cache the browser binaries between CI runs, cache this location in your CI configuration, against a hash of the Playwright version.
186
+
To cache the browser downloads between CI runs, cache this location in your CI
187
+
configuration, against a hash of the Playwright version.
188
+
189
+
## Debugging browser launches
190
+
191
+
Playwright supports the `DEBUG` environment variable to output debug logs during execution. Setting it to `pw:browser*` is helpful while debugging `Error: Failed to launch browser` errors.
0 commit comments