Run Selenium WebDriver tests in Jenkins pipeline
In modern software development, automation testing is not complete without CI/CD integration. Running Selenium tests manually is inefficient and does not scale in real-world projects. In this guide, you will learn how to integrate Selenium with Jenkins pipeline and execute automated tests as part of your CI/CD workflow.
What is Jenkins in Selenium Automation?
Jenkins is an open-source automation server used for:
- Continuous Integration (CI)
- Continuous Delivery (CD)
- Automated build execution
- Running test suites
When combined with Selenium, Jenkins allows automated execution of UI tests after every code commit.
Why Integrate Selenium with Jenkins?
Without Jenkins:
- Tests are run manually
- Feedback is delayed
- Human errors increase
With Jenkins:
- Tests run automatically
- Faster feedback loop
- Continuous validation of builds
- Better software quality
Jenkins + Selenium Architecture
Developer Push Code ↓ GitHub ↓ Jenkins ↓ Maven Build ↓ Selenium Test Suite ↓ Test Reports
Prerequisites
Before integrating Selenium with Jenkins, ensure you have:
- Java installed
- Maven project ready
- Selenium test framework (TestNG or JUnit)
- GitHub repository
- Jenkins installed or cloud Jenkins access
Step 1: Install Jenkins
You can install Jenkins:
- Locally (Windows/Linux)
- Docker
- Cloud Jenkins instance
After installation:
- Open Jenkins dashboard
- Install recommended plugins
Step 2: Install Required Jenkins Plugins
Install:
- Git Plugin
- Maven Integration Plugin
- TestNG Plugin (optional)
- HTML Publisher Plugin
Step 3: Push Selenium Project to GitHub
Ensure your Selenium framework is pushed to a Git repository:
Example structure:
SeleniumFramework│├── src├── pom.xml├── testng.xml
Step 4: Create Jenkins Job
Steps:
- Click New Item
- Enter job name
- Select Freestyle Project or Pipeline
- Click OK
Step 5: Connect GitHub Repository
In Jenkins:
- Go to Source Code Management
- Select Git
- Add repository URL
Step 6: Configure Maven Build
In Build section:
Add goal:
clean test
This will execute Selenium tests using Maven.
Step 7: Add TestNG Suite Execution
If using TestNG, configure:
testng.xml
And pass it in Maven:
mvn clean test -DsuiteXmlFile=testng.xml
Step 8: Jenkins Pipeline (Declarative Example)
Instead of freestyle jobs, you can use Jenkins pipeline.
Jenkinsfile Example
pipeline { agent any stages { stage('Checkout Code') { steps { git 'https://github.com/your-repo.git' } } stage('Build') { steps { sh 'mvn clean compile' } } stage('Run Tests') { steps { sh 'mvn test' } } stage('Generate Reports') { steps { publishHTML([ reportDir: 'target/surefire-reports', reportFiles: 'index.html', reportName: 'Selenium Test Report' ]) } } }}
Step 9: View Test Reports
After execution:
- Go to Jenkins job
- Click Test Results
- View HTML reports
Reports include:
- Passed tests
- Failed tests
- Execution time
- Stack traces
Step 10: Schedule Automatic Execution
You can schedule Jenkins jobs using cron syntax:
H/15 * * * *
This runs tests every 15 minutes.
Jenkins Integration with Selenium Framework
Your framework should include:
- Page Object Model (POM)
- TestNG
- Maven
- Utilities
- Reporting tools (Extent/Allure)
Jenkins + Selenium + Git Flow
Code Push → GitHub → Jenkins Trigger → Build → Selenium Tests → Report → Feedback
Common Issues in Jenkins Selenium Integration
1. Browser Not Found
Cause:
- Jenkins machine missing browser
Solution:
- Install Chrome/Firefox on Jenkins node
2. Driver Issues
Solution:
- Use Selenium Manager
3. Test Failing in Jenkins but Passing Locally
Cause:
- Headless environment differences
Solution:
- Use headless mode in CI
4. Permission Errors
Cause:
- Jenkins workspace restrictions
Best Practices
- Use pipeline instead of freestyle jobs
- Run tests in headless mode
- Store credentials securely
- Use Maven for build management
- Integrate reporting tools
- Run tests in parallel using Selenium Grid
- Keep Jenkins agents clean
Real-World Usage
Jenkins + Selenium is used in:
- Continuous regression testing
- Smoke testing after deployment
- Nightly build validation
- Cross-browser automation pipelines
Jenkins vs Manual Execution
| Feature | Manual Execution | Jenkins Automation |
|---|---|---|
| Speed | Slow | Fast |
| Reliability | Low | High |
| Frequency | On-demand | Continuous |
| Reporting | Manual | Automated |
Frequently Asked Questions
Can Selenium run in Jenkins?
Yes, Selenium tests can be fully automated in Jenkins pipelines.
Do I need Maven for Jenkins Selenium integration?
Not mandatory, but highly recommended.
Can Jenkins run tests in parallel?
Yes, especially when combined with Selenium Grid.
What is Jenkinsfile?
It is a script that defines CI/CD pipeline stages.
Why do Selenium tests fail in Jenkins?
Common reasons:
- Missing drivers
- Headless environment issues
- Timing issues
Conclusion
Integrating Selenium with Jenkins enables full CI/CD automation, allowing teams to run tests automatically on every code change. This improves software quality, reduces manual effort, and ensures faster feedback cycles.
With Jenkins pipelines, Selenium frameworks become production-ready and scalable for enterprise-level automation.
In the next article, we will explore TestNG in Selenium, which controls test execution flow, grouping, and reporting in automation frameworks.
Related Articles
✓ Selenium Framework Design
✓ Selenium Grid Explained
✓ Page Object Model in Selenium
✓ Selenium Waits Explained
✓ Complete Selenium Tutorial
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.

Pingback: Selenium on BrowserStack Setup - Rotebit
Pingback: Selenium Interview Questions (Beginner to Advanced) - Rotebit