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.
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.
// Save with a descriptive filenameawait testdriver.screenshot("login-page");// Saves to: .testdriver/screenshots/<test>/login-page.pngawait testdriver.screenshot("after-click");// Saves to: .testdriver/screenshots/<test>/after-click.png
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
Take a screenshot before making assertions. If the assertion fails, you’ll have a visual record of what the screen looked like.
Copy
await testdriver.screenshot();const result = await testdriver.assert("checkout button is visible");
Add to .gitignore
Add .testdriver/screenshots/ to your .gitignore to avoid committing screenshots to version control: