Continuous Integration with Cypress
Cypress runs in any continuous integration (CI) provider, including GitHub Actions, CircleCI, GitLab CI, Jenkins, and AWS CodeBuild. Running your Cypress tests on every push and pull request catches regressions before they reach your users, and recorded results show you exactly what happened when a test fails.
Setting it up takes two commands: install Cypress, then run it. This guide covers those commands and everything around them: booting your app's server, choosing a Docker image, caching, parallelization, and setup guides for each major CI provider.
What you'll learn
- How to install and run Cypress in any CI provider
- How to start your app's server before running tests
- How to record results to Cypress Cloud and run tests in parallel
- How to pick a Cypress Docker image for a consistent test environment
- How to configure machine resources, caching, and environment variables
- How to troubleshoot common CI failures
What is Continuous Integration?​
Continuous integration is the practice of merging code changes into a shared repository frequently, where each change is verified by an automated build and test run. When Cypress is part of that pipeline, every commit runs your end-to-end and component tests against your application, so a change that breaks a user flow fails the build instead of shipping.
Setting up CI​
Install and run Cypress​
Running Cypress in CI is almost the same as running it locally in your terminal. You generally only need to do two things:
- Install Cypress
- npm
- Yarn
- pnpm
- Bun
npm install cypress --save-dev
yarn add cypress --dev
pnpm add --save-dev cypress
bun add --dev cypress
- Run Cypress
- npm
- Yarn
- pnpm
- Bun
npx cypress run
yarn cypress run
pnpm cypress run
bunx cypress run
Where these commands go depends on your CI provider: each defines its own configuration file format for the steps in a build. Refer to your CI provider's documentation for where to add the commands to install and run Cypress, or start from one of our CI examples.
Boot your server​
Typically you will need to boot a local server before running Cypress. A web server is a long running process that never exits, so you need to run it in the background or your CI provider will never move on to the next command. You also need to wait for the server to be ready before Cypress starts. A command like this has a race condition:
npm start & npx cypress run # don't do this
There is no guarantee that your server has booted by the time cypress run
executes, so your tests may try to visit your local server before it is ready.
Instead of adding an arbitrary wait (like sleep 20), use a tool that waits
for the server to respond.
If you run your tests with the official
Cypress GitHub Action, its
start and wait-on options boot and wait for your server without any extra
packages. See our
GitHub Actions guide.
start-server-and-test module​
The start-server-and-test module starts your server, waits until a URL responds, runs your test command, and shuts the server down when the tests finish.
- npm
- Yarn
- pnpm
- Bun
npm install start-server-and-test --save-dev
yarn add start-server-and-test --dev
pnpm add --save-dev start-server-and-test
bun add --dev start-server-and-test
In your package.json scripts, pass the command that boots your server, the
URL your server is hosted on, and your Cypress test command.
{
"scripts": {
"start": "my-server -p 3030",
"cy:run": "cypress run",
"test": "start-server-and-test start http://localhost:3030 cy:run"
}
}
In the example above, the cy:run command will only be executed when the URL
http://localhost:3030 responds with an HTTP status code of 200. The server
also shuts down when the tests complete.
Gotchas
When
working with webpack-dev-server
or another server that does not respond to HEAD requests, use an explicit
GET method to ping the server like this:
{
"scripts": {
"test": "start-server-and-test start http-get://localhost:3030 cy:run"
}
}
When working with local https in webpack, set a system environment variable
to allow the local certificate:
{
"scripts": {
"start": "my-server -p 3030 --https",
"cy:run": "cypress run",
"cy:ci": "START_SERVER_AND_TEST_INSECURE=1 start-server-and-test start https-get://localhost:3030 cy:run"
}
}
wait-on module​
If you'd rather manage the server process yourself, the wait-on module blocks until a URL responds. Background the server, wait for it, then run Cypress:
npm start & npx wait-on http://localhost:8080
npx cypress run
Most CI providers automatically kill background processes, so you don't have to worry about cleaning up your server process once Cypress finishes.
However, if you're running this script locally you'll have to do a bit more
work to collect the backgrounded PID and then kill it after cypress run.
concurrently module​
A general-purpose process runner like
concurrently can compose the
same flow: start the server and a wait-on-gated test command together, kill
the server when the tests finish (-k), and pass or fail based on the test
command alone (-s first).
npx concurrently -k -s first "npm start" "npx wait-on http://localhost:8080 && npx cypress run"
Record tests​
Cypress can record your test runs and make the results available in Cypress Cloud, giving you insight into what happened when your tests ran in CI.
Recording tests allows you to:
- See the number of failed, pending, and passing tests.
- Debug failures with Test Replay, which captures the state of your application so you can inspect the DOM, network requests, and console logs at every step of the failed test.
- Get the entire stack trace of failed tests, or hand that same failure context to your AI coding agent through Cypress Cloud MCP so it can debug the failing run for you.
- View screenshots taken when tests fail and when using
cy.screenshot(). - Detect and manage flaky tests that pass and fail across recorded runs.
- Analyze trends in your test suite with Analytics, like run duration, most common errors, and slowest tests.
- Generate UI Coverage and Cypress Accessibility reports from your recorded runs with no additional test code or configuration (premium solutions).
- See which machines ran each test when parallelized.
To record tests:
- Set up your project to record and copy your record key.
- Pass the
--recordflag tocypress runwithin CI, along with the record key, either inline with the--keyflag or via theCYPRESS_RECORD_KEYenvironment variable.
- npm
- Yarn
- pnpm
- Bun
npx cypress run --record --key=abc123
yarn cypress run --record --key=abc123
pnpm cypress run --record --key=abc123
bunx cypress run --record --key=abc123
Read the full guide on Cypress Cloud.
Run tests in parallel​
Cypress can run tests in parallel across multiple machines, cutting your total run time roughly in proportion to the number of machines.
You'll want to refer to your CI provider's documentation on how to set up multiple machines to run in your CI environment.
Once multiple machines are available within your CI environment, you can pass the --parallel flag to have your tests run in parallel. Parallelization requires recording to Cypress Cloud, which load-balances specs across your machines.
- npm
- Yarn
- pnpm
- Bun
npx cypress run --record --key=abc123 --parallel
yarn cypress run --record --key=abc123 --parallel
pnpm cypress run --record --key=abc123 --parallel
bunx cypress run --record --key=abc123 --parallel
Read the full guide on parallelization.
Cypress Docker Images​
CI providers, such as GitHub Actions and CircleCI, allow workflows to run using Docker container images.
Cypress supports the use of Docker through the provisioning of official Cypress Docker images. Images are Linux-based and support the following platforms:
- Linux/amd64
- Linux/arm64
Cypress Docker images provide a consistent environment tailored for use with Cypress. By choosing an appropriate Cypress Docker image, you determine the exact environment that your Cypress tests run in. This shields your workflows from version updates made by your CI provider, for instance if they update Node.js or browser versions.
Cypress Docker images are available from:
Cypress Docker variants​
-
cypress/base is the entry-level Cypress Docker image, allowing you to test in the Electron browser, built in to Cypress. It contains a complete Linux (Debian) operating system, together with the prerequisite operating system packages for Cypress, Node.js, npm and Yarn v1 Classic. An image
<tag>gives you the choice of Node.js version. -
cypress/browsers builds on the cypress/base image. For
Linux/amd64images it adds Chrome, Firefox and Edge browsers. ForLinux/arm64images it adds only Firefox browsers from version136and above. Chrome and Edge browsers are currently not available forLinux/arm64. A corresponding image<tag>allows selection of the combined Node.js and browser versions. The version tags for the unavailable Chrome and Edge browsers on theLinux/arm64platform are empty place-holders only, required for multi-platform support compatibility. -
cypress/included builds on the cypress/browsers image. It adds a fixed version of Cypress, globally installed by npm. A short-form image
<tag>selects the version of Cypress. A corresponding long-form<tag>selects the version of Cypress and documents the combined Node.js and browser versions. -
cypress/factory provides the base operating system image and allows individual selection of other components by version. It is used to generate customized Docker images.
CI Docker examples​
You can find examples that use Cypress Docker images below:
- cypress-docker-images examples
- cypress-example-kitchensink
- Real World App - CircleCI
- Real World App - GitHub Actions
- cypress-docker-images - GitHub Actions
CI Examples​
We maintain in-depth setup guides for the most popular CI providers, and working example configurations for many others.
AWS Amplify Console​
AWS CodeBuild​
Read our extensive guide on how to set up Cypress in AWS CodeBuild.
Azure Pipelines​
Bitbucket Pipelines​
Read our extensive guide on how to set up Cypress in Bitbucket Pipelines.
Buildkite​
CircleCI​
Read our extensive guide on how to set up Cypress in CircleCI.
GitHub Actions​
Read our extensive guide on how to set up Cypress in GitHub Actions.
GitLab​
Read our extensive guide on how to set up Cypress in GitLab.
Jenkins​
Netlify​
Use our official netlify-plugin-cypress to execute end-to-end tests before and after deployment to the Netlify platform.
Semaphore​
TravisCI​
Advanced setup​
Machine requirements​
Hardware requirements to run Cypress depend on how much memory the browser, the application under test, and the server (if running it locally) need to run the tests without crashing. Visit our System Requirements guide for minimum hardware recommendations.
Some signs that your machine may not have enough CPU or memory to run Cypress:
- The recorded video artifacts have random pauses or dropped frames.
- Debug logs of the CPU and memory frequently show CPU percent above 100%.
- The browser crashes.
You can see the total available machine memory and the current free memory by
running the cypress info
command.
npx cypress info
...
Cypress Version: 15.18.1 (stable)
System Platform: linux (Debian - 12)
System Memory: 73.6 GB free 48.6 GB
You can see the CPU parameters on the CI machines by executing the command below.
node -p 'os.cpus()'
[
{
model: 'Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz',
speed: 3399,
times: { user: 760580, nice: 1010, sys: 158130, idle: 1638340, irq: 0 }
}
...
]
Example projects and the machine configurations used to run them on CI:
- The Real World App
project runs tests on a CircleCI machine using the
Docker executor with
resource_class: largeproviding 4 vCPUs and 8 GB of RAM.cypress inforeportsSystem Memory: 73.6 GB free 48.6 GB. - The Real World App project also
executes its tests on
GitHub Actions using the
Cypress GitHub Action with the
standard Ubuntu GitHub-hosted runner for Public repositories
providing 4 vCPUs and 16 GB of RAM.
cypress inforeportsSystem Memory: 16.8 GB free 15.5 GBwith CPUs reported asAMD EPYC 7763 64-Core Processor.
Tip: if there are problems with longer specs, try splitting them into shorter ones.
Dependencies​
Cypress runs on many CI providers' virtual machine environments out-of-the-box without needing additional dependencies installed.
Linux​
If you see a message about a missing dependency when you run Cypress in a Linux CI environment, then refer to the Linux Prerequisites lists for guidance.
Caching​
Cypress downloads its binary to the global system cache - on Linux that is
~/.cache/Cypress. By ensuring this cache persists across builds you can save
minutes off install time by preventing a large binary download.
We recommend that you:
-
Cache the
~/.cachefolder after runningnpm install,yarn,npm cior equivalents as demonstrated in the configs below. -
Do not cache
node_modulesacross builds. Instead, cache the package manager's own cache directory (~/.npmfor npm or~/.cache/yarnfor yarn). These tools maintain package-level caches that track installed versions, validate integrity, and only re-download packages that have changed. Cachingnode_modulesdirectly bypasses these built-in mechanisms and can cause issues such as Cypress not downloading the Cypress binary onnpm install. -
If you are using
npm installin your build process, consider switching tonpm ciand caching the~/.npmdirectory for a faster and more reliable build. -
If you are using
yarn, caching~/.cachewill include both theyarnand Cypress caches. Consider usingyarn install --frozen-lockfileas annpm ciequivalent. -
If you need to override the binary location for some reason, use the CYPRESS_CACHE_FOLDER environment variable.
-
Make sure you are not restoring the previous cache using lax keys; then the Cypress binaries can "snowball", accumulating every version you have ever installed.
Tip: you can find lots of CI examples with configured caching in our cypress-example-kitchensink repository.
Environment variables​
You can set various environment variables to modify how Cypress runs.
Configuration Values​
You can set any configuration value as an
environment variable by prefixing it with CYPRESS_. This overrides values in
the Cypress configuration.
Typical use cases would be modifying things like:
CYPRESS_BASE_URL- point tests at a preview or staging deploymentCYPRESS_REPORTER- switch to a CI-friendly reporter likejunitCYPRESS_DEFAULT_COMMAND_TIMEOUT- allow more time on slower CI machinesCYPRESS_VIEWPORT_WIDTHandCYPRESS_VIEWPORT_HEIGHT- vary the screen size per CI job
The install-time variable
CYPRESS_INSTALL_BINARY
is also commonly set in CI, to skip or redirect the binary download.
Refer to the Environment Variables recipe for more examples.
Record Key
If you are recording your runs on a public project, you'll want to protect your Record Key. Learn why.
Instead of hard coding it into your run command like this:
- npm
- Yarn
- pnpm
- Bun
npx cypress run --record --key abc-key-123
yarn cypress run --record --key abc-key-123
pnpm cypress run --record --key abc-key-123
bunx cypress run --record --key abc-key-123
You can set the record key as the environment variable CYPRESS_RECORD_KEY
and we'll automatically use that value. You can now omit the --key flag when
recording.
- npm
- Yarn
- pnpm
- Bun
npx cypress run --record
yarn cypress run --record
pnpm cypress run --record
bunx cypress run --record
Set CYPRESS_RECORD_KEY in your CI provider's settings as a secret or masked
environment variable so it doesn't appear in your configuration files or build
logs.
CYPRESS_RECORD_KEY must be set as an actual operating system environment
variable (for example via export CYPRESS_RECORD_KEY=... or your CI provider's
secrets). Cypress reads it directly from your shell or CI environment — it is
not read from cypress.env.json or the env block of your Cypress
configuration, since those only populate test environment variables. If you
don't want to set an environment variable, pass the key inline with the --key
flag instead.
Git information​
Cypress assumes there is a .git folder and uses Git commands to get each property,
like git show -s --pretty=%B to get the commit message.
Under some environment setups (e.g. docker/docker-compose) if the .git
directory is not available or mounted, you can pass all git related information
under custom system environment variables.
- Branch:
COMMIT_INFO_BRANCH - Message:
COMMIT_INFO_MESSAGE - Author email:
COMMIT_INFO_EMAIL - Author:
COMMIT_INFO_AUTHOR - SHA:
COMMIT_INFO_SHA - Remote:
COMMIT_INFO_REMOTE
If the commit information is missing in the Cypress Cloud run then
GitHub Integration or other
tasks might not work correctly. To see the relevant Cypress debug logs, set the
system environment variable DEBUG on your CI machine and inspect the terminal output
to see why the commit information is unavailable.
DEBUG=cypress:server:record
CI Build Information​
In some newer CI providers, Cypress can't map the system environment variables required to link back to builds or pull requests. In this case we provide users some environment variables to help pass that information along.
- Pull Request Id:
CYPRESS_PULL_REQUEST_ID - Pull Request URL:
CYPRESS_PULL_REQUEST_URL - Build URL:
CYPRESS_CI_BUILD_URL
Setting these will allow links within the Cloud run to take you to the appropriate place.
Custom Environment Variables​
You can also set custom values for use in your tests. Which API you use depends on whether the value is sensitive.
Private values: cy.env()
For secrets like API tokens, set an OS environment variable prefixed with
CYPRESS_ using your CI provider's secret or masked variable settings:
export CYPRESS_SERVICE_API_TOKEN=secret-token-123
Cypress strips the prefix, and your tests read the value with
cy.env(), which retrieves only the values you request
without serializing them into browser state:
cy.env(['SERVICE_API_TOKEN']).then(({ SERVICE_API_TOKEN }) => {
cy.request({
url: 'https://api.example.com/users',
headers: { Authorization: `Bearer ${SERVICE_API_TOKEN}` },
})
})
Public values: Cypress.expose()
For non-sensitive configuration that is safe to appear in browser state, like
feature flags or API versions, pass values with the --expose CLI flag:
- npm
- Yarn
- pnpm
- Bun
npx cypress run --expose apiVersion=v2,featureFlag=true
yarn cypress run --expose apiVersion=v2,featureFlag=true
pnpm cypress run --expose apiVersion=v2,featureFlag=true
bunx cypress run --expose apiVersion=v2,featureFlag=true
and read them synchronously with
Cypress.expose():
const apiVersion = Cypress.expose('apiVersion') // => 'v2'
Refer to the dedicated Environment Variables & Secrets guide for more examples.
Module API​
Oftentimes it can be less complex to programmatically control and boot your servers with a Node script.
If you're using our Module API then you can write a script that boots and then shuts down the server later. As a bonus, you can work with the results and do other things.
const cypress = require('cypress')
const server = require('./lib/my-server')
;(async () => {
await server.start()
// kick off a cypress run
const results = await cypress.run()
// stop your server when it's complete
await server.stop()
})()
node scripts/run-cypress-tests.js
Common problems and solutions​
Missing binary​
When npm or yarn install the cypress package, a postinstall hook is executed
that downloads the platform-specific Cypress binary. If the hook is skipped for
any reason the Cypress binary will be missing (unless it was already cached).
To better diagnose the error, add commands to get information about the Cypress cache to your CI setup. This will print where the binary is located and what versions are already present.
- npm
- Yarn
- pnpm
- Bun
npx cypress cache path
npx cypress cache list
yarn cypress cache path
yarn cypress cache list
pnpm cypress cache path
pnpm cypress cache list
bunx cypress cache path
bunx cypress cache list
If the required binary version is not found in the cache, you can try the following:
- Clean your CI's cache using your CI's settings to force a clean
npm installon the next build. - Run the binary install yourself by adding the command
npx cypress installto your CI script. If there is a binary already present, it should finish quickly.
Xvfb​
When running on Linux, Cypress needs an X11 server; otherwise it spawns its own
X11 server during the test run. When running several Cypress instances in
parallel, the spawning of multiple X11 servers at once can cause problems for
some of them. In this case, you can separately start a single X11 server and
pass the server's address to each Cypress instance using the DISPLAY
variable.
First, spawn the X11 server in the background at some port, for example :99.
If you have installed xvfb on Linux or if you are using one of our Docker
images from
cypress-docker-images,
the tools below should be available.
Xvfb :99 &
Second, set the X11 address in a system environment variable
export DISPLAY=:99
Start Cypress as usual
- npm
- Yarn
- pnpm
- Bun
npx cypress run
yarn cypress run
pnpm cypress run
bunx cypress run
After all tests across all Cypress instances finish, kill the Xvfb background
process using pkill
pkill Xvfb
In certain Linux environments, you may experience connection errors with your X11 server. In this case, you may need to start Xvfb with the following command:
Xvfb -screen 0 1024x768x24 :99 &
Cypress internally passes these Xvfb arguments, but if you are spawning your own Xvfb, you would need to pass these arguments. This is necessary to avoid using 8-bit color depth with Xvfb, which will prevent Chrome or Electron from crashing.
Colors​
If you want colors to be disabled, you can pass the NO_COLOR environment
variable to disable colors. You may want to do this if ASCII characters or
colors are not properly formatted in your CI.
NO_COLOR=1 cypress run
See also​
- Cypress Real World App runs parallelized CI jobs across multiple operating systems, browsers, and viewport sizes.
- cypress-example-kitchensink is set up to run on multiple CI providers.
- Command Line - all
cypress runflags and options - Test Replay
- Cross Browser Testing Guide