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

To capture Selenium screenshots on a Jenkins agent and keep them with the build, have the test save each PNG inside the Jenkins workspace, then archive the matching files with archiveArtifacts. Put the archive step in Declarative Pipeline’s post { always { ... } } block when you need screenshots from failed builds, too. With a remote browser or container, first ensure the screenshot file is visible in the workspace Jenkins archives.

How the screenshot-to-artifact workflow works

Selenium captures the current browsing context through WebDriver; its language bindings can return or save PNG data. Jenkins agents run Pipeline steps in a workspace, and archiveArtifacts collects matching files from that workspace. The reliable handoff is therefore: capture in the test process, write to a workspace-relative path, and archive that path after the test stage.

  1. Choose whether you need a screenshot of the current browsing context or a particular element.
  2. In the Selenium test, write the image under a directory such as screenshots/ in the workspace.
  3. Configure Jenkins to archive the directory with a matching pattern.
  4. Use post { always { ... } } if artifact collection must run after a failed test as well as a successful one.

Selenium’s official WebDriver documentation includes full-context and element screenshot examples across bindings: Selenium: Working with windows and tabs. WebDriver is a W3C Recommendation; Selenium’s getting-started guide explains the browser and driver setup: Selenium: Getting started.

Configure Jenkins to archive screenshots

This Declarative Pipeline example runs tests and archives any PNGs created below screenshots/. It assumes the test command writes files into the agent workspace.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
pipeline {
    agent any
    stages {
        stage('Browser tests') {
            steps {
                sh 'pytest'
            }
        }
    }
    post {
        always {
            archiveArtifacts artifacts: 'screenshots/**/*.png', allowEmptyArchive: true
        }
    }
}

Jenkins resolves artifact paths relative to the workspace and uses Ant-style include patterns. Its artifact scanner is case-sensitive by default. The Declarative always condition runs at completion regardless of the pipeline result. See the Jenkins guides for recording tests and artifacts, the archiveArtifacts step, and Pipeline post conditions.

Decide whether an empty archive is acceptable

allowEmptyArchive: true prevents the build from failing just because the pattern matched no files. That can be appropriate if screenshots are only produced under certain conditions. But if every run should create a screenshot, allowing an empty archive can hide a broken capture path or a test that never wrote the file. In that case, omit the option so Jenkins reports the zero-match problem.

Keep paths aligned

The code that writes the screenshot and the archive glob must agree. For example, a file at screenshots/failure.png matches screenshots/**/*.png. A file written to another directory, or with an extension such as .PNG, may not match the pattern as intended. Save relative to the process working directory when that directory is the workspace, or construct an explicit workspace path.

Save screenshots with Selenium

Use the binding already used by your tests. The examples below capture a PNG from the current browsing context; Selenium also supports element screenshots when the whole page context is unnecessary. Confirm the portion of the page returned by your selected browser and driver rather than assuming every implementation captures beyond the current viewport.

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.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Python

For a test or failure handler running from the workspace, create the destination directory and call save_screenshot:

from pathlib import Path

screenshot_dir = Path("screenshots")
screenshot_dir.mkdir(parents=True, exist_ok=True)
driver.save_screenshot(str(screenshot_dir / "failure.png"))

Selenium’s Python example uses driver.save_screenshot('./image.png'). Put the call in the test code or framework’s failure hook if the image is specifically for diagnosing a failed test. The hook itself is framework-specific; Jenkins can archive only files that have actually been written before the post section runs.

JavaScript

The JavaScript WebDriver API returns a Base64-encoded PNG. Decode it when writing the file, and ensure its parent directory exists:

const fs = require('node:fs/promises');

await fs.mkdir('screenshots', { recursive: true });
const encoded = await driver.takeScreenshot();
await fs.writeFile('screenshots/failure.png', encoded, 'base64');

Run the test process with the Jenkins workspace as its working directory, or replace the relative path with a known workspace path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Java

