Selenide takes screenshots automatically when a test fails, and its current Configuration API says screenshot capture is enabled by default. For a deliberate checkpoint, call Selenide.screenshot("name"); for successful-test captures or failures outside Selenide checks, use a JUnit or TestNG integration. This guide covers those options, where the files go, and how to preserve them in CI.
What Selenide captures automatically
Selenide’s screenshot guide says it takes screenshots on test failure. In the current Configuration API, screenshots defaults to true. This is the simplest route for diagnosing a failed Selenide check: write a normal test, let the assertion run, then inspect the generated report artifacts. See the Selenide screenshot guide and Configuration API.
For Gradle projects, the documented default report directory is build/reports/tests. Set a predictable alternative either as a Java property or a JVM system property:
- Java:
Configuration.reportsFolder = "test-result/reports"; - JVM argument:
-Dselenide.reportsFolder=test-result/reports
Use one location consistently in local runs and CI so the artifact-upload step knows where to look. Selenide writes artifacts locally; uploading or retaining them in a CI system is a separate pipeline configuration.
Choose the capture route that matches the test
| Route | Best for | Important distinction |
|---|---|---|
| Automatic failure capture | Debugging ordinary failed checks | Controlled by Configuration.screenshots. |
| JUnit or TestNG integration | Capturing successful tests or failures from general test assertions | Hooks into the test framework lifecycle. |
Selenide.screenshot("name") |
A named checkpoint in the middle of a test | Creates a PNG even when automatic screenshot capture is disabled. |
| Element screenshot API | Inspecting a component rather than the whole page | Some returned files are temporary; consume or copy them promptly. |
| Chromium MHTML page source | Keeping markup with embedded page resources | Requires savePageSourceWithResources; non-Chromium capture or failure can fall back to HTML. |
Set up a Selenide test
Add Selenide and your chosen test framework using the dependency version already selected for your project. The official overview describes the basic workflow as opening a page, acting on an element, and checking a condition; it does not require a special screenshot test type. The example below is a JUnit 5-style test using Selenide’s static API:
import org.junit.jupiter.api.Test;
import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Condition.*;
class HomePageTest {
@Test
void headingIsVisible() {
open("https://example.com");
$("h1").shouldHave(text("Example Domain"));
}
}
Replace the URL and assertion with the page and condition your test owns. With automatic capture enabled, a failing Selenide check is the trigger; the screenshot then appears with the test report artifacts. The documented workflow is described in Selenide’s documentation overview.
Capture a named screenshot during a test
Call Selenide.screenshot("my_file_name") where the checkpoint matters. The API writes my_file_name.png. Depending on configuration, Selenide can also save my_file_name.html, or in Chromium, my_file_name.mhtml when page-source-with-resources capture is enabled.
import org.junit.jupiter.api.Test;
import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Condition.*;
class CheckoutTest {
@Test
void captureAfterCartLoads() {
open("https://example.com/cart");
$(".cart").shouldBe(visible);
screenshot("cart-loaded");
}
}
The method is useful for capturing a state before a later action changes it, or for a successful test where automatic failure capture would not run. The named screenshot method creates its PNG even if Configuration.screenshots is false. The API also supports returning the capture in forms such as bytes, Base64, or a temporary file; consult the Selenide API for the exact overloads available to your project version.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Capture only an element
For a component-focused artifact, use the element screenshot methods in Selenide’s Screenshots API. The API describes capture to a file or image, including iframe-aware methods. This is useful when a page contains unrelated content that makes a full-page capture harder to inspect.
Handle returned files as short-lived artifacts: the API warns that a returned file may be temporary and is not guaranteed to persist after tests complete. If another process needs it, copy it into the test’s report/artifact directory or read its contents while the test is still running. Do not assume that a temporary file path remains valid after teardown.
Capture successful tests and non-Selenide assertion failures
Automatic Selenide failure screenshots are useful for Selenide checks, but a test suite may also need captures after successful tests or when a framework assertion outside Selenide fails. The screenshot guide documents integrations for JUnit 5, JUnit 4, and TestNG.
JUnit 5
Register ScreenShooterExtension. The guide’s customization example is:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
new ScreenShooterExtension(true).to("target/screenshots")
Follow the extension registration pattern supported by the Selenide and JUnit versions in your build. The guide’s true option and destination are useful when you want screenshots on successful tests as well as failures.
JUnit 4 and TestNG
The same Selenide screenshot guide documents the JUnit 4 ScreenShooter rule and a TestNG ScreenShooter listener. Use the integration matching the framework already running your tests; avoid registering multiple screenshot hooks unless you intend to produce multiple captures. Verify the examples against the actual versions in your project, since framework registration APIs can differ across versions.
Keep page source alongside images when useful
Screenshots show rendered pixels, while page source can help investigate why a layout or resource is missing. In the current Configuration API, savePageSource defaults to true; savePageSourceWithResources defaults to false. To request page-source capture with resources in Chromium, set:
Configuration.savePageSourceWithResources = true;
Or set the JVM property -Dselenide.savePageSourceWithResources=true. Selenide 7.18.0 release notes, published 2026-08-20, describe this resource-inclusive capture using CDP’s Page.captureSnapshot. It is Chromium-specific; if CDP is unavailable or capture fails, Selenide falls back to plain HTML. The release note explains the behavior at Selenide 7.18.0.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRank #4
The current API pages identify version 7.18.2, but that does not establish that 7.18.2 is the latest released artifact. Check your dependency and the official release feed before treating a version-specific example as current for your project.
Make screenshots accessible in CI
- Set
Configuration.reportsFolderor pass-Dselenide.reportsFolder=...so the output path is known. - Run the browser tests and confirm locally that the report directory contains the expected screenshot and page-source artifacts.
- Configure your CI system to upload or retain that directory as a job artifact; Selenide does not itself upload it.
- If artifact links should include a CI report URL, configure
Configuration.reportsUrl. The Configuration API documents this URL-prefix setting.
Keep automatic failure captures for unexpected regressions, and add named checkpoints only where a particular state is diagnostically valuable. Capturing every intermediate state can increase the volume of artifacts your CI job must retain and review.
Troubleshooting Selenide screenshot tests
No screenshot appears after a failure
- Check that
Configuration.screenshotshas not been set tofalse. - Confirm the test failed through a Selenide check if you expect the default failure behavior; use a test-framework integration for broader lifecycle coverage.
- Look in the configured
reportsFolder, not only in the project root. The documented Gradle default isbuild/reports/tests. - In CI, verify that the job uploads the same directory Selenide writes to.
A named screenshot is missing
- Ensure the test reaches the
screenshot("name")call; an earlier assertion or exception prevents later code from running. - Check the working directory and report configuration when locating the generated artifact.
- Remember that the named screenshot method’s PNG capture is separate from the automatic
screenshotssetting.
The element image disappears after the test
The returned file may be temporary. Copy it into a durable report folder or consume its bytes before test cleanup, as noted in the Screenshots API.
MHTML was not created
- Enable
savePageSourceWithResourcesin Configuration or with its system property. - Use Chromium for the documented CDP-backed MHTML capture.
- If CDP is unavailable or capture fails, expect plain HTML fallback rather than a broken test, as documented in the 7.18.0 release notes.
Or skip the browser setup
If your goal is a screenshot of a URL rather than an in-test browser assertion, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return an image or PDF. For example:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents use tools for screenshots and page information. The free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000 shots. That makes it a different fit from Selenide: use Selenide to test application behavior in your Java suite, or an API when you need a URL capture without setting up a browser test.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
Screenshot capture is not visual comparison
A generated image is an artifact to inspect; it is not by itself a pass/fail comparison against a baseline. The cited Selenide documentation describes screenshot creation and artifacts, but does not establish built-in pixel comparison or a current visual-regression plugin recommendation. If you need visual regression testing, choose and configure a separate baseline comparison workflow rather than treating capture as comparison.
Frequently Asked Questions
Can Selenide return a screenshot as data instead of writing a file?
Yes. The Selenide API describes requested return forms including bytes, Base64, and a temporary file; use the overload supported by your project’s Selenide version.
Can Selenide take screenshots?
Yes. Its official FAQ includes this question, and the screenshot guide documents automatic failure captures and explicit screenshot calls.
Quick Recap
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.

