Skip to content

Commit f9ae0cf

Browse files
pftgclaude
andcommitted
docs: rewrite README with value-first positioning and Web UI section
- Opening line sells outcome ("Stop shipping UI bugs") with competitive positioning vs Percy/Chromatic/BackstopJS - Renamed "HTML Reporter" to "Web UI for Reviewing Screenshot Changes" with GitHub Actions PR comment integration shown inline - Promoted Web UI to its own section (was buried in 1 line) - Replaced tuning table with single configure block - Reframed Troubleshooting as "Common Questions" - Added Diff.compare usage showing actual return API - Folded ruby-vips into Quick Start Gemfile Based on 3-reviewer brutal honesty review (Rails dev, DevOps, OSS maintainer). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f5aa3ef commit f9ae0cf

2 files changed

Lines changed: 52 additions & 45 deletions

File tree

README.md

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
# Capybara::Screenshot::Diff
66

7-
Catch visual regressions before they ship. Screenshots taken during tests are automatically compared against committed baselines — if the UI changed, the test fails.
7+
Stop shipping UI bugs. Take screenshots in your Rails tests, commit baselines to git, and let CI catch visual regressions in pull requests — no cloud service, no subscription, runs entirely in your test suite.
8+
9+
**Why this gem?** Percy and Chromatic cost money and send your screenshots to a third party. BackstopJS requires Node. This gem integrates directly into your Capybara tests, stores baselines in git, and works offline.
810

911
## Quick Start
1012

1113
```ruby
1214
# Gemfile
1315
gem 'capybara-screenshot-diff'
16+
gem 'ruby-vips' # Optional: 10x faster comparisons
1417
```
1518

1619
```ruby
@@ -42,104 +45,108 @@ git commit -m "chore: add screenshot baselines"
4245
bundle exec rake test # Second run compares against committed baselines
4346
```
4447

45-
That's it. The first run saves baseline screenshots (always passes). Subsequent runs compare against them — if the UI changed, the test fails. Commit baselines to git so CI catches regressions.
48+
First run saves baseline screenshots to `doc/screenshots/` (always passes). Commit them to git. Subsequent runs compare against committed baselines — if the UI changed, the test fails.
4649

47-
> **CI note:** In CI, `fail_if_new` is `true` by default — new screenshots without a committed baseline will fail. Always commit your baselines before pushing.
50+
> **CI note:** `fail_if_new` is `true` by default in CI — new screenshots without a committed baseline will fail. Always commit baselines before pushing.
4851
4952
For RSpec, Cucumber, or non-Rails setup, see [Framework Setup](docs/framework-setup.md).
5053

51-
## What You Get
54+
## What Happens When a Screenshot Changes
5255

53-
When a screenshot differs, the test fails with a clear message:
56+
The test fails with a clear message and generates diff files:
5457

5558
```text
5659
Screenshot does not match for 'homepage':
5760
({"area_size":1250,"region":[0,19,199,83],"max_color_distance":42.5})
5861
```
5962

60-
And generates diff files for inspection:
63+
Open `doc/screenshots/homepage.diff.png` to see exactly what changed. If the change is intentional, delete the baseline and re-run to update it.
6164

6265
| File | Description |
6366
|------|-------------|
6467
| `homepage.png` | Committed baseline |
6568
| `homepage.diff.png` | Visual diff with changes highlighted in red |
6669
| `homepage.heatmap.diff.png` | Heatmap of pixel differences |
6770

68-
Enable the [HTML report](docs/reporters.md) for an interactive dashboard with side-by-side comparison, zoom, and annotation toggle.
71+
## Web UI for Reviewing Screenshot Changes
72+
73+
Add one line to get an interactive dashboard for reviewing all screenshot differences:
6974

70-
**Compare any two images** without a browser — PDFs, generated images, CI artifacts:
7175
```ruby
72-
Capybara::Screenshot::Diff.compare("baseline.png", "current.png")
76+
# test/test_helper.rb
77+
require 'capybara_screenshot_diff/reporters/html'
7378
```
7479

75-
## Installation
80+
After tests run, open `doc/screenshots/snap_diff_report.html` — side-by-side comparison with 4 view modes (both/base/new/heatmap), per-image zoom, annotation toggle, keyboard navigation, and search.
7681

