Visual Testing
Detect visual regressions and UI changes with automatic screenshot comparison.
Visual Testing
Visual testing compares screenshots between runs to detect unexpected UI changes. Catch CSS regressions, layout shifts, and missing elements automatically.
How It Works
- Baseline - First successful run establishes the baseline screenshot
- Compare - Subsequent runs compare against the baseline
- Diff - Pixel differences are calculated as a percentage
- Alert - If diff exceeds threshold, an alert is triggered
Enabling Visual Testing
Visual testing is enabled per-journey:
- Go to your journey settings
- Enable Visual Testing
- Set the Diff Threshold (default: 5%)
Journey Settings:
Visual Testing: enabled
Diff Threshold: 5%
Full Page Capture: trueDiff Threshold
The diff threshold determines how much change triggers an alert:
| Threshold | Use Case |
|---|---|
| 1-2% | Pixel-perfect requirements |
| 5% | Normal web applications |
| 10% | Dynamic content, ads |
| 20%+ | Major layout changes only |
Start with a higher threshold (10%) and lower it as you identify acceptable variation in your application.
Understanding Visual Diffs
When a visual diff is detected, you'll see:
- Baseline Image - The expected appearance
- Current Image - What the page looks like now
- Diff Image - Highlighted differences (usually in pink/red)
- Diff Percentage - Numerical difference
Types of Changes Detected
| Change Type | Example | Typical Diff |
|---|---|---|
| Text change | Different heading | 2-5% |
| Color change | Button color update | 1-3% |
| Layout shift | Element moved | 5-20% |
| Missing element | Deleted component | 10-30% |
| New element | Added banner | 5-15% |
| Font change | Different font family | 3-10% |
Managing Baselines
Viewing Current Baseline
- Go to your journey
- Click Visual Testing tab
- View the current baseline image
Updating Baseline
When an intentional UI change occurs:
- Review the failed run
- Verify the change is expected
- Click Promote to Baseline
This sets the new screenshot as the baseline for future comparisons.
Automatic Baseline Updates
You can configure automatic baseline updates:
Visual Testing:
Auto-update Baseline: true
After: 3 consecutive matchesThis promotes a new baseline after consistent results, useful for frequently changing pages.
Screenshot Configuration
Full Page vs Viewport
| Mode | Description | Best For |
|---|---|---|
| Viewport | Captures visible area only | Above-the-fold content |
| Full Page | Captures entire scrollable page | Complete page verification |
Specific Element Capture
Target specific elements instead of full page:
Visual Testing:
Target Selector: .main-content
Ignore Selectors:
- .dynamic-timestamp
- .ad-banner
- .user-avatarIgnoring Dynamic Content
Exclude elements that change between runs:
Ignore Regions:
- selector: .current-time
- selector: .random-ad
- selector: .live-counter
- area: { x: 0, y: 0, width: 200, height: 50 } # Header areaAlert Rules for Visual Testing
Create alert rules specifically for visual changes:
Alert Rule:
Name: Visual Regression Alert
Type: visual_diff
Threshold: 5%
Channels:
- Slack (#design-alerts)
- Email ([email protected])Alert Conditions
| Condition | Description |
|---|---|
diff_exceeds | Alert when diff % exceeds threshold |
any_change | Alert on any visual difference |
element_missing | Alert when specific element not found |
Best Practices
1. Use Stable Selectors
Target stable elements, not dynamic content:
# Good - specific component
Target: [data-testid="product-grid"]
# Bad - includes dynamic content
Target: body2. Set Appropriate Thresholds
Match threshold to your use case:
- E-commerce product pages: 5% (images may vary)
- Documentation pages: 2% (should be stable)
- Dashboards with live data: 15% (expect variation)
3. Exclude Known Dynamic Elements
Ignore Selectors:
- .timestamp
- .live-visitor-count
- .ad-container
- .chat-widget4. Run at Consistent Times
Schedule visual tests during low-activity periods to reduce variance:
Schedule: 0 3 * * * # 3 AM daily5. Use Consistent Viewport Sizes
Set explicit viewport dimensions:
Viewport:
Width: 1280
Height: 720Troubleshooting
High False Positive Rate
Problem: Alerts triggering for acceptable changes
Solutions:
- Increase diff threshold
- Add ignore selectors for dynamic content
- Use element-specific capture instead of full page
Missing Important Changes
Problem: UI bugs not being caught
Solutions:
- Lower diff threshold
- Capture full page instead of viewport
- Add specific assertions for critical elements
Baseline Drift
Problem: Baseline gradually becomes outdated
Solutions:
- Manually review and update baselines periodically
- Set up baseline review schedule
- Use automatic baseline updates cautiously
Visual testing works best as a complement to functional testing. Use journeys to verify functionality and visual testing to catch unexpected UI changes.
Visual Testing vs Snapshot Testing
| Aspect | Visual Testing | Snapshot Testing |
|---|---|---|
| What's compared | Rendered pixels | DOM/HTML structure |
| Catches | Visual bugs, CSS issues | Markup changes |
| False positives | Higher (anti-aliasing, fonts) | Lower |
| Setup | Screenshot capture | Component rendering |
| Best for | End-to-end appearance | Component structure |
tracer uses visual (pixel) testing for the most accurate representation of what users see.