Skip to content

Commit

Permalink
docs(ci): update docs for caching and troubleshooting (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunattam committed May 11, 2020
1 parent c5b0baa commit 2510edc
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 140 deletions.
137 changes: 123 additions & 14 deletions docs/ci.md
Expand Up @@ -3,17 +3,24 @@
Playwright tests can be executed to run on your CI environments. To simplify this, we have created sample configurations for common CI providers that can be used to bootstrap your setup.

<!-- GEN:toc -->
- [GitHub Actions](#github-actions)
- [Docker](#docker)
- [Azure Pipelines](#azure-pipelines)
- [Travis CI](#travis-ci)
- [CircleCI](#circleci)
- [AppVeyor](#appveyor)
- [CI configurations](#ci-configurations)
* [GitHub Actions](#github-actions)
* [Docker](#docker)
- [Tips](#tips)
* [Azure Pipelines](#azure-pipelines)
* [Travis CI](#travis-ci)
- [Tips](#tips-1)
* [CircleCI](#circleci)
* [AppVeyor](#appveyor)
- [Debugging browser launches](#debugging-browser-launches)
- [Caching browsers](#caching-browsers)
<!-- GEN:stop -->

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.

## GitHub Actions
## CI configurations

### GitHub Actions

The [Playwright GitHub Action](https://github.com/microsoft/playwright-github-action) can be used to run Playwright tests on GitHub Actions.

Expand All @@ -26,24 +33,126 @@ steps:

We run [our tests](/.github/workflows/tests.yml) on GitHub Actions, across a matrix of 3 platforms (Windows, Linux, macOS) and 3 browsers (Chromium, Firefox, WebKit).

## Docker
### Docker

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.

## Azure Pipelines
#### Tips
1. By default, Docker runs a container with a `/dev/shm` shared memory space 64MB.
This is [typically too small](https://github.com/c0b/chrome-in-docker/issues/1) for Chromium
and will cause Chromium to crash when rendering large pages. To fix, run the container with
`docker run --shm-size=1gb` to increase the size of `/dev/shm`. Since Chromium 65, this is no
longer necessary. Instead, launch the browser with the `--disable-dev-shm-usage` flag:

```js
const browser = await playwright.chromium.launch({
args: ['--disable-dev-shm-usage']
});
```

This will write shared memory files into `/tmp` instead of `/dev/shm`. See
[crbug.com/736452](https://bugs.chromium.org/p/chromium/issues/detail?id=736452) for more details.
1. Using `--ipc=host` is also recommended when using Chromium—without it Chromium can run out of memory
and crash. Learn more about this option in [Docker docs](https://docs.docker.com/engine/reference/run/#ipc-settings---ipc).
1. Seeing other weird errors when launching Chromium? Try running your container
with `docker run --cap-add=SYS_ADMIN` when developing locally. Since the Dockerfile
adds a `pwuser` user as a non-privileged user, it may not have all the necessary privileges.
1. [dumb-init](https://github.com/Yelp/dumb-init) is worth checking out if you're
experiencing a lot of zombies Chromium processes sticking around. There's special
treatment for processes with PID=1, which makes it hard to terminate Chromium
properly in some cases (e.g. in Docker).

### Azure Pipelines

For Windows or macOS agents, no additional configuration required, just install Playwright and run your tests.

For Linux agents, refer to [our Docker setup](docker/README.md) to see additional dependencies that need to be installed.

## Travis CI
### Travis CI

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.

## CircleCI
#### Tips
- [User namespace cloning](http://man7.org/linux/man-pages/man7/user_namespaces.7.html) should be enabled to support proper sandboxing
- [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)

To sum up, your `.travis.yml` might look like this:

```yml
language: node_js
dist: bionic
addons:
apt:
packages:
# These are required to run webkit
- libwoff1
- libopus0
- libwebp6
- libwebpdemux2
- libenchant1c2a
- libgudev-1.0-0
- libsecret-1-0
- libhyphen0
- libgdk-pixbuf2.0-0
- libegl1
- libgles2
- libevent-2.1-6
- libnotify4
- libxslt1.1
- libvpx5
# This is required to run chromium
- libgbm1

# allow headful tests
before_install:
# Enable user namespace cloning
- "sysctl kernel.unprivileged_userns_clone=1"
# Launch XVFB
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
```

### CircleCI

We run our tests on CircleCI, with our [pre-built Docker image](docker/README.md). Use our [CircleCI configuration](/.circleci/config.yml) to create your own. Running Playwright smoothly on CircleCI requires the following steps:

1. Use the pre-built [Docker image](docker/README.md) in your config like so:

```yaml
docker:
- image: aslushnikov/playwright:bionic
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
```

1. If you’re using Playwright through Jest, then you may encounter an error spawning child processes:

```
[00:00.0] jest args: --e2e --spec --max-workers=36
Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:394:11)
```

This is likely caused by Jest autodetecting the number of processes on the entire machine (`36`) rather than the number allowed to your container (`2`). To fix this, set `jest --maxWorkers=2` in your test command.

### AppVeyor

We run our tests on Windows agents in AppVeyor. Use our [AppVeyor configuration](/.appveyor.yml) to create your own.

## Debugging browser launches

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.

```
DEBUG=pw:browser* npm run test
```

## Caching browsers

We run our tests on CircleCI, with our [pre-built Docker image](docker/README.md). Use our [CircleCI configuration](/.circleci/config.yml) to create your own.
By default, Playwright installs browser binaries in the following directories. This behavior can be [customized with environment variables](installation.md).

## AppVeyor
- `%USERPROFILE%\AppData\Local\ms-playwright` on Windows
- `~/Library/Caches/ms-playwright` on MacOS
- `~/.cache/ms-playwright` on Linux

We run our tests on Windows agents in AppVeyor. Use our [AppVeyor configuration](/.appveyor.yml) to create your own.
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.
17 changes: 9 additions & 8 deletions docs/core-concepts.md
Expand Up @@ -8,14 +8,15 @@ Along with a test runner Playwright can be used to automate user interactions to
validate and test web applications. The Playwright API enables this through
the following primitives.

#### Contents
- [Browser](#browser)
- [Browser contexts](#browser-contexts)
- [Pages and frames](#pages-and-frames)
- [Selectors](#selectors)
- [Auto-waiting](#auto-waiting)
- [Node.js and browser execution contexts](#nodejs-and-browser-execution-contexts)
- [Object & element handles](#object--element-handles)
<!-- GEN:toc-top-level -->
- [Browser](#browser)
- [Browser contexts](#browser-contexts)
- [Pages and frames](#pages-and-frames)
- [Selectors](#selectors)
- [Auto-waiting](#auto-waiting)
- [Node.js and browser execution contexts](#nodejs-and-browser-execution-contexts)
- [Object & element handles](#object--element-handles)
<!-- GEN:stop -->

<br/>

Expand Down
5 changes: 3 additions & 2 deletions docs/emulation.md
Expand Up @@ -9,13 +9,14 @@ Playwright allows overriding various parameters of the device where the browser

Most of these parameters are configured during the browser context construction, but some of them such as viewport size can be changed for individual pages.

#### Contents
<!-- GEN:toc-top-level -->
- [User agent](#user-agent)
- [Viewport, color scheme](#viewport-color-scheme)
- [Devices](#devices)
- [Locale & Timezone](#locale--timezone)
- [Locale & timezone](#locale--timezone)
- [Permissions](#permissions)
- [Geolocation](#geolocation)
<!-- GEN:stop -->

<br/>

Expand Down
4 changes: 2 additions & 2 deletions docs/extensibility.md
@@ -1,8 +1,8 @@
# Extensibility

#### Contents

<!-- GEN:toc-top-level -->
- [Custom selector engines](#custom-selector-engines)
<!-- GEN:stop -->

## Custom selector engines

Expand Down
3 changes: 2 additions & 1 deletion docs/input.md
@@ -1,6 +1,6 @@
# Input

#### Contents
<!-- GEN:toc-top-level -->
- [Text input](#text-input)
- [Checkboxes](#checkboxes)
- [Select options](#select-options)
Expand All @@ -9,6 +9,7 @@
- [Keys and shortcuts](#keys-and-shortcuts)
- [Upload files](#upload-files)
- [Focus element](#focus-element)
<!-- GEN:stop -->

<br/>

Expand Down
7 changes: 7 additions & 0 deletions docs/loading.md
Expand Up @@ -2,6 +2,13 @@

Playwright logically splits the process of showing a new document in the page into **navigation** and **loading**.

<!-- GEN:toc-top-level -->
- [Navigation](#navigation)
- [Loading](#loading)
- [Common scenarios](#common-scenarios)
- [Loading a popup](#loading-a-popup)
<!-- GEN:stop -->

## Navigation

Page navigation can be either initiated by the Playwright call:
Expand Down
15 changes: 8 additions & 7 deletions docs/network.md
Expand Up @@ -4,13 +4,14 @@ Playwright provides APIs to **monitor** and **modify** network traffic, both HTT
Any requests that page does, including [XHRs](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) and
[fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) requests, can be tracked, modified and handled.

#### Contents
- [HTTP Authentication](#http-authentication)
- [Handle file downloads](#handle-file-downloads)
- [Network events](#network-events)
- [Handle requests](#handle-requests)
- [Modify requests](#modify-requests)
- [Abort requests](#abort-requests)
<!-- GEN:toc-top-level -->
- [HTTP Authentication](#http-authentication)
- [Handle file downloads](#handle-file-downloads)
- [Network events](#network-events)
- [Handle requests](#handle-requests)
- [Modify requests](#modify-requests)
- [Abort requests](#abort-requests)
<!-- GEN:stop -->

<br/>

Expand Down
6 changes: 6 additions & 0 deletions docs/selectors.md
Expand Up @@ -4,6 +4,12 @@ Playwright supports multiple selector engines used to query elements in the web

Selector can be used to obtain `ElementHandle` (see [page.$()](api.md#pageselector) for example) or shortcut element operations to avoid intermediate handle (see [page.click()](api.md#pageclickselector-options) for example).

<!-- GEN:toc-top-level -->
- [Selector syntax](#selector-syntax)
- [Examples](#examples)
- [Built-in selector engines](#built-in-selector-engines)
<!-- GEN:stop -->

## Selector syntax

Selector is a string that consists of one or more clauses separated by `>>` token, e.g. `clause1 >> clause2 >> clause3`. When multiple clauses are present, next one is queried relative to the previous one's result.
Expand Down

0 comments on commit 2510edc

Please sign in to comment.