A Beginner’s Guide to Integrating Test Automation into a CI/CD Pipeline


Welcome to this beginner-friendly guide on how to include test automation in a Continuous Integration and Continuous Delivery (CI/CD) pipeline! If you’re new to software development or testing, don’t worry this blog will break down the process step by step. By the end, you’ll understand how CI/CD works, why it’s important, and how to set it up using tools like GitHub, Jenkins, and Webhooks, with a focus on automating tests. Let’s dive in!
What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Delivery. These practices help developers and testers work faster and deliver high-quality software more efficiently. In traditional software projects, the process is slow: developers write code, testers (QA) manually test it, write automation test cases, and after weeks, the code is released to production. This can take a long time!
However, companies like Google and Microsoft release updates multiple times a day, sometimes every few minutes! How do they do it? The answer is CI/CD. With CI/CD, every time a developer makes changes to the code, it’s automatically tested and, if it passes, deployed to production without manual delays. This automation saves time and reduces errors.
Here’s how it works at a high level:
A developer writes code and pushes it to a source control repository (like GitHub).
A tool like Jenkins automatically detects the new code, runs automated tests, and, if the tests pass, deploys the code to production.
This process happens without manual intervention, ensuring continuous integration (merging code changes frequently) and continuous delivery (deploying code to production quickly).
Why CI/CD Matters
In traditional projects, releasing software involves multiple steps:
Developers push code.
QA tests it manually or with automation.
Bugs are found, fixed, and retested.
After weeks, the code is deployed on a set release date.
This process is slow and error-prone. CI/CD automates these steps, allowing companies to:
Test code as soon as it’s written.
Catch bugs early.
Deploy to production quickly and reliably.
How CI/CD Works: A Simple Example
Let’s break down the CI/CD process using a real-world example. Imagine you’re working on an app, and you add a new feature, like a search section for men or women. Here’s what happens in a CI/CD pipeline:
Developer Pushes Code: The developer adds the new feature and pushes the code to a GitHub repository.
Webhooks Notify Jenkins: A Webhook in GitHub detects the code push and alerts Jenkins, a tool that manages automation tasks.
Jenkins Runs Tests: Jenkins pulls the latest code from GitHub and runs automated tests (e.g., Selenium tests) to check if the new feature works.
Deploy to Production: If all tests pass, Jenkins can trigger another job to deploy the code to production automatically.
This entire process is automated, meaning no one has to manually test or deploy the code. The result? Faster, more reliable software releases!
Step-by-Step Guide to Setting Up a CI/CD Pipeline
Now, let’s walk through the detailed steps to set up a CI/CD pipeline for test automation. We’ll use a Selenium framework (a tool for automating web testing) as the example project, push it to GitHub, configure Jenkins to run tests, and use Webhooks to automate the process.
Step 1: Prepare Your Project and Push to GitHub
Create a Project Folder
First, you need a project to work with. I will be using a Selenium Framework that we built earlier. To keep things organized, create a new folder for the CI/CD setup:
Open a terminal (on Mac or Windows).
Navigate to a directory and create a new folder called
cicd
using the command:mkdir cicd
Move into the folder:
cd cicd
Copy your project (e.g.,
SeleniumFrameworkDesign
) into this folder. You can do this manually by copying the project folder or using a file explorer.
Initialize Git
To push your project to GitHub, you need to make it Git-compatible:
Navigate to your project folder in the terminal:
cd SeleniumFrameworkDesign
Initialize Git:
git init
This creates a hidden
.git
file, allowing your project to interact with GitHub.
Create a Branch
Create a branch called main
(GitHub’s default branch name):
git checkout -b main
Stage and Commit Files
Check the status of your project files:
git status
This shows all files as untracked. To track them:
Stage all files:
git add .
Check the status again to confirm files are staged (they’ll appear green in the terminal).
Commit the files with a message:
git commit -m "initial files commit"
Create a GitHub Repository
Go to github.com and sign up or log in.
Click New to create a repository called
AutomationCICD
(make it public for simplicity).Copy the repository’s HTTPS URL (e.g.,
https://github.com/username/AutomationCICD.git
).
Push Code to GitHub
Link your local project to the GitHub repository:
git remote add origin https://github.com/username/AutomationCICD.git
Push the code:
git push origin main
You may need to authenticate with your GitHub username and password. For a smoother experience, install the Git Credential Manager:
On Mac, use Homebrew to install it:
brew install git-credential-manager brew upgrade git-credential-manager
On Windows, it’s included when you install Git.
After authentication, your code is now on GitHub!
Step 2: Set Up Jenkins
Jenkins is a tool that automates tasks like running tests or deploying code. Here’s how to set it up:
Check Java Requirements
Jenkins requires a specific Java version (e.g., Java 11, 17, or 21). Check your system’s Java version:
On Mac:
echo $JAVA_HOME
On Windows, check environment variables for
JAVA_HOME
.
If you don’t have a supported version, install one before proceeding.
Download Jenkins
Visit the Jenkins website and download the Long-Term Support (LTS) version (a stable release).
Download the
jenkins.war
file (a Java package).Rename it to something unique (e.g.,
jenkinsnewest.war
) to avoid confusion.
Clean Up Old Jenkins Configurations
If you’ve used Jenkins before, clear old configurations to avoid compatibility issues:
Navigate to the
.jenkins
folder:Windows:
C:\Users\YourName\.jenkins
Mac:
/Users/YourName/.jenkins
Delete all files in this folder (back up any important jobs first).
Start Jenkins
Navigate to the folder where
jenkinsnewest.war
is saved (e.g., Downloads):cd ~/Downloads
Start Jenkins on a specific port (e.g., 9090):
java -jar jenkinsnewest.war --httpPort=9090
Jenkins will create a new
.jenkins
folder and display an initial admin password in the terminal. Copy it.
Configure Jenkins
Open a browser and go to
http://localhost:9090
.Paste the admin password and click Continue.
Choose Install suggested plugins to install necessary plugins.
Create an admin account and save the credentials.
Keep the default Jenkins URL (
http://localhost:9090
) and finish setup.
Install the Maven Plugin
Since the project is a Maven project (a tool for managing Java projects), install the Maven plugin:
Go to Manage Jenkins > Plugins > Available Plugins.
Search for Maven Integration, select it, and install.
Restart Jenkins to apply the plugin:
java -jar jenkinsnewest.war --httpPort=9090
Configure Maven in Jenkins
Go to Manage Jenkins > Global Tool Configuration.
Scroll to Maven and add your Maven installation:
Find your Maven home path (e.g.,
C:\Users\YourName\apache-maven-3.8.6
on Windows or/usr/local/apache-maven-3.8.6
on Mac).Enter the Maven version (e.g.,
3.8.6
) and the home path.
Save the configuration.
Create a Jenkins Job
Go to New Item and create a job called
Selenium Automation Test
(select Maven project).Under Source Code Management, select Git and enter the GitHub repository URL (e.g.,
https://github.com/username/AutomationCICD.git
).Add credentials:
Go to your GitHub account > Settings > Developer Settings > Personal Access Tokens > Generate new token (classic).
Select all permissions, name the token (e.g., SeleniumCICD), and copy it.
In Jenkins, add the token as a Secret Text credential.
Specify the branch (
main
).Under Build Triggers, check GitHub hook trigger for GITScm polling (this enables Webhook triggers).
In the Build section, specify the Maven goal:
test -P regression
This runs the
regression
profile, which triggers specific tests defined in thetestng.xml
file.Save the job.
Test the Job
Click Build Now to run the job. Jenkins will:
Pull the code from GitHub.
Run the Maven command (
mvn test -P regression
).Execute the tests defined in
testng.xml
(e.g.,SubmitOrderTest
andErrorValidationTest
).Display the results in the Console Output.
If the tests pass, the setup is working!
Step 3: Configure Webhooks for Automation
To make Jenkins run tests automatically when code is pushed to GitHub, you need a Webhook:
Get the Jenkins Webhook URL
Go to Manage Jenkins > System > GitHub section.
Click Advanced and check Specify another hook URL for GitHub configuration.
Copy the URL (e.g.,
http://localhost:9090/github-webhook/
).
Handle Localhost Limitations
Webhooks require a public URL, but localhost
is private. To test locally, use ngrok to create a temporary public URL:
Sign up at ngrok.com and download ngrok for your system:
Windows: Download the 64-bit executable and extract it.
Mac: Install via Homebrew:
brew install ngrok
Authenticate ngrok:
Copy the authentication command from the ngrok dashboard (e.g.,
ngrok authtoken YOUR_TOKEN
).Run it in the terminal.
Create a public URL for your Jenkins server:
ngrok http 9090
This generates a public URL (e.g.,
https://abc123.ngrok.io
).Combine it with the Webhook path:
https://abc123.ngrok.io/github-webhook/
.
Set Up the Webhook in GitHub
Go to your GitHub repository (
AutomationCICD
) > Settings > Webhooks > Add webhook.Paste the ngrok URL (e.g.,
https://abc123.ngrok.io/github-webhook/
) in the Payload URL field.Add the secret token (the same GitHub personal access token used in Jenkins).
Select Just the push event to trigger the Webhook on code pushes.
Click Add webhook. A green checkmark indicates success.
Verify the Jenkins Job
Ensure the Jenkins job has the GitHub hook trigger for GITScm polling checkbox enabled in its configuration.
Step 4: Test the CI/CD Pipeline
Now, let’s see the CI/CD pipeline in action:
Open your project in a code editor (e.g., Eclipse) or text editor.
Modify a file (e.g., add a comment to
StandaloneTest.java
).Stage, commit, and push the changes:
git add StandaloneTest.java git commit -m "updated standalone test file" git push origin main
The Webhook detects the push, notifies Jenkins via the ngrok URL, and triggers the
Selenium Automation Test
job.Check Jenkins to see the job running automatically. The console output will show the tests executing and the results.
If the tests pass, the pipeline is working! The code is automatically tested as soon as it’s pushed, ensuring quality without manual intervention.
Key Takeaways
CI/CD automates testing and deployment, making software releases faster and more reliable.
GitHub stores your code, and Webhooks notify Jenkins when changes are made.
Jenkins pulls the code, runs automated tests (e.g., Selenium), and can deploy to production if tests pass.
ngrok is a workaround for testing Webhooks locally by providing a public URL.
As an automation engineer, your role is to set up the pipeline to run tests automatically, ensuring code quality.
Tips for Real-World CI/CD
In companies, Jenkins runs on cloud servers (e.g., AWS, Azure) with public URLs, so ngrok isn’t needed.
Always check Java and Maven versions for compatibility with Jenkins.
Use personal access tokens for secure communication between GitHub and Jenkins.
Backup Jenkins configurations before cleaning the
.jenkins
folder.
Conclusion
By following this guide, you’ve learned how to set up a CI/CD pipeline to automate test execution using GitHub, Jenkins, and Webhooks. You initialized a Git repository, pushed code to GitHub, configured Jenkins to run Selenium tests, and used ngrok to enable Webhooks locally. This setup ensures that every code change is automatically tested, bringing you closer to the fast-paced release cycles of companies like Google and Microsoft.
For more advanced topics, like deploying to production, explore DevOps courses or cloud platforms like AWS and Azure. Keep practicing, and you’ll master CI/CD in no time! 🚀
Happy automating! 😊
Subscribe to my newsletter
Read articles from Samiksha Kute directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Samiksha Kute
Samiksha Kute
Passionate Learner!