Areesha Altaf
Areesha Altaf

Reputation: 21

How to run Cypress tests in parallel using a single machine on Jenkins?

So I have around 45 spec files that I want to execute in parallel on a single machine on Jenkins.

If I create a freestyle job on Jenkins and run this command "npx cypress run --record --key abc --parallel" it executes sequentially.

Do I need to set up nodes on Jenkins, in order to do parallel execution using this command? I am not able to find how exactly I can do that and I have tried various configurations but it still runs sequentially despite the "--parallel"

How do I specify how many threads I can execute it on? Or is that decided automatically by the number of machines? In my case, I can only do this using my single machine and local Jenkins.

Creating a pipeline and passing parallel{} in the stage as mentioned here is not working either so I don't know what I'm doing wrong. Can someone please share a sample pipeline format for parallel Cypress test execution along with a guide to how nodes are created on Jenkins? Please tell me what additional steps I need to do as well. Thanks in advance

Upvotes: 2

Views: 3460

Answers (1)

agoff
agoff

Reputation: 7137

You will have to execute multiple cypress runners in order for Cypress to actually run in parallel. If you only have one npx cypress run command, then only one runner is being used.

I've found the easiest way to run multiple cypress runners is to use npm-run-all.

Assuming my script in my package.json is cypress-tests, my npm-run-all script to run the tests with three runners would be:

npm-run-all cypress-tests cypress-tests cypress-tests --parallel

Note: the --parallel flag here tells npm-run-all to run your commands in parallel. If the corresponding cypress flag is removed, your tests will not run in parallel (instead, npm-run-all will run two cypress runners in parallel, but each running your entire suite.)

Upvotes: 1

Related Questions