Skip to main content

Overview

TestDriver can capture screenshots manually at any point during a test, or automatically before and after every command. Screenshots are saved to a structured directory for easy debugging.

Manual Screenshots

Use testdriver.screenshot() to capture the current screen:

Options

string
Custom filename for the screenshot. .png is appended automatically if missing. If omitted, defaults to screenshot-<timestamp>.png.
Returns: Promise<string> — the absolute file path of the saved screenshot.

Auto Screenshots

Enable automatic screenshots before and after every command:
boolean
default:false
When true, captures a screenshot before and after every SDK command (click, type, find, scroll, hover, pressKeys, assert, exec, etc.). On error, an error-phase screenshot replaces the after-phase screenshot.

Filename Format

Auto-screenshots follow this naming convention:
Examples:

Phases

Screenshot Directory

Screenshots are saved to:
Where <testFileName> is the test file name without its extension. For example, a test at tests/login.test.mjs saves screenshots to .testdriver/screenshots/login.test/.

Directory Cleanup

The screenshot directory for each test file is automatically cleaned at the start of a test run. This happens once per process per test file to prevent concurrent tests from the same file from interfering with each other.

Debug Screenshots

Elements have a saveDebugScreenshot() method for debugging element detection:
This saves the screenshot that was captured during the find() call, which can be useful for understanding what the AI “saw” when locating the element.

Complete Example

After running, your screenshot directory will contain: