Cypress: Parametrized build execution with Jenkins

Reading Time: 3 minutes

Hello everyone, in my previous blog we discussed how we can integrate our cypress tests with Jenkins. In this blog, we will discuss how we can parametrized build execution with Jenkins.

In Cypress, we can parameterize our tests, with the help of scripts.
For achieving parameterization in cypress we can add scripts in our package.json file with all the required commands.

We can use following script for reference

{
  "name": "CypressTestDemo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "keywords": [],
  "scripts": {
    "test": "npx cypress run",
    "headedTest":"npm run test --headed",
    "chromeTest":"npm run test --browser chrome",
    "recordDashboardReport":"npm run test --record --key b01d0016-e848-4141-abb9-a8ae5e7be6af"
  },
    "author": "",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^4.7.0",
    "mocha": "7.2.0",
    "mochawesome": "6.1.1",
    "mochawesome-merge": "4.1.0",
    "mochawesome-report-generator": "5.1.0"
  },
  "dependencies": {
    "mocha": "7.2.0"
  }
}

As here we can see that, we have defined “test” as npx cypress run. This command used for running cypress test. In the second script, we have used the first script to run the desired command for running our tests.

we can integrate the same with Jenkins as well, for creating a parameterized build for executing the cypress test we can use the following steps.

  • Firstly we will create a new build in Jenkins, and we will click on the configuration button for creating a parameterized build.
  • In the general configuration, we will select our project as parametrized and select the choice parameter from the drop-down menu of add parameters option.
  • In the build environment section, we will click on add build step and select the execute shell option from the drop-down menu.
  • After selecting the build step, we can write our script in execute shell’s command section:
npm run "$scripts"

Note: here $script will denote the selected parameter before execution.

  • After adding our script we will click on the save button to save the latest changes. This will create a parameterized Jenkins build as per our requirements.

Execution of the Parameterized Jenkins build

  • For running the parameterized build, firstly we will select the build with parameter option for that particular project.
  • From the drop-down menu, we need to select one option as per our requirement and after that, we will click on the build button.

After/during the execution we can see the logs as well, for this we need to click on console output after selecting the running job.

Thanks for reading this blog!!

References:

https://www.udemy.com/course/cypress-tutorial
https://blog.knoldus.com/integration-of-cypress-with-jenkins/

Knoldus-blog-footer-image

Written by 

Vandana is a Sr. QA Consultant having experience of more than 2.5 years. She is familiar with the core concepts of manual and automation, postman and Newman are her expertise. She is always eager to learn new and advance concepts in order to expand her horizon and apply them in project development with her existing knowledge. Her hobbies include reading novels and listening to music.

Leave a Reply