Skip to main content

Overview

TestDriver can capture screenshots by hand at any point during a test. It can also capture them automatically before and after each command. TestDriver saves the screenshots to a structured directory. This makes debug easy.

Manual Screenshots

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

Options

string
A custom filename for the screenshot. TestDriver adds .png automatically if it is not there. If you do not give this, the default is 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: