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

Yes—Selenide captures screenshots automatically when a Selenide check fails. In the current Configuration API, screenshot capture is enabled by default, and failure artifacts normally go to build/reports/tests. You can configure that directory, take named page or element screenshots at deliberate checkpoints, add JUnit or TestNG lifecycle hooks, and preserve HTML or Chromium MHTML alongside the image for diagnosis.

This guide shows a complete Java workflow, explains which capture route fits each test, and covers CI artifacts, temporary files, browser limitations, and common failures. The API pages cited here identify Selenide 7.18.2; use the version selected by your project and verify examples against that dependency.

What Selenide screenshot testing does

Selenide is a Java browser-automation library. Its normal test flow is to open a page, interact with elements, and check conditions. When a Selenide assertion fails, the framework automatically saves a screenshot and page source for troubleshooting. The official guide states that this happens on every test failure, while the current Configuration API documents screenshots as enabled by default.

Automatic capture is diagnostic evidence, not visual-baseline comparison. The reviewed Selenide documentation explains how to create and store screenshots, but does not document built-in pixel comparison or establish a current visual-regression plugin recommendation. If you need baseline diffs, choose and configure a separate visual-testing workflow.

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

Choose the right capture route

Route Use it when Important behavior
Automatic failure capture You need evidence when a Selenide check fails Controlled by Configuration.screenshots; enabled by default
JUnit 4, JUnit 5, or TestNG integration You also want successful-test captures or captures for assertions outside Selenide Hooks into the test-framework lifecycle
Selenide.screenshot("name") You want a deliberate checkpoint during a test Creates a named PNG even when automatic screenshots are disabled; may also save page source
Element screenshot API Only a component matters Captures an element; returned files can be temporary
Chromium MHTML page source You need markup with embedded page resources Requires savePageSourceWithResources; unsupported cases fall back to HTML

Set up a Java test

Add dependencies

Add Selenide and your selected test framework to the project using the versions already managed by your build. Do not copy a version number from an unrelated example into a project with a dependency-management policy. A minimal JUnit 5 test has the following shape:

import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Condition.*;

import org.junit.jupiter.api.Test;

class CheckoutTest {
  @Test
  void checkoutPageLoads() {
    open("https://example.com/checkout");
    $("h1").shouldHave(text("Checkout"));
  }
}

When the condition fails, Selenide writes the screenshot and page-source artifacts into its reports directory. Replace the URL and selectors with those used by your application; the example deliberately makes no assumption about a particular site.

Configure where artifacts are written

For Gradle projects, the documented default reports location is build/reports/tests. Set a stable directory when your CI uploader expects another path.

Java configuration

import com.codeborne.selenide.Configuration;

class SelenideConfig {
  static {
    Configuration.reportsFolder = "test-result/reports";
    Configuration.screenshots = true;
    Configuration.savePageSource = true;
  }
}

Load this class before tests start, or place the assignments in your test-suite setup. The same settings are available as system properties:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
./gradlew test 
  -Dselenide.reportsFolder=test-result/reports 
  -Dselenide.screenshots=true 
  -Dselenide.savePageSource=true

Configuration.reportsUrl can prefix artifact links with a CI report URL when your reporting system exposes one. Selenide stores files; it does not, by itself, upload them to your CI service. Configure the CI platform’s artifact-upload step separately.

Take a named screenshot at a checkpoint

Use the Selenide API when a screenshot is part of the test’s intended evidence, not merely a failure side effect.

import static com.codeborne.selenide.Selenide.*;

@Test
void captureAfterApplyingFilter() {
  open("https://example.com/catalog");
  $("button[data-filter='available']").click();
  $("[data-testid='results']").shouldBe(visible);

  Selenide.screenshot("catalog-available");
}

The call creates catalog-available.png. Depending on configuration, Selenide can also save .html or, in Chromium with page-source-with-resources enabled, .mhtml. The named PNG is created even if Configuration.screenshots is false. The API can return a capture as bytes, Base64, or a temporary file when your code needs to process it immediately.

Use an element screenshot

The current Screenshots API documents page and element capture, including iframe-aware methods. Element capture is useful for a card, table, or chart rather than the entire viewport. Treat the returned file as temporary: copy it to your reports directory or consume it before the test process cleans temporary storage.

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.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

var temporary = $("[data-testid='summary-card']").screenshot();
if (temporary != null) {
  Files.copy(temporary.toPath(), Path.of("test-result/reports/summary-card.png"));
}

Check the exact return type and overload for your selected Selenide version before compiling; the API offers file and image forms and iframe-aware variants.

Capture successful tests and non-Selenide failures

