Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add cypress/browsers examples #1113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion browsers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,47 @@ for example:
- `cypress/browsers:node-20.14.0-chrome-125.0.6422.141-1-ff-126.0.1-edge-125.0.2535.85-1`
- `cypress/browsers:latest`

To avoid unplanned breaking changes, specify a fixed `<node version>` & `<browser version>` combination tag, not the `latest` tag. The `latest` tag is linked to the latest released `cypress/browsers` image and is updated without notice.
To avoid unplanned breaking changes, specify a fixed `<node version>` & `<browser version>` combination tag, not the `latest` tag. The `latest` tag is linked to the latest released `cypress/browsers` image and is updated without notice.

## CMD

When running a container from a `cypress/browsers` image, `bash` is executed, as defined by the [CMD](https://docs.docker.com/reference/dockerfile/#cmd) parameter of the image.

### Docker interactive

In this example we first run the unchanged image `cypress/browsers` as a container:

```shell
cd examples/basic # Use a pre-configured simple Cypress E2E project
npm ci # Install Cypress
docker run -it --rm -v .:/e2e -w /e2e cypress/browsers # Run image as container
```

At the `bash` prompt `:/e2e#`, we can then enter the following commands:

```shell
npx cypress install # Install Cypress binary into running Docker container
npx cypress run -b chrome # Run Cypress test in Chrome
```

### Docker build and run

In this example we use a customized `Dockerfile` which bases a new image on `cypress/browsers`, copies the complete Cypress project into the image, including installed dependencies, then installs the Cypress binary.

The file is [examples/basic/Dockerfile.browsers](../examples/basic/Dockerfile.browsers) and it has the following contents:

```dockerfile
FROM cypress/browsers
COPY . /opt/app
WORKDIR /opt/app
RUN npx cypress install # Install Cypress binary into image
```

We build the new image, run the container from the image and execute the Cypress command `npx cypress run -b chrome` to run the test using the Chrome browser:

```shell
cd examples/basic # Use a pre-configured simple Cypress E2E project
npm ci # Install Cypress
docker build . -f Dockerfile.browsers -t test-browsers # Build a new image
docker run -it --rm --entrypoint bash test-browsers -c "npx cypress run -b chrome" # Run Cypress test in container using Chrome
```
4 changes: 4 additions & 0 deletions examples/basic/Dockerfile.browsers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM cypress/browsers
COPY . /opt/app
WORKDIR /opt/app
RUN npx cypress install # Install Cypress binary into image