Visual Regression Testing
FlutterProbe includes screenshot-based visual regression testing that compares current screenshots against baseline images to detect unintended visual changes.
How It Works
Section titled “How It Works”- Baseline capture — On the first run, screenshots are saved as baseline images
- Comparison — On subsequent runs, new screenshots are compared pixel-by-pixel against the baselines
- Diff reporting — If the difference exceeds the configured threshold, the test fails with a visual diff
Taking Screenshots
Section titled “Taking Screenshots”Use the take screenshot command in your tests:
test "checkout page looks correct" open the app tap "Cart" tap "Checkout" wait for the page to load take screenshot "checkout_page"Screenshots are saved as PNG files in the reports/screenshots/ directory.
Comparing Screenshots
Section titled “Comparing Screenshots”compare screenshot is the verb that actually runs the regression check. The first run
establishes the baseline; every later run compares against it and fails the step when the diff
exceeds the configured threshold:
test "checkout page has not changed" tap "Checkout" wait for the page to load compare screenshot "checkout_page"Element-scoped comparison
Section titled “Element-scoped comparison”Add of <selector> to crop the comparison to one widget’s on-screen bounds — both the baseline
and every later actual image are just that widget’s region, not the full screen. Useful when the
rest of the screen legitimately changes (timestamps, feeds) but one component must stay
pixel-stable:
compare screenshot "total_price" of "Total"compare screenshot "avatar" of #profile_avatarFailed comparisons write a diff image to reports/visual-diff/ showing exactly which pixels
changed.
Configuration
Section titled “Configuration”Threshold
Section titled “Threshold”The maximum allowed pixel difference as a percentage. If the diff exceeds this value, the test fails.
visual: threshold: 0.5 # 0.5% — defaultOr via CLI flag:
probe test tests/ --visual-threshold 0.5Pixel Delta
Section titled “Pixel Delta”The per-pixel color delta tolerance. Small differences (e.g., anti-aliasing) below this value are ignored.
visual: pixel_delta: 8 # defaultOr via CLI flag:
probe test tests/ --visual-pixel-delta 8Typical Workflow
Section titled “Typical Workflow”- Create baseline — Run tests the first time to capture baseline screenshots
- Make changes — Update your app UI
- Run tests — Visual regression detects differences against the baseline
- Review diffs — Check if changes are intentional
- Update baseline — If changes are expected, re-run to update the baselines
- Use a consistent device/simulator for baselines (different screen sizes produce different screenshots)
- Set a reasonable threshold — too low causes false positives from rendering differences, too high misses real regressions
- Run visual regression tests on a single platform first, then expand
- Screenshots are captured by the Dart agent directly (no external tools needed)