QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › CI, parallelization, reports

Which Cypress Docker images to use in CI?

Cypress has four families of official images: base, browsers, included and factory. The cypress/base image has no browsers, cypress/browsers adds Chrome, Firefox and Edge (the project controls the Cypress version), cypress/included has a fixed Cypress version, and cypress/factory builds a custom combination. The tag is pinned, because a short tag with a Node version can be updated without notice and the browser would change between runs.

Cypress · CI

The same test behaves differently in CI and locally. Could the browser in the image be to blame?

A test is green on a laptop and red in CI, and the only difference is the Chrome version or system libraries. The image the run happens in is part of the test environment, and choosing it decides whether it is reproducible. The lesson covers which official Cypress images exist, how they differ and how to pin them.

How it works and why. Cypress supports four families of official images: three ready-made ones are built on each other, and the fourth builds an image for your own versions. All of them remove the work of installing browsers and system libraries that you would otherwise write in every pipeline. The difference is what is already inside and who is responsible for the Cypress version.

Images built on each other

cypress/baseNode + system dependenciescypress/browsers+ Chrome, Firefox, Edgecypress/included+ Cypress globally, a fixed version
Figure 1. Each level adds a layer: from Node to a ready Cypress. cypress/factory stands apart and is built from your versions.
ImageWhat is insideWhen to take it
cypress/baseNode and system dependencies, no browsersBuilt-in Electron or your own browsers
cypress/browsers+ Chrome, Firefox, Edge; Cypress from the projectThe Cypress version is led by package.json
cypress/included+ Cypress of a fixed version, globallyA ready image with no package installation
cypress/factoryA base OS, you choose the versionsYour own combination of Node, Cypress and browsers

cypress/base has no browsers, so it fits the built-in Electron (deprecated as a test browser in Cypress 16) or cases where the browser is installed separately. cypress/browsers adds Chrome, Firefox and Edge (for Linux/amd64), and Cypress is installed from the project through npm ci, so the version is set by package.json. cypress/included has a fixed Cypress version installed globally: the project does not need to install the package, but the version in the image and the version in the project can drift apart.

Example: an image in GitHub Actions. The image is set by the container field in the job. This works only on Linux runners. The container runs as root by default; the documentation advises options: --user 1001 to avoid permission problems (as root in GitHub Actions Firefox fails: Cypress does not detect versions below 138, and 138 and later hang):

jobs:
  cypress:
    runs-on: ubuntu-latest
    container:
      image: cypress/browsers:24.22.1
      options: --user 1001
    steps:
      - uses: actions/checkout@v7
      - uses: cypress-io/github-action@v7

In GitLab CI the image is set with the image: key, in Jenkins with a Docker agent in the Jenkinsfile. The same image can be started locally to reproduce a CI failure:

# reproduce the run locally in the same image
docker run -it -v $PWD:/e2e -w /e2e cypress/included:<tag>

Limits and alternatives. Pin the image tag. A short tag with the Node version (cypress/browsers:24.22.1) can be updated without warning, so to keep the browser from changing between runs, take a frozen tag with browser versions of the form node-…-chrome-…-ff-…-edge-…. A single image for all parallel jobs aligns the browser versions. An image with browsers is large, and downloading it is part of the run time, so on self-hosted runners it is cached. Alternatives to images: install browsers yourself on the runner (slower and less reproducible) or build your own image through cypress/factory when a non-standard combination is needed. In Playwright the same approach is provided by the official image mcr.microsoft.com/playwright.

Typical mistakes.

  • Taking the latest tag or a short Node tag: the browser changes between runs and a test suddenly fails with no code change.
  • Taking cypress/included and also installing the package in the project: the versions drift apart and it is unclear which one runs.
  • Using container on a Windows or macOS runner in GitHub Actions: it is supported only on Linux.
  • Leaving root in the container unchecked: some tools and older browsers behave differently as root.

Check yourself

A test suddenly started failing in CI with no code change, and the workflow image is cypress/browsers:24.22.1. Which cause do you check first?

Answer

The short tag may have been updated without warning, so the browser version changed. Pin a frozen tag with the Node, Chrome, Firefox and Edge versions and compare the browser version in the logs of the two runs.

How does cypress/browsers differ from cypress/included regarding the Cypress version?

Answer

In browsers Cypress is installed from the project through npm ci, so package.json sets the version. In included a fixed version is already installed globally and it may drift from the version in the project.

In the interview. Junior: I take cypress/browsers when Chrome or Firefox is needed and the project leads the Cypress version, and cypress/included if I want an image with Cypress already installed. cypress/base has no browsers. Middle/Senior: I take a frozen tag with browser versions so the browser does not change between runs, and one image for all parallel jobs. In Actions that is container on Linux only, with --user 1001. I run the same image locally to reproduce a failure.

More articles in this chapter