Back to All Scenarios
Scenario 83 of 100
CI/CD
Intermediate
Running Selenium Automation Suites in Jenkins Pipelines
ποΈScenario Overview
Running Selenium Automation Suites in Jenkins Pipelines
Key Takeaways & Cheat Sheet
- βMaintain a clean Maven pom.xml configuration file
- βDefine a standard Jenkinsfile using pipeline stages
- βEnable headless execution mode for target browser runners
- βArchive Extent and TestNG reports using Jenkins artifacts features
Short Direct Answer
To run tests in Jenkins, define a declarative `Jenkinsfile` that pulls the code, installs dependencies, and runs the Maven test suite using `mvn test`. Ensure your tests run in headless mode to work on non-GUI CI environments, and use Jenkins post-build actions to archive test reports.
β οΈ Senior Warning (Red Flag)
Do not run desktop browser GUI environments inside standard headless Jenkins servers. Without a virtual display frame buffer (like Xvfb) or headless arguments, your execution will throw a WebDriverException.
π‘ STAR Deep Dive Explanation & Pro Tip
Archiving report artifacts ensures that your visual execution reports and screenshots are preserved and accessible from the Jenkins build page.
SeleniumAutomation.java
Selenium 4 + Java// β
Standard declarative Jenkinsfile pipeline
pipeline {
agent any
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Execute Tests') {
steps {
// Run Maven suite passing headless system property flags
sh 'mvn test -Dheadless=true -Dbrowser=chrome'
}
}
}
post {
always {
// Archive HTML Extent reports and TestNG logs
archiveArtifacts artifacts: 'target/*.html, target/surefire-reports/**/*', onlyIfSuccessful: false
junit 'target/surefire-reports/**/*.xml'
}
}
}