DEV Community

Cover image for Become a CI/CD Pro: Run Selenium Java Tests in Jenkins Pipelines from Scratch!
JigNect Technologies
JigNect Technologies

Posted on

Become a CI/CD Pro: Run Selenium Java Tests in Jenkins Pipelines from Scratch!

In today’s fast-paced development environment, ensuring your web applications are continuously tested is critical for delivering high-quality software. This blog is your complete guide to integrating Selenium Java tests into Jenkins pipelines for Continuous Integration (CI). Whether you’re a beginner just starting with test automation or looking to scale your CI setup, this step-by-step guide will take you from zero to hero. You’ll learn how to set up your environment, write and manage Selenium tests, configure Jenkins pipelines, run tests automatically on code changes, generate reports, and follow best practices for efficient test automation. By the end, you’ll have a solid, real-world-ready CI pipeline powering your test automation lifecycle.

The Role of CI/CD and Jenkins in Modern Test Automation

What is CI/CD?

Continuous Integration (CI) is a development practice where developers frequently integrate code into a shared repository. Each integration can then be verified by an automated build and automated tests. This helps detect errors quickly, improve software quality, and reduce the time it takes to release updates.

Continuous Delivery (CD) extends Continuous Integration (CI) by ensuring the application is always in a deployable state. With CD, code changes are automatically prepared for a production release. In some cases, CD refers to Continuous Deployment, where every change that passes the tests is automatically deployed to production without manual intervention.

If you want to learn more about CI/CD and explore, check out our in-depth blog: The top tools every QA automation engineer should know

Overview of Jenkins as a CI/CD Tool

Jenkins is a powerful, open-source automation server that helps developers and QA teams build, test, and deploy software efficiently. It’s one of the most popular tools in the CI/CD ecosystem and acts as the glue that brings your automation workflow together. Whether you’re working on small personal projects or managing enterprise-scale pipelines, Jenkins offers the flexibility and extensibility to suit your needs.

What Makes Jenkins Essential in CI/CD?

Jenkins plays a central role in Continuous Integration and Continuous Delivery by automating key tasks such as:

  • Pulling code from version control like GitHub or GitLab
  • Building the code using tools like Maven or Gradle
  • Running tests using TestNG, JUnit, Selenium, etc.
  • Deploying builds to various environments like QA, staging, or production
  • Notifying stakeholders of success or failure via email, Slack, or dashboards

Why Use Jenkins for Test Automation?

Jenkins is highly compatible with a wide variety of test automation frameworks and tools. It streamlines the process of executing test suites, capturing results, and providing continuous feedback to the development team. Its ability to integrate with popular tools like Selenium, TestNG, JUnit, Cucumber, and Allure makes it an ideal choice for automation projects.

Key Reasons to Use Jenkins for Test Automation:

  • Automated Scheduling: Run tests at fixed intervals, after code commits, or before releases.
  • Triggering on Code Changes: Jenkins can initiate tests automatically when new code is pushed to version control.
  • Test Reporting: Jenkins supports native and plugin-based test result visualization (like TestNG reports, JUnit, and Allure).
  • Integration with DevOps Tools: Seamlessly connects with Docker, Kubernetes, Slack, GitHub, and more.
  • Scalability: Distribute test execution across multiple agents and environments.

Advantages of Using Jenkins for Automation

  • Open-source & Free: Jenkins is backed by a vibrant community, making it cost-effective and well-supported.
  • Extensible: With over 1500 plugins, you can tailor Jenkins to fit any workflow or toolchain.
  • Cross-platform Compatibility: Runs on all major operating systems, including Windows, macOS, and Linux.
  • Rich Plugin Ecosystem: Supports integration with virtually any testing, deployment, or monitoring tool.
  • Easy Integration: Quick to connect with version control systems, build tools, and testing libraries.
  • Stable & Reliable: Proven by thousands of organizations and teams around the world for CI/CD processes.
  • Community & Documentation: Comprehensive documentation, active forums, and frequent updates make it beginner- and expert-friendly

Environment Setup & Building Your Selenium Java Project

Before integrating your tests with Jenkins, it’s essential to have a basic Selenium Java framework up and running.

  • Installing Java, Maven, and Git: Java is required for both Selenium and Jenkins. Maven handles dependencies and builds, while Git enables version control.
  • Setting Up IDE (IntelliJ/Eclipse): Choose your preferred IDE for writing and organizing test code efficiently.
  • Building Your Selenium Java Project: Start with a Maven project to manage your test structure and dependencies easily.
  • Creating a Maven Project & Managing Dependencies: Use the pom.xml file to add Selenium, TestNG, and other libraries.
  • Writing Your First Test (TestNG or JUnit): Create simple test cases to validate your setup and ensure everything works.
  • Running Tests Locally: Execute tests via IDE or using the Maven command mvn test.

Already covered in detail in our previous blog!
Read the full beginner-friendly Selenium with Java & TestNG guide here

Version Control with Git

Using Git ensures your test automation code is trackable, collaborative, and easily integrated into CI/CD pipelines.

  • Initializing Git in Your Project: Start by running git init in your project directory to track changes locally.
  • Pushing Code to GitHub: Add a remote repository and push your code using git push to share and collaborate with your team. Want to learn Git commands in detail with test automation best practices? Check out our full Git guide here

Jenkins Essentials

Download and Install Jenkins

  • Go to the official Jenkins site:
  • https://www.jenkins.io/download/
  • Click on Windows and download the .msi installer.
  • Run the installer:
  • Jenkins runs as a Windows Service after installation, or use java -jar jenkins.war
  • The default port is 8080
  • After installation, open your browser and go to: http://localhost:8080
  • On first launch, Jenkins will ask for an initial admin password. Open this file to get the password: C:\Users.jenkins\secrets\initialAdminPassword Replace with your system username

Jenkins

Install Plugins:

  • Choose Install suggested plugins.
  • Wait for installation to complete.

![Customize Jenkins(https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p57glau2sxwdurjspkeg.png)

Create Admin User :

  • Fill out the form to create your first admin account.
  • Click Save and Continue

Create Admin User

Configure Jenkins URL :

  • Keep the default: http://localhost:8080
  • Click Save and Finish
    Jenkins is Ready!

  • Click Start using Jenkins to go to the dashboard.

Jenkins Ready

Image

The Jenkins Dashboard is your central hub. From here, you can create and manage jobs, view build history, access system configurations via Manage Jenkins, and monitor the health of your automation workflows. Jenkins provides a web interface where you’ll spend most of your time:

Jenkins Dashboard Tour

Read The Full Blog Here:- JigNect Technologies

Top comments (1)

Collapse
 
onlineproxy profile image
OnlineProxy

Use a minimal Declarative Jenkinsfile that runs mvn clean test, publishes junit, and archives screenshots, then install Jenkins on your OS and wire up JDK, Maven, browsers, and core plugins with Allure for pretty reports. Hook a Multibranch Pipeline to GitHub webhooks so every PR auto runs and posts checks. Ship Allure, stash screenshots and videos, scale with sharding and Docker or K8s or a cloud grid, and lock down Jenkins with RBAC, CSRF, and secret rotation while watching trends in JUnit, Allure, and Grafana.