Run Parallel Tests Cases in Cypress on Real Devices with BrowserStack

Save Time & Costs by Parallel Testing in Cypress. Use BrowserStack Automate to Test on Real Devices & Browsers Effortlessly

Get Started free
Home Guide Run Cypress tests in parallel without Dashboard: Tutorial

Run Cypress tests in parallel without Dashboard: Tutorial

By Gurudatt S A, Community Contributor -

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.

Running Cypress Tests Sequentially vs in Parallel

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

  1. Test1 takes 5 minutes
  2. Test2 takes 10 minutes
  3. 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 hereFolder Structure of Cypress Tests in ParallelAnd 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 modeRunning Cypress Tests SequentiallyNow to run tests in parallel without Cypress Dashboard, We are going to use two plugins in this article

  1. cypress-parallel
  2. cypress-split

Method 1: Using cypress-parallel

You need to install the plugin cypress-parallel.Install the Cypress Parallel plugin to run Cypress Tests in Parallel without DashboardTo 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

  1. -s <npm script> – -s cypress:run( cypress:run is the npm script which exists in our package.json file)
  2. -t <number of threads>
  3. -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 Creating Parallel Weights JSON file to run Cypress Tests in Parallel without using DashboardYou 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 containersRun the specific specs of Cypress Tests in Parallel on the 2 containersBelow Github action will run all the tests in Parallel in across multiple agentsRun all Cypress tests in Parallel in across multiple agents using Cypress SplitThe 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 summary reportGithub 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.

BrowserStack Automate Banner 8

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 QuarterlyRun Stats of Cypress Parallel Test Execution without Dashboard
  • Run Duration: Provides analytics on the Average run duration, Agents used and Time saved while running in Parallel mode Run Duration of Cypress Parallel Tests during Execution without Dashboard
  • Test Suite Size: Provides analytics on the test suite added over a period of time Test Suite Size during Cypress Parallel Test Execution without Dashboard
  • Top Failures: Provides analytics about top failing test cases over period of time Test Failures during Cypress Parallel Test Execution without Dashboard
  • Slowest Tests: Provides analytics on the tests that taking more time and making execution slower over a period of time Slow running Tests during Cypress Parallel Test Execution without Dashboard
  • Most Common Errors: Provides analytics on the failing tests by grouping based on the error thrown Most common errors during Cypress Parallel Test Execution without Dashboard
  • Flaky Tests:  Provides analytics on the flaky tests based on the retry over a period of time analytics on the flaky tests

Talk to an Expert

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.

Run Cypress Tests on Real Devices

Tags
Automated UI Testing Automation Testing Cypress

Featured Articles

How to Run Cypress Tests in Parallel

Cypress Best Practices for Test Automation

Run Cypress Parallel Tests on Real Devices

User BrowserStack Automate to Save Costs & Time by Parallel Testing in Cypress on real devices & browsers