Cypress Parallelization
Detailed guide to Cypress Tests Parallelization
Last updated
Detailed guide to Cypress Tests Parallelization
Last updated
As your Cypress Tests suite grows, it becomes crucial to optimizing the overall duration in order to get faster feedback. Once your cypress tests suite volume passed 10 spec files, you'd start looking for solutions to run the tests in parallel.
Parallelization is the most popular technique for reducing the duration of your cypress tests. One of the most convenient and easy solutions is to use cloud services like Currents or Cypress Dashboard.
Those services integrate with your CI provider and use intelligent techniques to parallelize the tests, reduce overall duration, as well as provide features like storing video and screenshot recording, test outputs, and providing analytics and integration with 3rd party tools.
Running cypress tests in parallel in CI environment involves creating multiple containers. Depending on the size of your browser test suite, it can be dozens or hundreds of containers.
Containers use Currents cloud service to get instructions about tests (technically, spec files) to run - every test runs in a different container. Currents uses intelligent orchestration heuristics to optimally distribute the tests between containers and reduce overall runtime.
The simplistic animation below demonstrates the parallelization of 6 spec files using 3 containers.
Each container runs an identical cypress
or cypress-cloud
command with --parallel
flag
Each container connects to Currents dashboard to get instructions about the next spec file to run
Currents dashboard assigns each container a spec file
Each container runs its spec file
Each container sends the results back to Currents and gets the next spec file to run
When no more spec files are left, containers finish their execution
Yes. You still need CI machines that will run the actual tests. Currents Dashboard (and other orchestration services) will load-balance the tests between the machines and will record test results to allow troubleshooting of your cypress tests.
Yes! You don't have to have different machines/containers for running cypress tests in parallel.
You can run multiple cypress-cloud
/ cypress
instances on the same machine. Keep in mind that cypress tests are quite resource-demanding - running too many instances of a test runner can actually slow down the overall execution or even crash the machine.
Running cypress tests in parallel on localhost requires running two or more cypress runners at the same time. Open two separate terminals and run an identical cypress-cloud command with --parallel
flag --ci-build-id
flag with identical value:
You will see that two runners are executing different spec files and running in parallel.
You don't need to split files manually when using Cypress / Currents or Sorry Cypress dashboard service - the service does that for you automatically and distributes the spec files between cypress runners.
Moreover, Currents dashboard uses historical data to optimally sort the spec files in order to reduce the overall build / run duration.
Any CI provider or tool that allows creating multiple containers/jobs can be integrated with Currents for running cypress tests in parallel. See section for details.
Here are a few popular CI providers that can run cypress tests in parallel:
To run cypress tests in parallel and use Currents as an orchestration service, run this command:
Read more about the importance of CI Build ID. You can generate currents_key
by creating an organization and a project on Currents Dashboard.
Currents uses --ci-build-id
flag to uniquely identify one parallelized build from another.
The value of this flag is calculated automatically for popular CI tools, but you can also provide it explicitly. See CI Build ID for details.