Running Cypress Tests in Parallel using GitHub Actions [shorts]
In the previous article "Running Cypress Tests in GitHub Actions (Part 10)" of the Cypress-TestFramework article series, we saw how we can leverage Github to run our tests in a docker container within GitHub Actions CI/CD. In this #shorts article, we'll see about how to speed up the overall speed of Test Execution.
What is Test Execution Parallelization?
When we run our Tests one after another it takes a certain amount of time to complete those tests in a sequential manner. As a good practice in Test Automation:
A single test's execution shouldn't be dependent on the other tests' execution/s
Keeping this principle in mind we can ideally delegate running tests to different machines provided by CI/CD offering; hence considerably reducing the test execution time.
Here's a good article on Parallelization with Cypress:
Cypress.io supports running parallel tests on a number of CI/CD providers. All we need is CI/CD provider configured to spin up multiple machines on demand.
All Cypress needs is passing --parallel flag along with the run command
That's about it.
Configuring GitHub Actions to support Parallelization:
You can directly clone this repo and use the following main.yml workflow file.
In our Workflow file in GitHub Actions, we just need to configure how many machines we need and how to pass --parallel flag to Cypress.
this strategy matrix is the key here for spinning up new machines
strategy:
matrix:
job: [0, 1, 2, 3]
Here's a nice article on how to better leverage Github Action's strategy matrix:
Once done another thing I did is create a new script inside the package.json which has a --parallel flag
...
"scripts": {
...
"cy:record:parallel:qa": "node runner.js cypress run --env TAGS=\"@API\" configFile=qa --record --parallel --key YOUR_KEY_HERE --tag \"release,v1.10\""
...
Now once you commit these changes you should see CI/CD workflow in action.
Sample run:
https://github.com/far11ven/Cypress-TestFramework/actions/runs/2144385546
Cypress-Dashboard result:
We can see 4 Specs present in the source repo were distributed among 3 different job/machines
Ciao!!
GitHub Repo:
https://github.com/far11ven/Cypress-TestFramework