We're heading to Adobe Summit 2025 (Mar 18-20)! Visit our booth 1290A and win big! Let’s meet at Summit
automate-cypress-tests-with-penkins-pipeline.jpg

How to automate cypress test with Jenkins pipeline

Feb 11th | Aaron Godinho

Cypress, a powerful JavaScript-based testing tool, has gained popularity for its ability to perform end-to-end testing with ease. When integrated with Jenkins, a leading automation server, Cypress can be seamlessly incorporated into your CI/CD pipeline. This article covers how to automate Cypress tests with Jenkins pipeline, showcasing how this combination can streamline automation testing in both marketing and technology environments.



Understanding Cypress for automated testing


Cypress is an open-source testing framework designed to handle everything from unit testing,component testing as well as end-to-end testing on modern web applications. Its simplicity and real-time reloading capabilities make it a preferred choice for developers and testers alike.

Setting up Cypress for end-to-end testing

Before diving into automation, it’s essential to set up Cypress properly. For those new to the platform, installation is straightforward. Refer to Cypress documentation for detailed guidance on setting it up.

Once set up, you can write your first Cypress test. Below is an example where we check the title of the Initialyze homepage:





describe('template spec', () => {
  it('Running Test', () => {
    cy.visit('https://www.initialyze.com/')
    cy.get('title').should('contain.text',’Initialyze | We deliver world-class customer experiences’)
  })
})

This simple test case ensures that the correct title is displayed when visiting the website.



Why Jenkins is essential for continuous integration


Continuous Integration is a software development practice that automates the process of integrating code changes from multiple developers into a single repository. Jenkins helps automate this process by fetching the latest code, running tests, and deploying the builds automatically. This makes Jenkins an indispensable tool for any development team aiming to improve their workflow.

Setting up Jenkins for automation

To execute Cypress tests using Jenkins, you need to create a script file called ‘Jenkinsfile’ within your project folder. This file will define the pipeline stages for the Jenkins automation process.


pipeline {
    agent any
    stages {
        stage('Build') { 
            steps {
                sh 'npm install'
            }
        }
stage('Run Tests') { 
      steps {
          sh 'npx cypress run' 
      }
 }
    }
}

This script tells Jenkins to install the required Node packages and then run the Cypress tests.



Executing Cypress scripts with Jenkins Pipeline


Next, configure Jenkins to fetch the script from your GitHub repository:

  • From the Jenkins home screen, select new item.

  • Select 'Pipeline' as the option and press the OK button.

  • Configuring Jenkins to get script from GitHub:

    1. Under 'Pipeline' configuration, select 'Pipeline script from SCM' and choose 'Git' as the source.

    2. Provide your GitHub repository URL under the Repository URL.


    3. Add your Git creds in Jenkins and select them under the Credentials dropdown.
    4. You can also specify the branch for which you want to execute or edit it and set it to ‘main’.
    5. Specify the Jenkinsfile script where it is inside the folder.


    6. Click on the save button.


Execute the Jenkins pipeline job from the dashboard


  1. Go to the Jenkins Dashboard and select the pipeline project you created.
  2. Different options will be displayed.


  3. To start the job, click on the “Build Now” button.
  4. The job will begin building, and you can monitor the progress of each stage.


  5. Once the build is triggered, click the down arrow icon next to the triggered job to view the “Console Output.”


  6. The entire execution log will be available in the console output, allowing you to track the details of the process.


  7. After the job completes, any failed stages will be marked in red, making it easy to identify where issues occurred. As shown in the image below.


  8. The user can track the reason for the test failing inside the Console output.
  9. If all tests pass, each stage will be marked green.



By following these steps, you can successfully execute Cypress test scripts in Jenkins using the Jenkinsfile. Moving forward, consider expanding your testing framework to include full end-to-end tests and regression tests. This approach will help reduce overall test coverage time and ensure comprehensive test results.


Final Thoughts:

Integrating Cypress with Jenkins in a CI/CD pipeline brings immense value to your development and testing workflow. By automating the testing process, development teams can ensure faster releases, higher code quality, and a significant reduction in manual effort. Whether you're working in a technology-driven company or within the marketing domain, leveraging Jenkins to run Cypress scripts will elevate your automation capabilities, enabling you to deliver exceptional digital experiences with confidence.


If you need any assistance with automation testing or require help with other software testing solutions, feel free to reach out to us. We're here to support your testing needs and help streamline your processes.