Skip to main content

Overview

Playwright can capture screenshots and record videos of your tests, providing visual evidence of test execution and helping debug failures.

Screenshots

Full Page Screenshot

Capture a screenshot of the entire page:

Element Screenshot

Capture a screenshot of a specific element:

Screenshot Options

Visual Regression Testing

Compare Screenshots

Playwright includes built-in visual comparison:

Update Baseline Screenshots

When intentional UI changes are made, update baselines:

Configure Visual Comparison

Customize comparison tolerance in playwright.config.ts:

Video Recording

Configure Video Recording

Enable video recording in your configuration:

Video Recording Options

1

Always record

Records video for all tests.
2

Record failures only

Only keeps videos of failed tests.
3

Record on retry

Records when tests are retried.
4

Never record

Disables video recording.

Access Video Path

Get the video path programmatically:

Screenshot on Failure

Automatic Screenshots

Configure automatic screenshots for failed tests:

Custom Failure Handler

Implement custom screenshot logic:

Artifacts Location

Configure where screenshots and videos are saved:

Practical Examples

Debug Failed Tests

Visual Testing Workflow

Hide Dynamic Content

CI/CD Integration

Store artifacts in CI pipelines for easy access:

Best Practices

Selective Recording: Use retain-on-failure for videos to save disk space while still capturing failures.
  • Use visual regression for stable UIs: Only apply visual testing to components with predictable rendering
  • Mask dynamic content: Hide timestamps, ads, and random content to reduce false positives
  • Set appropriate tolerances: Configure pixel difference thresholds based on your needs
  • Store artifacts in CI: Upload screenshots and videos to CI artifacts for easy debugging
  • Clean up old artifacts: Implement retention policies to manage disk space
Video recording increases test execution time and storage requirements. Use it judiciously in CI/CD pipelines.

Troubleshooting

Screenshots appear blank

Wait for content to load before capturing:

Visual comparison failing unexpectedly

Increase tolerance or update baselines:

Videos not being saved

Ensure video path is accessible and verify configuration: