Skip to main content

Overview

Capture a screenshot of the current screen and automatically save it to a local file. Screenshots are organized by test file for easy debugging and review.
Automatic Screenshots: TestDriver can automatically capture screenshots before and after every command (click, type, find, etc.). These are saved with descriptive filenames like 001-click-before-L42-submit-button.png that include the line number from your test file. Enable this with autoScreenshots: true in your TestDriver options.

Syntax

Parameters

string
Custom filename for the screenshot (without .png extension). If not provided, a timestamp-based filename is generated automatically.

Returns

Promise<string> - The absolute file path where the screenshot was saved

File Organization

Screenshots are automatically saved to .testdriver/screenshots/<test-file-name>/ in your project root:

Automatic Screenshot Naming

When autoScreenshots is enabled, filenames follow this format: <seq>-<action>-<phase>-L<line>-<description>.png
The screenshot folder for each test file is automatically cleared when the test starts. This ensures you only see screenshots from the most recent test run.

Examples

Basic Screenshot

Custom Filename

Debugging with Screenshots

Automatic Screenshots

By default, TestDriver captures screenshots automatically before and after every command. This creates a complete visual timeline of your test execution without any additional code.

Enabling/Disabling

What Gets Captured

Automatic screenshots are taken around these commands:
  • find() / findAll()
  • click() / hover() / doubleClick() / rightClick()
  • type() / pressKeys()
  • scroll()
  • waitForText() / waitForImage()
  • focusApplication()
  • assert() / extract() / exec()

Example Output

For this test code:
TestDriver automatically saves:
If an error occurs, the phase will be error instead of after.

Best Practices

With autoScreenshots: true, you get comprehensive coverage without adding manual screenshot() calls. Only add manual screenshots for specific named checkpoints.
When a test fails intermittently, add screenshots at key steps to capture the actual screen state. This helps identify timing issues or unexpected UI states.
Take a screenshot before making assertions. If the assertion fails, you’ll have a visual record of what the screen looked like.
Add .testdriver/screenshots/ to your .gitignore to avoid committing screenshots to version control:

Viewing Saved Screenshots

After saving screenshots during test execution, you can view them using TestDriver MCP commands. This is especially useful for debugging failed tests or verifying test behavior.

MCP Commands for Screenshot Viewing

List all saved screenshots:
View a specific screenshot:
These commands allow you to:
  • View screenshots from failed tests to understand what went wrong
  • Review test execution flow by examining screenshots in chronological order
  • Compare screenshots across test runs to identify flaky behavior
For detailed workflows and examples of using these MCP commands for debugging, see the Debugging with Screenshots guide.