1

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

1 Answers1

1

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.)

agoff
  • 5,818
  • 1
  • 7
  • 20
  • Thanks, but then how do I specify how many runners/threads I want? Means how will I tell that I want the tests to be divided in 2 or 3 or 4 for parallel? – Areesha Altaf Sep 12 '22 at 17:34
  • You have to specifically start the runners. Cypress does not control _how_ many runners you have running, only orchestrating what tests each runner gets. I'll update my answer to be clearer. – agoff Sep 12 '22 at 17:36
  • I tried this, but it didn't work for me. It's executing the files in sequential manner – Areesha Altaf Sep 12 '22 at 18:22
  • Do you have a cypress director that is controlling the execution? Running Cypress in parallel requires a director to assign out tests for each runner to execute. By default, this is your Cypress dashboard account. – agoff Sep 12 '22 at 19:34