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

Use Robot Framework’s ${TEST NAME} variable as the identity portion of the filename, call Capture Page Screenshot from a failure teardown or failure hook, and add SeleniumLibrary’s {index} token for uniqueness. A practical filename is ${TEST NAME}_FAILURE_{index}.png. The index starts at 1 and prevents repeated captures from overwriting one another.

The recommended SeleniumLibrary pattern

A test teardown is the simplest place to capture one screenshot only when the test has failed. The teardown runs after the test body, while Run Keyword If Test Failed prevents successful tests from producing an artifact.

*** Settings ***
Library    SeleniumLibrary
Test Teardown    Capture Failure Screenshot

*** Keywords ***
Capture Failure Screenshot
    Run Keyword If Test Failed    Capture Page Screenshot    ${TEST NAME}_FAILURE_{index}.png

Capture Page Screenshot accepts the filename as its argument. When no screenshot directory is configured, SeleniumLibrary writes the file beside the Robot Framework log. The keyword returns the absolute path of the file, which can be logged or passed to another keyword if your pipeline needs it.

What each filename component does

  • ${TEST NAME}: identifies the Robot Framework test case that produced the artifact.
  • _FAILURE: makes the purpose obvious when logs contain many images.
  • {index}: is expanded by SeleniumLibrary to a running number beginning at 1. Use it whenever a retry, a teardown, or a run-on-failure hook could capture more than once.
  • .png: keeps the output in a lossless, broadly supported format.

Capture after every failed SeleniumLibrary keyword

A teardown gives you one final-state image. If you need an image immediately after any failed SeleniumLibrary keyword, configure SeleniumLibrary’s run-on-failure mechanism instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
*** Settings ***
Library    SeleniumLibrary    run_on_failure=Capture Page Screenshot

The default run-on-failure keyword is Capture Page Screenshot. To force a test-name-based filename, register a wrapper keyword and have that wrapper supply the name:

*** Settings ***
Library    SeleniumLibrary
Suite Setup    Configure Failure Hook

*** Keywords ***
Configure Failure Hook
    Register Keyword To Run On Failure    Capture Named Failure Screenshot

Capture Named Failure Screenshot
    Capture Page Screenshot    ${TEST NAME}_FAILURE_{index}.png

This hook can run more than once in a single test, so retaining {index} is important. It also captures the page at the point of the failed SeleniumLibrary operation, rather than only at teardown.

Choose the capture trigger deliberately

Trigger Best use Trade-off Naming guidance
Test teardown One diagnostic image of the final page state Does not show earlier failed steps ${TEST NAME}_FAILURE_{index}.png
Run-on-failure Immediate evidence after failed SeleniumLibrary keywords Several images may be produced for one test Always include {index}
Explicit screenshot keyword A known checkpoint or a manually selected state Requires test authors to call it Use the test name plus a step marker

Keep names valid on every CI agent

Robot test names can contain spaces and punctuation that are harmless in a log but invalid in a filesystem name. Before passing a test-derived value to the screenshot keyword, apply one consistent sanitization policy for all agents.

  • Replace path separators, colons, quotes, wildcard characters, control characters and other OS-reserved symbols with an underscore.
  • Collapse repeated underscores if that improves readability, and trim trailing spaces or periods for Windows workers.
  • Preserve enough of the original name to identify the test; do not silently reduce every name to a generic value.
  • Keep the failure marker and index outside the sanitized portion so filtering remains predictable.

The SeleniumLibrary documentation specifies filename handling and indexing, but it does not prescribe a universal sanitization algorithm. The correct replacement set depends on the operating systems and artifact store used by your project, so test the policy on each CI image.

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.

Prevent overwrites and make artifacts easy to collect

A fixed name such as checkout_FAILURE.png is deterministic but unsafe when a test can produce multiple captures. Add {index} unless you can prove that exactly one capture is possible. The counter starts at 1, making the first image easy to recognize as ..._1.png.

