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 (Default: Enabled): TestDriver automatically captures 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. You can disable this with autoScreenshots: false in your TestDriver options.Syntax
Parameters
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
WhenautoScreenshots is enabled (default), filenames follow this format:
<seq>-<action>-<phase>-L<line>-<description>.png
| Component | Description | Example |
|---|---|---|
seq | Sequential number (001, 002, …) | 001 |
action | Command name | click, type, find |
phase | Before, after, or error | before, after |
L<line> | Line number from test file | L42 |
description | Element description or action target | submit-button |
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()/scrollUntilText()/scrollUntilImage()waitForText()/waitForImage()focusApplication()assert()/extract()/exec()
Example Output
For this test code:error instead of after.
Best Practices
Let automatic screenshots do the work
Let automatic screenshots do the work
With
autoScreenshots: true (default), you get comprehensive coverage without adding manual screenshot() calls. Only add manual screenshots for specific named checkpoints.Use screenshots for debugging flaky tests
Use screenshots for debugging flaky tests
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.
Capture before assertions
Capture before assertions
Take a screenshot before making assertions. If the assertion fails, you’ll have a visual record of what the screen looked like.
Add to .gitignore
Add to .gitignore
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 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.
Related
- Debugging with Screenshots - View and analyze saved screenshots using MCP
- assert() - Make AI-powered assertions
- find() - Locate elements on screen

