Overview
Playwright provides powerful visual comparison capabilities to detect visual regressions. Compare screenshots pixel-by-pixel to ensure your UI remains consistent across changes.Screenshot Assertions
ThetoHaveScreenshot() assertion compares screenshots and highlights differences.
Screenshot Options
Customize screenshot behavior with various options.Comparison Thresholds
Control the sensitivity of visual comparisons.Animation Handling
Handle animations and transitions in screenshots.Multi-Page Screenshots
Compare screenshots across different page states.Page State Comparisons
Viewport Variations
Test visual consistency across different viewport sizes.Dark Mode Testing
Compare screenshots in both light and dark themes.Theme Comparisons
Update Snapshots
Update baseline screenshots when changes are intentional.Cross-Browser Screenshots
Ensure visual consistency across different browsers.playwright.config.ts
Diff Output
Playwright generates diff images when screenshots don’t match.Understanding Diff Images
Manual Screenshot Capture
Capture screenshots programmatically for custom comparisons.Configuration
Configure screenshot defaults globally.playwright.config.ts
Best Practices
Mask Dynamic Content
Always mask timestamps, user-specific data, and ads that change frequently.
Wait for Stability
Ensure page is fully loaded and stable before taking screenshots. Wait for network idle.
Appropriate Thresholds
Set reasonable thresholds - too strict causes false positives, too loose misses issues.
Organized Snapshots
Use descriptive names and organize snapshots by feature or component.
Related Resources
Screenshots
Learn more about screenshot capabilities
Visual Debugging
Debug visual test failures effectively