Store screenshots in a dedicated CI artifact directory rather than relying on the working directory. If you leave SeleniumLibrary’s screenshot directory unset, its default is the directory containing the Robot Framework log. A dedicated location keeps screenshots separate from source files and makes artifact collection rules simple.

For Robot Framework’s built-in Screenshot library, set screenshot_directory when importing the library or use Set Screenshot Directory. Its default is also the log directory. Apply the same naming policy when calling Take Screenshot.

Browser library alternative

Robot Framework Browser documents a failure-screenshot convention using ${TEST NAME}_FAILURE_SCREENSHOT_{index}. Its Take Screenshot keyword can be registered as the failure handler with a custom prefix. The same rules still apply: derive identity from the test name, include a visible failure token and retain an index when more than one capture is possible.

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

Common failures and fixes

The filename contains the literal ${TEST NAME}

Check that the value is written with Robot Framework’s scalar syntax, exactly ${TEST NAME}, and that the filename is passed as a separate argument to the screenshot keyword. A misspelled variable or a variable written with shell-style syntax will not expand.

Images overwrite one another

Add {index} to the filename. This is especially necessary with run-on-failure hooks, retries, nested keywords that fail more than once, or a teardown that can be invoked after another capture.

The file is created somewhere unexpected

Look at the output directory containing log.html first; that is SeleniumLibrary’s default when no screenshot directory is configured. Then set one dedicated directory in the library or CI configuration and collect that directory as an artifact.

A name works locally but fails in CI

The test name probably contains characters rejected by the CI runner’s operating system or artifact backend. Sanitize separators and reserved characters before constructing the filename, and test with the same operating systems used in the pipeline.

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

There are too many screenshots

Run-on-failure captures after every failed SeleniumLibrary keyword. Use a teardown when one final image is sufficient, or make the failure wrapper conditional so it captures only the states that help diagnose the failure.

The screenshot shows the wrong state

A teardown captures the page after the test body has finished. Register a run-on-failure handler when timing matters and you need the page immediately after the failing browser operation.

Operational notes for CI

  • Runtime: screenshots add browser and disk work. Capturing only failed tests keeps successful runs fast; run-on-failure provides richer evidence at the cost of potentially more files.
  • Retention: retain failure images with the matching Robot log and output XML so the test name and index remain useful after parallel jobs finish.
  • Parallel execution: give each worker its own output directory or include a worker-specific directory in the CI artifact path. The index solves repeated captures in one output location; it is not a substitute for isolating parallel workers.
  • Security: screenshots can contain customer data, tokens rendered in pages or personal information. Restrict artifact access and apply the same retention policy as your test logs.
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 screenshot of a publicly reachable URL rather than the exact live state of a Selenium session, ScreenshotNeo provides a website screenshot API and MCP server. It accepts a URL in one request and returns PNG, JPEG, WebP or PDF. It is not a replacement for a screenshot of an authenticated, in-progress browser session, but it is useful for URL-level checks and agent workflows.

ScreenshotNeo removes cookie and consent banners, newsletter popups and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

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

cURL

See the ScreenshotNeo API documentation for the request options.

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

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
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}`);

Plans and limits

Plan Included shots per month Price
Free 1,000 $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Every feature is available on every plan, and yearly billing provides two months free. Options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets, arbitrary viewports, retina scale, PDF paper and page controls, HTML/CSS rendering, custom JavaScript and CSS, clicks before capture, hidden selectors, selector or network-idle waits, request and resource blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API and an OpenAPI specification.

Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Frequently Asked Questions

Can I use this naming scheme for screenshots taken during a passing test?

Yes. Keep the test-name component, but replace the failure marker with a state or checkpoint label such as _CHECKOUT_STEP so passing and failing artifacts cannot be confused.

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

Can ScreenshotNeo capture the exact page state held by my Selenium driver?

No. ScreenshotNeo requests the URL independently. You can provide supported headers or cookies for a remote request, but it does not attach to an existing local browser session.

Is a dedicated output directory required?

No. SeleniumLibrary and the built-in Screenshot library use the Robot log directory by default, but a dedicated CI artifact directory is easier to collect and retain.

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.