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 inplaywright.config.ts:
Video Recording
Configure Video Recording
Enable video recording in your configuration:Video Recording Options
1
Always record
2
Record failures only
3
Record on retry
4
Never record
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
- 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
