How can we run Cypress tests in parallel on a single machine? - jenkins

I need to run my tests on a single machine. The project has more than 50 tests (spec files).
Is it possible to achieve this via jenkins configuration?

You could run parallel tests in docker containers and use sorry-cypress.
https://sorry-cypress.dev/

Related

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

VueJS, run e2e tests using Cypress into a Jenkins pipeline using a docker image

I created a VueJs project with some unit tests (using Jest) and integration tests using Cypress.
I have also a Jenkins pipeline in order to build, test and deploy the application.
I Integrated, as test stage, the unit tests but I would like to integrate also Cypress in order to run the integration tests into a dedicated pipeline step.
Is is possible to have this without installing any additional Cypress Jenkins plugin?
I mean, Is it possible to use a docker image to run the tests using Cypress?
Can you point me to some examples?
You should be able to use this with Jenkins Docker capabilities. Also here is another example you can refer to.

Setup & Execution of Jmeter Distributed Test run from Jenkins

i'm looking for some assistance in execution of Jmeter distributed test runs using Jenkins hosted on Windows platform.
I need to know how to
Start Jmeter master/slave agents (jmeter-server.bat) from Jenkins machine.
how to stop the above process once the test run completes.
A hint: if you don't "stop the above process once the test run completes" you won't have to "start" them.
If you want to control everything from Jenkins you need to install Jenkins agent process on each machine you intend to use as JMeter slave, see Step by step guide to set up master and agent machines on Windows Jenkins wiki page for more details.
Once done you can create a job which will start JMeter processes using simple "Execute windows batch command" step on the agent machines
With regards to your point 2 - it's sufficient to set server.exitaftertest JMeter property to true on slave machines in any convenient way, i.e. by adding -J command-line argument like:
jmeter-server.bat -Jserver.exitaftertest=true
For any Distributed Load Run via Jmeter, the pre-requisite is to get the Jmeter-server.bat running to support and enable master-slave communications by Jmeter between Load agents. Initially i had a struggle how to get this executed as first step in Jenkins and then followed execution of Jmeter commands for load test using Remote distributed run. Hence instead of running the pre-requisite condition of running Jmeter-server.bat from jenkins i made it as a Windows service (as load agents are windows machines) which is running all time and whenever Load test starts from Jenkins, the Jmeter-server running in background which will allow distributed run to go.

JMeter: Stoptest.sh/Shutdown.sh doesn't work from Jenkins

I am running some performance tests from Jenkins. I do have two Windows machines with JMeter and I can configure from Jenkins which one to use. Everything works as expected here.
My issue: I did create another job for Stop/Shutdown the tests in case something goes wrong and you have a big run time. Whenever I try to summon Stoptest.sh/Shutdown.sh on the Windows machine that run tests, nothing happens.
How can I stop tests remotely? It has anything to do with the listening port? Thank you.
PS: Tests are ran using PSExec from Jenkin's Windows slave so there is no active CMD window on the screen.
Be aware that .sh is extension for Linux shell scripts, they cannot be executed by Windows command-line interpreter (CMD or Powershell) if you're running JMeter on Windows you need to go for shutdown.cmd or stoptest.cmd instead
There is also AutoStop Listener plugin which can be used for conditional stopping of JMeter test basing on various criteria, it can be installed using JMeter Plugins Manager

Run tests inside Docker container with Jenkins

We want to give it a try to setup CI/CD with Jenkins for our project. The project itself has Elasticsearch and PostgreSQL as runtime dependencies and Webdriver for acceptance testing.
In dev environment, everything is set up within one docker-compose.yml file and we have acceptance.sh script to run acceptance tests.
After digging documentation I found that it's potentially possible to build CI with following steps:
dockerize project
pull project from git repo
somehow pull docker-compose.yml and project Dockerfile - either:
put it in the project repo
put it in separate repo (this is how it's done now)
put somewhere on a server and jut copy it over
execute docker-compose up
project's Dockerfile will have ONBUILT section to run tests. Unit tests are run through mix tests and acceptance through scripts/acceptance.sh. It'll be cool to run them in parallel.
shutdown docker-compose, clean up containers
Because this is my first experience with Jenkins a series of questions arise:
Is this a viable strategy?
How to connect tests output with Jenkins?
How to run and shut down docker-compose?
Do we need/want to write a pipeline for that? Will we need/want pipeline when we will get to the CD on the next stage?
Thanks
Is this a viable strategy?
Yes it is. I think it would be better to include the docker-compose.yml and Dockerfile in the project repo. That way any changes are tied to the version of code that uses the changes. If it's in an external repo it becomes a lot harder to change (unless you pin the git sha somehow , like using a submodule).
project's Dockerfile will have ONBUILD section to run tests
I would avoid this. Just set a different command to run the tests in a container, not at build time.
How to connect tests output with Jenkins?
Jenkins just uses the exit status from the build steps, so as long as the test script exits with a non-zero code on failure and a zero code on success that's all you need. Test output that is printed to stdout/stderr will be visible from jenkins console.
How to run and shut down docker-compose?
I would recommend this to run Compose:
docker-compose pull # if you use images from the hub, pull the latest version
docker-compose up --build -d
In a post-build step to shutdown:
docker-compose down --volumes
Do we need/want to write a pipeline for that?
No, I think just a single job is fine. Get it working with a simple setup first, and then you can figure out what you need to split into different jobs.

Resources