In Java, use Selenium’s TakesScreenshot interface and copy the returned file into the workspace directory. Create the directory before the test or capture operation:

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

Path directory = Path.of("screenshots");
Files.createDirectories(directory);
File image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(image.toPath(), directory.resolve("failure.png"),
    StandardCopyOption.REPLACE_EXISTING);

The exact driver and browser setup varies by project. The important artifact requirement is unchanged: the final file must be available at a path under the Jenkins workspace when the archive step executes.

Choose full-context or element capture

A full-context screenshot gives more surrounding information, which is often useful for layout or navigation failures. An element screenshot focuses on a specific component, which can make a targeted assertion failure easier to inspect. Selenium documents both options, but the precise screenshot scope can depend on the binding, driver, and browser.

  • Use a full-context screenshot for failures where surrounding page state matters.
  • Use an element screenshot when the diagnostic question is confined to one component and your binding and driver support it.
  • For failure-only capture, call the relevant screenshot API from the test framework’s failure hook or exception handling path, then let Jenkins archive the resulting files.

Account for agents, containers, and remote browsers

Browser running on the Jenkins agent

If the browser and test process run on the agent, write screenshots directly into the agent’s workspace. Jenkins allocates a workspace for Pipeline execution; the artifact archive step reads from that workspace.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Container agent

For a containerized test, make sure the path used by the process is part of the workspace visible to the Pipeline step. Container and workspace mounts vary by Jenkins deployment, so verify the actual mount arrangement rather than assuming a file written inside a container is automatically available for archiving. Jenkins documents agent and workspace execution in its Pipeline agent guidance.

Selenium Grid or another remote WebDriver

A WebDriver screenshot call returns image data to the test process, but a screenshot saved on a separate machine is not automatically an artifact in Jenkins. Keep the screenshot call and file-write operation in the test process and write the returned data into that process’s Jenkins workspace. If the test process itself runs remotely, arrange an explicit transfer into the workspace before archiveArtifacts runs.

Troubleshoot missing screenshots

  • No screenshot file was created: The capture code may not have run, or it may have failed before writing. Check the test log and confirm the capture path is reached, especially in a failure hook.
  • Jenkins reports no matching artifacts: Compare the actual file path and extension with the archive pattern. Remember that matching is case-sensitive by default.
  • The file exists locally but not in the archive: Confirm it is under the workspace, not a temporary directory or another machine’s filesystem.
  • Containerized tests produce no archived file: Inspect the container/workspace mount arrangement and ensure the screenshot lands in a path visible to the Pipeline step.
  • Remote WebDriver tests produce no archived file: Write the screenshot data in the test process and transfer it to the Jenkins workspace if that process is not running there.
  • Files disappear before archive: Check cleanup steps and move cleanup after artifact collection, or preserve the screenshot directory until archiving completes.
  • The build passes but the screenshot is absent: If capture is limited to failures, that may be expected. If screenshots should always exist, remove allowEmptyArchive: true so a missing match is not silently accepted.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website image or PDF rather than a Selenium-driven test session, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. It can remove cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. An MCP server provides screenshot tools for Claude, Cursor, and other MCP clients.

The following cURL request saves a WebP screenshot of a URL. Replace the example URL and provide your API key. See the ScreenshotNeo API documentation for request options and response details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo’s free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. For Jenkins test artifacts, Selenium remains the appropriate choice when you need a browser session controlled by your test. To try ScreenshotNeo’s hosted capture API, sign up free for 1,000 screenshots a month with no card.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Frequently Asked Questions

Does Jenkins take the Selenium screenshot automatically when a test fails?

No. The test code or framework failure handler must capture and write the image; Jenkins archives files that already exist in the workspace.

Can I archive screenshots only when tests fail?

Yes. Capture them in the test failure path and use a Jenkins post condition that runs regardless of result to collect any resulting files.

Can Jenkins archive a screenshot saved on a Selenium Grid machine?

Only after the file is made available in the Jenkins workspace. A screenshot saved elsewhere is not automatically visible to the archive step.

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

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.