Building a CI/CD Pipeline with Selenium and Jenkins

 Building a CI/CD pipeline with Selenium and Jenkins involves automating the build, test, and deployment of your application while ensuring that UI tests (via Selenium) are executed as part of the process. Below is a step-by-step guide to set it up:


πŸ”§ Prerequisites

Jenkins Installed (locally or on a server)


Selenium Test Suite (e.g., Java + TestNG/JUnit, Python + pytest, etc.)


Git Repository (GitHub, GitLab, etc.)


Build Tool:


Maven/Gradle for Java


pip/virtualenv for Python


Web Driver (ChromeDriver, GeckoDriver, etc.)


🧱 CI/CD Pipeline Overview

mathematica

Copy

Edit

Git Push → Jenkins Build Trigger → Build App → Run Selenium Tests → Report Results → Optional Deployment

πŸš€ Step-by-Step Setup

1. Install Required Jenkins Plugins

Git plugin


Maven Integration / Pipeline


HTML Publisher (for test reports)


Allure Jenkins plugin (if using Allure reports)


2. Prepare Your Project Structure

Example (Java + Maven):


css

Copy

Edit

my-app/

├── pom.xml

├── src/

│   ├── main/

│   └── test/

│       └── java/

│           └── selenium/

│               └── LoginTest.java

In pom.xml, define Selenium and TestNG/JUnit dependencies.


3. Create a Jenkins Job (Freestyle or Pipeline)

Option A: Freestyle Project

Source Code Management:


Git repo URL


Build Triggers:


GitHub hook trigger / Poll SCM


Build Step:


mvn clean test


Post-Build Actions:


Publish HTML or Allure reports


Option B: Pipeline (Jenkinsfile)

Create a Jenkinsfile in your repo:


groovy

Copy

Edit

pipeline {

    agent any


    tools {

        maven 'Maven 3.8.5'

        jdk 'JDK11'

    }


    stages {

        stage('Checkout') {

            steps {

                git 'https://github.com/your-org/your-repo.git'

            }

        }


        stage('Build') {

            steps {

                sh 'mvn clean compile'

            }

        }


        stage('Run Selenium Tests') {

            steps {

                sh 'mvn test'

            }

        }


        stage('Publish Reports') {

            steps {

                publishHTML(target: [

                    reportDir: 'target/surefire-reports',

                    reportFiles: 'index.html',

                    reportName: 'Test Report'

                ])

            }

        }

    }


    post {

        always {

            junit 'target/surefire-reports/*.xml'

        }

    }

}

4. Run & Monitor the Pipeline

Push changes to your repository.


Jenkins triggers the build.


Selenium tests execute.


Reports are available in the Jenkins UI.


5. Tips for Selenium Tests in CI

Run tests in headless mode (especially in CI environments):


java

Copy

Edit

ChromeOptions options = new ChromeOptions();

options.addArguments("--headless");

Use Docker for browser infrastructure (e.g., Selenium Grid, Selenoid).


Integrate with test management tools (Allure, TestRail).


✅ Outcome

By the end of this setup, you’ll have:


Fully automated build and test cycle


Immediate feedback on Selenium test results


Extensible pipeline for deployment stages

Learn Testing Tools Training in Hyderabad

Read More

Performance Testing with JMeter: Advanced Tips

Creating Custom Cypress Plugins

Mocking APIs in Postman

How to Choose the Right Testing Tool for Your Project

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

How to Install and Set Up Selenium in Python (Step-by-Step)

Tosca for API Testing: A Step-by-Step Tutorial

Waits in Playwright: Explicit, Implicit, and Auto