Run Cypress tests in parallel without Dashboard: Tutorial
By Gurudatt S A, Community Contributor - March 15, 2023
What is Cypress Parallelization?
Tests built using Cypress run very fast and in any real time project the tests grow from 100s to 1000s. If you run the test in sequential manner (1 at a time), no matter how fast the test execution in Cypress is, it is still going to take a good amount of time.
Cypress provides a feature to run tests in Parallel in CI runs using the Cypress Cloud. To use this feature, users should enable Cypress Cloud Integration with our Project and set the flag –parallel in the cypress execution command.
The Cypress parallel in built feature requires Multiple agents configured in CI run and Cypress balances the load based on the agents and number of spec files.
Why is it important to run Cypress Tests in Parallel
To speed up the tests you need to run our tests in Parallel. Parallelization refers to executing multiple tests at any given time.
Taking example of three tests
- Test1 takes 5 minutes
- Test2 takes 10 minutes
- Test3 takes 5 minutes
When executing these tests in Sequential mode it will take 20 minutes. But if you run these three tests in parallel it will average to 10 minutes (It saved 10 minutes!).
How to run Cypress Tests in Parallel without Dashboard
Before trying to run tests in Parallel without Dashboard, lets run the three tests which can be found hereAnd if you execute below command in command line, three tests will be run against Browser Stack’s Demo application
npx cypress run --spec "cypress/e2e/dropdown-examples/*.js"
It is taking 29 Seconds for executing three tests in Sequential modeNow to run tests in parallel without Cypress Dashboard, We are going to use two plugins in this article
- cypress-parallel
- cypress-split
Method 1: Using cypress-parallel
You need to install the plugin cypress-parallel.To install this plugin run the below command from root of your project
npm i cypress-parallel
Once the plugin is installed, all you need to do is execute below command
npx cypress-parallel -s cypress:run -t 3 -d "cypress/e2e/dropdown-examples/*.js"
In the above command, using cypress-parallel plugin to execute cypress tests. This command contains three parts
- -s <npm script> – -s cypress:run( cypress:run is the npm script which exists in our package.json file)
- -t <number of threads>
- -d <spec file path>
Executing the above command will create a parallel-weights.json file and the spec files are divided based on this file and run in parallel based on the thread number provided You need to ensure that the thread number provided should be based on the agent’s Hardware capacity.
Run Cypress Parallel Tests on Real Devices
Method 2: Using cypress-split
You can use this plugin to run the cypress tests parallel in CI builds.
Installation instruction can be found here
With this plugin you can run specific tests across multiple containers or you can run with multiple agents
Below Github action will run the specific specs in Parallel on the 2 containersBelow Github action will run all the tests in Parallel in across multiple agentsThe working example of Github actions can be found here
Once the Github action is executed as part of CI build, it will produce a summary report like belowGithub link for the above summary report can be found here
Run Cypress Tests on Real Devices
Benefits of Cypress Parallelization without Cypress Cloud
By using the two plugins as discussed above, you can run tests in Parallel without purchasing paid plans in Cypress Cloud.
You can also configure whether to run these tests in parallel across multiple agents or within a single agent with multiple containers.
Read More: Cypress Best Practices for Test Automation
Limitations of Cypress Parallel Execution without Cypress Cloud
Cypress cloud offers helpful Analytics, such as
- Runs Status: Users can filter the Run status by Branch, Tag, No of Days, Group by Daily, Weekly, Monthly and Quarterly
- Run Duration: Provides analytics on the Average run duration, Agents used and Time saved while running in Parallel mode
- Test Suite Size: Provides analytics on the test suite added over a period of time
- Top Failures: Provides analytics about top failing test cases over period of time
- Slowest Tests: Provides analytics on the tests that taking more time and making execution slower over a period of time
- Most Common Errors: Provides analytics on the failing tests by grouping based on the error thrown
- Flaky Tests: Provides analytics on the flaky tests based on the retry over a period of time
Conclusion
This article highlighted what is Parallel execution, How to achieve the Parallel Cypress tests execution by using plugins without using dashboard and also the limitations of not Using Cypress Cloud for Parallel execution.
Post Test Execution Analytics is critical to understand the run duration, tests performance and errors and this feature is available in Cypress Cloud which will benefit the projects tremendously.
Whenever running Cypress tests, it is recommended to test on real devices so that the real user conditions can be taken into account for better accuracy of test results. Tools like BrowserStack Automate help QAs by providing access to 3000+ device browser combinations for a comprehensive automated testing.