To show Selenium test results in Jenkins, publish the report files your test run produces and attach them to each build. This page explains what the Selenium HTML Report plugin snippet above does. It also covers how to run Selenium WebDriver tests in a Jenkinsfile and publish the results with the junit and publishHTML steps, and how to fix the common problem of HTML reports showing up blank or without styling.
Step 1 – Install seleniumhtmlreport
Step 2 – Use following code
seleniumHtmlReport(String testResultLocation = 'target') {}
job('seleniumreport') {
publishers {
seleniumHtmlReport('target/test-output') {
failOnExceptions()
}
}
}Code language: PHP (php)
What the Selenium HTML Report plugin actually does
The Selenium HTML Report plugin (seleniumhtmlreport) reads the HTML result files that the old Selenese HTML suite runner writes, such as Selenium RC’s -htmlSuite mode or Selenium IDE test suites. It adds a summary of those results to the build page. It does not read the output of modern Selenium WebDriver tests written with TestNG, JUnit or pytest.
Most Selenium projects today use WebDriver with a test framework. Those frameworks write JUnit-style XML and their own HTML reports. In Jenkins you publish them with the junit step from the JUnit plugin and the publishHTML step from the HTML Publisher plugin. Use the Selenium HTML Report plugin only if you still run legacy Selenese HTML suites. It is an old plugin that rarely gets updates, so check its page in Manage Jenkins > Plugins for warnings before you install it.
| Your tests | What they produce | Jenkins step to use |
|---|---|---|
| Selenese HTML suites (Selenium RC / IDE) | Selenese HTML result files | Selenium HTML Report plugin |
| WebDriver + TestNG or JUnit (Maven/Gradle) | JUnit XML + HTML in target/surefire-reports |
junit + publishHTML |
| WebDriver + pytest | --junitxml XML, optional pytest-html report |
junit + publishHTML |
| Extent, Allure or similar reporters | Self-contained HTML folder | publishHTML (or the reporter’s own plugin) |
What the code above is, with corrections
The two snippets in Step 2 are not Jenkins Pipeline code, so they will not work in a Jenkinsfile. They come from the Job DSL plugin, which builds freestyle jobs from a Groovy seed script. CODE 1 is the method signature as it appears in the Job DSL API viewer. It documents the method but is not a statement you can run. The # comment lines are also not valid Groovy, so the seed job would fail to parse them.
Here is a corrected seed script. It needs the Job DSL plugin and the Selenium HTML Report plugin. Run it from a freestyle seed job with a Process Job DSLs build step:
job('seleniumreport') {
publishers {
seleniumHtmlReport('target/test-output') {
failOnExceptions(true)
}
}
}Code language: JavaScript (javascript)
Processing this script creates or updates a freestyle job called seleniumreport with the report publisher already configured. You still have to add an SCM and a build step that actually runs the Selenese suite and writes results to target/test-output.
Note: Not every old publisher works in Pipeline. If you have the plugin installed and want it in a Jenkinsfile, open Pipeline Syntax > Snippet Generator in your job and look for it under step: General Build Step. If it is not listed, your installed version does not support Pipeline. In that case, use the publishHTML approach below.
Prerequisites for publishing WebDriver reports from a pipeline
- Jenkins with the Pipeline, JUnit and HTML Publisher plugins installed.
- An agent with Java, Maven (or your build tool) and a browser plus its driver. A Selenium Grid or a container image such as
selenium/standalone-chromealso works. - Tests that can run headless, because Jenkins agents usually have no display.
- Maven configured under Manage Jenkins > Tools if you use the
toolsdirective. The name in the Jenkinsfile must match the name you gave it there.
Jenkinsfile that runs Selenium tests and publishes the report
This declarative pipeline runs a Maven project that uses TestNG or JUnit through the Surefire plugin. It records the results and publishes the HTML report. The -Dbrowser and -Dheadless properties are examples. Pass whatever settings your own test framework reads.
pipeline {
agent any
tools {
maven 'Maven3'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Selenium tests') {
steps {
sh 'mvn -B clean test -Dmaven.test.failure.ignore=true -Dbrowser=chrome -Dheadless=true'
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: 'target/surefire-reports/*.xml'
publishHTML(target: [
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'target/surefire-reports',
reportFiles: 'index.html,emailable-report.html',
reportName: 'Selenium Report'
])
archiveArtifacts artifacts: 'target/screenshots/**', allowEmptyArchive: true
}
}
}Code language: JavaScript (javascript)
post { always { ... } }publishes reports even when tests fail. Failed runs are the ones where you most need the report.-Dmaven.test.failure.ignore=truekeeps Maven from stopping the stage, andjunitthen marks the build UNSTABLE instead of FAILURE. Leave it out if you want the build to fail hard.keepAll: truekeeps a report for every build rather than only the latest one.reportFilestakes a comma-separated list. Each file appears as a tab in the published report.- For TestNG under Surefire,
index.htmlandemailable-report.htmlare written totarget/surefire-reports. For Extent, Allure or pytest-html, setreportDirto the folder that reporter writes to.
After a build, the job page shows a Selenium Report link in the sidebar and a Test Result Trend graph. Each build page shows Test Result with any failing test names and stack traces.
Fixing a blank or unstyled HTML report
Jenkins serves published files with a strict Content Security Policy (CSP). This blocks JavaScript, inline CSS and external fonts. Reports from TestNG, Extent and Allure rely on these, so they often show up as plain text or a blank page. The report files themselves are fine. The browser simply refuses to run their scripts.
- Preferred fix: set a Resource Root URL under Manage Jenkins > System. This must be a second hostname that points to the same Jenkins controller. Jenkins then serves report files from that origin, where scripts can run without weakening the main UI.
- Temporary test only: in Manage Jenkins > Script Console, run
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")and reload the report. The setting is lost when Jenkins restarts. - Permanent but less safe: start Jenkins with
-Dhudson.model.DirectoryBrowserSupport.CSP=(or a less strict policy). This lets any user who can write files into a workspace serve scripts to other Jenkins users.
Note: Do not relax the CSP on a Jenkins instance where untrusted people can change job configuration or source code. Use the Resource Root URL instead.
Common errors and fixes
| Symptom | Cause | Fix |
|---|---|---|
No such DSL method 'seleniumHtmlReport' in a Jenkinsfile |
The snippet is Job DSL, not Pipeline syntax | Use it in a Job DSL seed job, or switch to publishHTML |
No such DSL method 'publishHTML' |
HTML Publisher plugin not installed | Install the HTML Publisher plugin and restart if prompted |
No test report files were found |
Wrong path, or tests never ran | Check the workspace for target/surefire-reports, or set allowEmptyResults: true |
| Report link missing after a failed build | Publishing steps sit inside a stage that stopped early | Move junit and publishHTML into post { always { } } |
SessionNotCreatedException or Chrome crashes on the agent |
No display, or browser and driver versions don’t match | Run headless, and keep browser and driver versions in step (recent Selenium releases can manage drivers automatically) or use a Selenium container |
| Report opens but looks broken | Jenkins Content Security Policy | Configure a Resource Root URL as described above |
Best practices
- Always publish JUnit XML with the
junitstep, even if you also publish HTML. It gives you trends, history and failure details that a static HTML page cannot. - Save screenshots and browser logs on failure and archive them with
archiveArtifacts. This makes failures much easier to diagnose. - Run browsers in containers or on a Selenium Grid, so that browser and driver versions are pinned and agents stay clean.
- Limit how many builds you keep (
options { buildDiscarder(logRotator(numToKeepStr: '20')) }), becausekeepAll: truereports can take up a lot of disk space. - Send results to the team with a
post { failure { ... } }email or chat notification.
Frequently asked questions
Can I use the seleniumHtmlReport code from this post in a Jenkinsfile?
No. That code is Job DSL syntax, and it only works inside a Job DSL seed job. In a Jenkinsfile, publish Selenium results with the junit and publishHTML steps.
Which plugin should I use for Selenium WebDriver reports in Jenkins?
Use the JUnit plugin for the XML results produced by TestNG, JUnit or pytest, and the HTML Publisher plugin for HTML reports. The Selenium HTML Report plugin only reads legacy Selenese HTML suite results.
Why does my published Selenium HTML report look blank in Jenkins?
Jenkins applies a strict Content Security Policy to published files, which blocks JavaScript and inline styles. Configure a Resource Root URL so reports are served from a separate origin. For a quick test, you can relax the hudson.model.DirectoryBrowserSupport.CSP property.
How do I keep the report when Selenium tests fail?
Put the junit and publishHTML steps in a post { always { } } block. They then run whatever the result of the test stage.
Where are TestNG HTML reports created in a Maven project?
When TestNG runs through the Maven Surefire plugin, it writes index.html and emailable-report.html into target/surefire-reports, next to the XML result files.
Related tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals
PakarPBN
A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.
In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.
The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.
Streaming Film
Nonton Film gratis
Jasa Backlink
Download Anime Batch