Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Run Selenium Screenshot Tests in a Jenkins Pipeline

A practical Jenkins Pipeline pattern for running Selenium tests, saving WebDriver screenshots, retaining failure evidence, and extending captures into visual regression checks.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run your existing Selenium test command on a Jenkins agent that can launch the chosen browser, save WebDriver screenshots to the workspace, and use a Pipeline post section to retain screenshots and reports—especially when tests fail. Capturing an image is not, by itself, a visual regression test: that also requires a reviewed baseline, a comparison method, and a project-defined policy for acceptable differences.

What the pipeline needs

Selenium WebDriver drives the browser; Jenkins runs the test command and handles the build lifecycle and artifacts. Selenium’s documentation says its language bindings use Selenium Manager by default for browser and driver management, but that does not guarantee a particular Jenkins agent already has the browser or environment your test needs. Check the chosen agent and test environment before relying on a run. Selenium documentation

As an Amazon Associate I earn from qualifying purchases.

  • A Jenkins agent able to run your selected browser and reach the application under test.
  • A normal project test command that works outside Jenkins, where possible.
  • Test code that saves screenshots in a known workspace directory.
  • A Pipeline post action that publishes or archives the files and test reports.

Capture screenshots from the active WebDriver session

Take a screenshot at a meaningful test checkpoint, or in failure handling while the relevant browser session is still available. Use a predictable path within the workspace so the pipeline can find the evidence. For example, a Java test can save a full-page viewport capture from the current WebDriver session like this:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

public final class ScreenshotSupport {
    private ScreenshotSupport() {}

    public static Path save(WebDriver driver, String filename) throws Exception {
        Path directory = Paths.get("target", "screenshots");
        Files.createDirectories(directory);
        Path destination = directory.resolve(filename);
        byte[] image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
        Files.write(destination, image);
        return destination;
    }
}

Call ScreenshotSupport.save(driver, "checkout.png") after the page has reached the state you want to inspect. In a test framework’s teardown or failure hook, save a uniquely named image before quitting the driver; adapt that hook to the framework you actually use. This example writes a screenshot from the current browser viewport. It does not create a full-page image or establish a visual comparison.

Keep capture paths predictable

Jenkins can only archive files that exist in the job workspace and match the configured path. Choose a directory that your test runner actually writes to, and avoid writing evidence only to a temporary location that is removed before artifact collection. The Jenkins UI Test Capture plugin documents target/screenshots and association with test result data; that is a plugin convention, not a Selenium or Jenkins requirement. UI Test Capture plugin

Run the tests and retain evidence in Jenkins

A declarative Pipeline can run the project’s usual test command and archive screenshots and reports from a post condition. This example assumes a Unix-like agent with Java and Maven already available, and that the project writes screenshots under target/screenshots and JUnit XML under target/surefire-reports. Adjust the command and paths for your build tool and test runner.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
pipeline {
    agent any

    stages {
        stage('Selenium tests') {
            steps {
                sh 'mvn test'
            }
        }
    }

    post {
        always {
            archiveArtifacts artifacts: 'target/screenshots/**/*.png,target/surefire-reports/**/*.xml',
                             allowEmptyArchive: true
            junit testResults: 'target/surefire-reports/**/*.xml',
                  allowEmptyResults: true
        }
    }
}

Jenkins Pipeline supports post conditions including always, failure, and unsuccessful. Use always when you want the publication step attempted after either success or failure; choose another condition if your retention policy calls for it. The exact artifact and report steps depend on the Jenkins installation and plugins. Jenkins Pipeline Syntax

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Failure handling and cleanup

If screenshots are useful only when a test fails, place the relevant artifact step under failure; if you want evidence for every run, use always. Be careful with cleanup: Jenkins documents post conditions and lifecycle behavior, but your own cleanup steps can still remove files before they are archived if ordered incorrectly. Confirm the archived build contains the expected files after both a passing and failing test run.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Optional reporting plugins

The UI Test Capture plugin describes displaying screenshots associated with failed tests. The Selenium HTML Report plugin describes scanning a Selenium result directory for HTML files and copying them under seleniumReports in the build root. These are optional presentation and convention choices; check each plugin’s current compatibility and maintenance status before installing it. Selenium HTML Report plugin

A Jenkins plugin page for Selenium describes Selenium 3 Grid integration and currently displays an unresolved security vulnerability warning and an adoption notice. It is not a required default for running Selenium tests in Jenkins; review the current status before considering it. Selenium plugin

Turn screenshots into visual regression tests

A screenshot is evidence of a rendered state, not an assertion that the rendering matches an approved design. A visual regression workflow needs all three of the following:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. A baseline: an image reviewed and accepted as the expected appearance for a defined page state.
  2. A comparison method: a selected tool or implementation that compares the new capture with that baseline.
  3. A difference policy: a team decision about which changes should fail the build and how differences are reviewed.

Selenium and Jenkins do not prescribe a visual-diff library or universal tolerance. Select those as project decisions. To make comparisons meaningful, keep the browser, viewport, test data, and other rendering conditions consistent between baseline creation and CI runs. A forum question about fixed viewport dimensions reflects a practical concern, but the exact standard belongs to the project.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a local agent or Selenium Grid

Execution approach Useful when Trade-off
One Jenkins agent running the browser The job needs a controlled environment and a limited browser/OS setup. Simpler to operate, but coverage is limited to the environment you configure.
Selenium Grid Tests need distribution across multiple machines or browser and operating-system combinations. Provides broader execution coverage, with additional Grid setup, capacity planning, and troubleshooting.

Selenium describes Grid as a way to distribute tests across machines and run them across browser and operating-system combinations. It is an option for a job that needs that coverage, not a prerequisite for taking screenshots in Jenkins. Selenium Overview

Troubleshoot common failures

  • No browser starts: confirm the selected browser can run on the Jenkins agent and that the agent has the required environment. Selenium Manager’s default browser and driver management does not establish that every browser is installed or configured on every CI machine. See the Selenium documentation.
  • Screenshot is missing from the build: check that the test wrote it inside the job workspace, that the archive glob matches its actual filename and location, and that the post action runs even after a test failure.
  • Screenshot is blank or shows the wrong state: capture only after the test reaches the intended checkpoint. If the page depends on asynchronous content, make the test wait for the required state before capturing.
  • Artifact step reports no matching files: verify the test runner’s output directory and the Pipeline’s artifact pattern. The sample uses Maven-style paths; other runners may write elsewhere.
  • Visual comparison changes between runs: check whether browser, viewport, operating system, test data, and page state match the conditions used for the baseline. The comparison threshold and policy must be set by your project.
  • Considering a reporting plugin: inspect its current compatibility, maintenance, and security information on its Jenkins plugin page before adding it to the controller.

Or skip the browser setup

If you need a screenshot of a URL rather than evidence from your test’s active WebDriver session, ScreenshotNeo offers a one-request screenshot API. It is not a replacement for Selenium assertions or a visual baseline workflow. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response includes X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Selenium take a full-page screenshot by default?

The WebDriver capture example shown here records the current browser viewport; full-page capture requires a separate approach.

Is Selenium Grid required for screenshot tests in Jenkins?

No. A single suitably prepared Jenkins agent can run them; Grid is an option for distributed execution or broader browser and operating-system coverage.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.