This directory contains a simple example of a Cypress E2E test with one test spec cypress/e2e/spec.cy.js running using the Google Chrome for Testing browser under the linux/amd64 platform.
Note that Chrome for Testing is currently not available for the linux/arm64 platform.
The example below downloads Chrome for Testing using @puppeteer/browsers.
cypress/factory also supports building a custom Docker image with Chrome for Testing using the parameter CHROME_FOR_TESTING_VERSION which must be a full version specification. This is more restrictive than the example below with @puppeteer/browsers, which has the flexibility of using a version alias, such as stable or a short version specification.
In this example we use a customized Dockerfile which bases a new image on cypress/base, copies the complete Cypress project into the image, including installed dependencies, then installs the Cypress binary and Chrome for Testing into the image.
The file is examples/chrome-for-testing/Dockerfile. It has the following contents which build a custom Docker image using the stable version of Chrome for Testing, downloaded with @puppeteer/browsers:
FROM cypress/base
COPY . /opt/app
WORKDIR /opt/app
# Install Cypress binary
RUN npx cypress install
# Install Chrome for Testing
ARG CHROME_VERSION=stable
RUN INSTALL_OUTPUT=$(npx @puppeteer/browsers install chrome@${CHROME_VERSION} --path /tmp/chrome-for-testing) && \
DOWNLOAD_DIR=$(echo "$INSTALL_OUTPUT" | grep -o '\/.*\/chrome-linux64') && \
mv $DOWNLOAD_DIR /opt/chrome-for-testing
RUN apt-get update && \
while read -r pkg; do \
apt-get satisfy -y --no-install-recommends "$pkg"; \
done < /opt/chrome-for-testing/deb.deps
RUN ln -fs /opt/chrome-for-testing/chrome /usr/local/bin/chrome
RUN rm -rf /tmp/chrome-for-testingWe build the new image, run the container from the image and execute the Cypress command npx cypress run --browser chrome-for-testing to run the test using Chrome for Testing:
cd examples/chrome-for-testing # Use a pre-configured simple Cypress E2E project
npm ci # Install all dependencies
docker build -t test-chrome-for-testing . # Build a new image
docker run --rm --entrypoint bash test-chrome-for-testing -c "npx cypress run --browser chrome-for-testing" # Run Cypress test using Chrome for TestingTo build the Docker image with a different version of Chrome for Testing, change the value of the Docker environment variable CHROME_VERSION. Any value accepted by @puppeteer/browsers is valid. This includes:
- an explicit full version e.g.
131.0.6778.204 - a major version e.g.
131 - a channel alias:
stablebetadevcanary
The value can be changed by:
-
editing the Dockerfile and replacing the version in
ARG CHROME_VERSION=or -
adding the version as a
build-argto the build command line, for example:docker build --build-arg CHROME_VERSION=beta -t test-chrome-for-testing .
Refer to Chrome for Testing availability for current versions or available downloads for other versions.
To test a set of Chrome for Testing version selections (channel alias: stable, beta, dev, canary, explicit full version & major version), execute:
cd examples/chrome-for-testing
./scripts/test.shGoogle Chrome for Testing:
Installation using