Automatic screenshots are tied to Selenide checks. If a team wants a capture after every successful test, or when a general JUnit assertion fails outside a Selenide condition, add the framework integration documented in the Selenide screenshots guide.

JUnit 5

import com.codeborne.selenide.junit5.ScreenShooterExtension;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(ScreenShooterExtension.class)
class AccountTest {
  // tests
}

The guide also shows a configurable registration such as new ScreenShooterExtension(true).to("target/screenshots"). Confirm the constructor and registration syntax against the Selenide and JUnit versions in your build.

JUnit 4 and TestNG

For JUnit 4, the guide documents a ScreenShooter rule. For TestNG, it documents a ScreenShooter listener. These hooks are appropriate when the framework lifecycle—not only a Selenide assertion—should trigger capture. Keep one lifecycle strategy per suite unless you intentionally want multiple artifacts.

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

Preserve page source, including Chromium MHTML

Screenshots show pixels; page-source artifacts help explain missing markup, scripts, or resources. Configuration.savePageSource defaults to true. Set Configuration.savePageSourceWithResources = true, or pass -Dselenide.savePageSourceWithResources=true, when you need a Chromium MHTML snapshot with page resources embedded.

import com.codeborne.selenide.Configuration;

Configuration.savePageSource = true;
Configuration.savePageSourceWithResources = true;

Selenide 7.18.0 release notes explain that this capture uses Chrome DevTools Protocol’s Page.captureSnapshot. If the browser is not Chromium, CDP is unavailable, or capture fails, Selenide falls back to ordinary HTML rather than breaking the test. MHTML is therefore a Chromium-specific enhancement, not a portable artifact guarantee.

Make screenshots useful in CI

  1. Choose a deterministic directory such as test-result/reports with reportsFolder.
  2. Run tests with screenshots and page source enabled.
  3. Configure the CI system to upload that directory after tests, including when the test command exits non-zero.
  4. Set reportsUrl only if your report server has a stable URL prefix for those files.
  5. Retain named checkpoint images only where they answer a diagnostic question; otherwise automatic failure artifacts keep storage smaller.

Use stable viewport, browser, timezone, locale, and test data settings in your own runner when comparing captures across builds. Selenide’s screenshot feature creates artifacts; environmental consistency and any pixel-diff policy belong to the surrounding test workflow.

Troubleshooting common problems

No screenshot after a failure

  • Cause: Screenshots were disabled or the failure occurred outside a Selenide check.
  • Fix: Set Configuration.screenshots = true (or -Dselenide.screenshots=true), and use the JUnit/TestNG integration for framework-level failures.

Files are in an unexpected directory

  • Cause: The default is build/reports/tests for Gradle projects, or a system property overrides your Java assignment.
  • Fix: Set Configuration.reportsFolder or -Dselenide.reportsFolder=... once in suite setup and print the resolved path in CI diagnostics.

The named screenshot is missing page source

  • Cause: Page-source saving is disabled, or resource embedding was not enabled.
  • Fix: Enable savePageSource. Enable savePageSourceWithResources only when Chromium MHTML is required; otherwise expect HTML.

An element capture disappears

  • Cause: The element API returned a temporary file.
  • Fix: Copy it immediately to a CI-published directory or read it into your processing pipeline before cleanup.

MHTML is not produced

  • Cause: The browser is non-Chromium, CDP is unavailable, or snapshot capture failed.
  • Fix: Use Chromium with compatible driver support, then inspect the HTML fallback; Selenide is designed to continue with plain HTML.

Artifacts exist locally but not in CI

  • Cause: The CI job does not upload the configured directory, or upload runs only after a successful command.
  • Fix: Add an always-run artifact step pointing to the exact reportsFolder path.
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 you need a rendered image from a URL rather than an in-process Java test, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—work with Claude, Cursor, and other MCP clients.

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

One GET request is enough:

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 all options, including full-page and element capture, device and viewport settings, custom CSS or JavaScript, waits, request blocking, headers and cookies, geolocation, PDF output, resizing, caching, signed links, asynchronous jobs, bulk capture, usage, and the OpenAPI specification.

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan, and yearly billing gives two months free. Create a free ScreenshotNeo account to get an API key.

FAQ

Can I disable automatic screenshots but keep named captures?

Yes. The named Selenide.screenshot("name") call creates its PNG even when Configuration.screenshots is false.

Does a screenshot prove that a page is visually correct?

No. It records the rendered state. A pass/fail visual baseline comparison requires a separate comparison workflow.

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

Which artifact should I inspect first?

Open the PNG to see the visible failure, then inspect HTML or Chromium MHTML when you need DOM and resource context.

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.