Overview
Capture a screenshot of the screen. TestDriver saves it to a local file automatically. TestDriver groups the screenshots by test file. This makes debug and review easy.Automatic Screenshots: TestDriver can capture screenshots automatically before and after each command (click, type, find, and more). It saves them with clear filenames such as
001-click-before-L42-submit-button.png. The filename includes the line number from your test file. Enable this with autoScreenshots: true in your TestDriver options.Syntax
Parameters
string
A custom filename for the screenshot (without the .png extension). If you do not give one, TestDriver makes a filename from the timestamp automatically.
Returns
Promise<string> - The absolute file path where TestDriver saved the screenshot
File Organization
TestDriver saves screenshots automatically to.testdriver/screenshots/<test-file-name>/ in your project root:
Automatic Screenshot Naming
WhenautoScreenshots 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:error instead of after.
Best Practices
Let automatic screenshots do the work
Let automatic screenshots do the work
With
autoScreenshots: true, 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