77-
```ruby
78-
# Gemfile
79-
gem 'capybara-screenshot-diff'
82+
**In GitHub Actions**, the report renders inline as a CI artifact — no download needed. Add a PR comment with a link to the report automatically:
8083

81-
# Optional: faster image processing (recommended)
82-
gem 'ruby-vips'
84+
```yaml
85+
- name: Upload screenshot report
86+
if: failure()
87+
uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
88+
with:
89+
name: screenshots
8390
```
8491
85-
Then run `bundle install`.
92+
See [CI Integration](docs/ci-integration.md) for the full GitHub Actions setup with PR commenting.
8693
87-
**Requirements:** Ruby 3.2+, Rails 7.1+. For the `:vips` driver: [libvips 8.9+](https://libvips.github.io/libvips/install.html).
94+
## Compare Any Two Images
95+
96+
Works without a browser — PDFs, generated images, CI artifacts:
97+
98+
```ruby
99+
result = Capybara::Screenshot::Diff.compare("baseline.png", "current.png")
100+
result.different? # => true if visually different
101+
result.quick_equal? # => true if byte-identical
102+
```
88103

89104
## Next Steps
90105

91106
- **Crop to element:** `screenshot "form", crop: "#main-form"`
92107
- **Ignore regions:** `screenshot "dashboard", skip_area: [".timestamp"]`
93-
- **Run in CI:** See [GitHub Actions setup](docs/ci-integration.md)
94-
- **HTML report:** `require 'capybara_screenshot_diff/reporters/html'`[details](docs/reporters.md)
108+
- **Disable animations:** `Capybara::Screenshot.disable_animations = true`
109+
- **Set window size:** `Capybara::Screenshot.window_size = [1280, 1024]`
95110

96-
## Tuning Flaky Tests
111+
## Handling Flaky Tests
97112

98-
**Defaults work for most Rails apps.** `blur_active_element`, `hide_caret`, and `fail_if_new` (in CI) are enabled automatically.
113+
Defaults work for most Rails apps `blur_active_element`, `hide_caret`, and `fail_if_new` (in CI) are enabled automatically.
99114

100-
If you see inconsistent results, choose a color comparison method:
115+
If screenshots differ between CI and local, set a comparison threshold:
101116

102117
```ruby
103-
# Option 1: Perceptual (recommended, VIPS only)
104-
Capybara::Screenshot::Diff.perceptual_threshold = 2.0
105-
106-
# Option 2: Tolerance-based comparison (legacy)
107-
Capybara::Screenshot::Diff.tolerance = 0.0005
108-
109-
# Always set window_size for consistent dimensions
110118
Capybara::Screenshot::Diff.configure do |screenshot, diff|
111119
screenshot.window_size = [1280, 1024]
120+
diff.perceptual_threshold = 2.0 # Recommended for VIPS — ignores anti-aliasing
121+
# or: diff.tolerance = 0.001 # Default for VIPS, percentage-based
112122
end
113123
```
114124

115-
| Use Case | VIPS `perceptual_threshold` | VIPS `tolerance` | ChunkyPNG `color_distance_limit` |
116-
|----------|---------------------------|-----------------|--------------------------------|
117-
| Cross-OS/browser testing | 2.0 (recommended) |||
118-
| Standard Rails apps || 0.001 (default) | 15 |
119-
| Animated/complex pages || 0.01 | 30 |
120-
| Pixel-perfect design || 0.0001 | 5 |
121-
122-
**⚠️ Color methods are exclusive:** Use `perceptual_threshold` OR `color_distance_limit`, not both. But `tolerance` works with either — it's applied by default for VIPS (0.001). See [Choosing the Right Method](docs/configuration.md#choosing-the-right-color-comparison-method).
125+
See [Choosing the Right Method](docs/configuration.md#choosing-the-right-color-comparison-method) for detailed comparison options.
123126

124-
## Troubleshooting
127+
## Common Questions
125128

126-
**"No existing screenshot found"** First run saves baselines. Run `bundle exec rake test` twice, then commit `doc/screenshots/`.
129+
**Why did my test pass on the first run?** First run always passes and saves baselines. Run again to compare.
127130

128-
**Screenshots differ between CI and local** — Use `tolerance: 0.001` or `perceptual_threshold: 2.0`. Set `window_size` for consistent dimensions.
131+
**How do I update baselines?** Delete the baseline file and re-run tests. Or delete all: `rm -rf doc/screenshots/ && bundle exec rake test`.
129132

130-
**Animations cause flaky diffs**`Capybara::Screenshot.disable_animations = true` disables CSS animations/transitions before each screenshot. Or use `stability_time_limit: 1` to wait for animations to finish.
133+
**Animations make screenshots flaky**`Capybara::Screenshot.disable_animations = true` freezes CSS animations/transitions before each capture.
131134

132-
**Dynamic content always differs**`screenshot "page", skip_area: [".timestamp", "#ad-banner"]`
135+
**CI screenshots differ from local**Set `window_size` for consistent dimensions and use `perceptual_threshold: 2.0` to ignore rendering differences.
133136

134137
**Debug mode**`DEBUG=1 bundle exec rake test` keeps `.diff.png` files for inspection.
135138

139+
## Installation
140+
141+
**Requirements:** Ruby 3.2+, Rails 7.1+. For the `:vips` driver: [libvips 8.9+](https://libvips.github.io/libvips/install.html).
142+
136143
## Advanced Topics
137144

138145
- [Framework Setup](docs/framework-setup.md) — Minitest, RSpec, Cucumber
139146
- [Image Processing Drivers](docs/drivers.md) — VIPS, ChunkyPNG, perceptual threshold
140147
- [Screenshot Organization](docs/organization.md) — groups, sections, cropping, multi-browser
141148
- [Configuration Reference](docs/configuration.md) — all options explained
142-
- [Reporters](docs/reporters.md)HTML report, custom reporters
149+
- [Web UI & Custom Reporters](docs/reporters.md)interactive report, custom reporters
143150
- [CI & Non-Rails Integration](docs/ci-integration.md) — GitHub Actions, reusable action, baseline updates
144151
- [Docker Testing](docs/docker-testing.md) — bin/dtest, recording baselines
145152

docs/reporters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Reporters
22

3-
## HTML Report
3+
## Web UI for Reviewing Screenshot Changes
44

5-
Generate an interactive HTML report of screenshot differences:
5+
Generate an interactive Web UI report of screenshot differences:
66

77
```ruby
88
# Add to test_helper.rb — one line, that's it

0 commit comments

Comments
 (0)