capybara-screenshot-diff 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +129 -0
- data/docs/RELEASE_PREP.md +15 -31
- data/docs/architecture.md +270 -0
- data/docs/ci-integration.md +107 -77
- data/docs/configuration.md +16 -0
- data/docs/images/snap_diff_annotated.png +0 -0
- data/docs/migration-guide.md +286 -0
- data/docs/organization.md +1 -23
- data/lib/capybara/screenshot/diff/screenshot_matcher.rb +15 -1
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- data/lib/capybara_screenshot_diff/cucumber.rb +9 -0
- data/lib/capybara_screenshot_diff/dsl.rb +28 -7
- data/lib/capybara_screenshot_diff/minitest.rb +6 -3
- data/lib/capybara_screenshot_diff/rspec.rb +8 -2
- data/lib/capybara_screenshot_diff/screenshot_assertion.rb +14 -1
- data/lib/capybara_screenshot_diff.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d2139e98f2c24b265a13882b8faf30282f5ef519dcbb77907f5d69d8f565606
|
|
4
|
+
data.tar.gz: 9302c796f95734c4ec4383f926c0aad03630caed8505f1d8fc815fe11bdb3c61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b072316d36fe69af44d3f318ba2d24968e9e0b377f85842c9a21d29aeb4ae7375a6b5b02c4842c9f3d9eb3115ed4fbcc33edff6c3b74b8ce788069d2301da95a
|
|
7
|
+
data.tar.gz: 30389f03f593e74c888a2d9de77717f1c839ad8ce41539ef0e6633b5dcff609ed546d7ed5279b3ab7ac9c86c53ed6608872e5b28a70663c7c2aef7c0974fcdf5
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [v1.13.0] - 2026-08-22
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **`capture_screenshot` DSL method** — take a screenshot without ever comparing or asserting ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
12
|
+
- **`compare:` option on `screenshot`** — pass `compare: true` (default) to assert, or `compare: false` to capture only ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
13
|
+
- **`Capybara::Screenshot::Diff.pending_if_new` config** — mark tests as skipped in teardown when a baseline does not exist, complementing `fail_if_new` ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **`assert_matches_screenshot` is now the primary assertion method** — captures a screenshot and compares against baseline ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
17
|
+
- **`screenshot` is now a convenience wrapper** — safe to override in user test classes; the gem no longer calls it internally ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
8
21
|
## [v1.12.0] - 2026-04-12
|
|
9
22
|
|
|
10
23
|
### Added
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement by
|
|
63
|
+
[opening a GitHub Issue](https://github.com/snap-diff/snap_diff-capybara/issues).
|
|
64
|
+
|
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
66
|
+
|
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
68
|
+
reporter of any incident.
|
|
69
|
+
|
|
70
|
+
## Enforcement Guidelines
|
|
71
|
+
|
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
74
|
+
|
|
75
|
+
### 1. Correction
|
|
76
|
+
|
|
77
|
+
**Community Impact:** Use of inappropriate language or other behavior deemed
|
|
78
|
+
unprofessional or unwelcome in the community.
|
|
79
|
+
|
|
80
|
+
**Consequence:** A private, written warning from community leaders, providing
|
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
|
83
|
+
|
|
84
|
+
### 2. Warning
|
|
85
|
+
|
|
86
|
+
**Community Impact:** A violation through a single incident or series
|
|
87
|
+
of actions.
|
|
88
|
+
|
|
89
|
+
**Consequence:** A warning with consequences for continued behavior. No
|
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
|
94
|
+
permanent ban.
|
|
95
|
+
|
|
96
|
+
### 3. Temporary Ban
|
|
97
|
+
|
|
98
|
+
**Community Impact:** A serious violation of community standards, including
|
|
99
|
+
sustained inappropriate behavior.
|
|
100
|
+
|
|
101
|
+
**Consequence:** A temporary ban from any sort of interaction or public
|
|
102
|
+
communication with the community for a specified period of time. No public or
|
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
105
|
+
Violating these terms may lead to a permanent ban.
|
|
106
|
+
|
|
107
|
+
### 4. Permanent Ban
|
|
108
|
+
|
|
109
|
+
**Community Impact:** Demonstrating a pattern of violation of community
|
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
112
|
+
|
|
113
|
+
**Consequence:** A permanent ban from any sort of public interaction within
|
|
114
|
+
the community.
|
|
115
|
+
|
|
116
|
+
## Attribution
|
|
117
|
+
|
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
119
|
+
version 2.1, available at
|
|
120
|
+
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
|
|
121
|
+
|
|
122
|
+
Community Impact Guidelines were inspired by
|
|
123
|
+
[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
|
124
|
+
|
|
125
|
+
[homepage]: https://www.contributor-covenant.org
|
|
126
|
+
|
|
127
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
128
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
129
|
+
https://www.contributor-covenant.org/translations.
|
data/docs/RELEASE_PREP.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
# Release Preparation — v1.
|
|
1
|
+
# Release Preparation — v1.13.0
|
|
2
2
|
|
|
3
3
|
## Summary
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Issue #191 API decoupling: `assert_matches_screenshot` becomes the primary
|
|
6
|
+
assertion method, plus a capture-only API and opt-in pending-instead-of-pass
|
|
7
|
+
for missing baselines.
|
|
6
8
|
|
|
7
9
|
## Release Checklist
|
|
8
10
|
|
|
9
11
|
### Pre-Release
|
|
10
12
|
|
|
11
|
-
- [x] Update version to `1.
|
|
12
|
-
- [x] Run tests: `bundle exec rake test` (
|
|
13
|
-
- [x]
|
|
14
|
-
- [x] Add docs/UPGRADING.md
|
|
13
|
+
- [x] Update version to `1.13.0`
|
|
14
|
+
- [x] Run tests: `bundle exec rake test:unit` (235 runs, 0 failures)
|
|
15
|
+
- [x] Update CHANGELOG.md
|
|
15
16
|
|
|
16
17
|
### Release (One Click)
|
|
17
18
|
|
|
18
19
|
1. Push to GitHub
|
|
19
20
|
2. Go to [Actions → Release](https://github.com/snap-diff/snap_diff-capybara/actions/workflows/release.yml)
|
|
20
|
-
3. Click **Run workflow**, enter `1.
|
|
21
|
+
3. Click **Run workflow**, enter `1.13.0`
|
|
21
22
|
4. Workflow will: test → tag → publish to RubyGems → create GitHub Release
|
|
22
23
|
|
|
23
24
|
### Post-Release
|
|
@@ -28,31 +29,14 @@
|
|
|
28
29
|
## What Changed
|
|
29
30
|
|
|
30
31
|
### New Features
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
- `
|
|
34
|
-
|
|
35
|
-
- `Diff.compare` for standalone image comparison
|
|
36
|
-
- Perceptual color distance (dE00) for anti-aliasing
|
|
37
|
-
- `assert_no_screenshot_changes` DSL method
|
|
38
|
-
- `Diff.configure` block helper
|
|
39
|
-
- Ruby 3.5 & 4.0 support
|
|
32
|
+
- `capture_screenshot` DSL method — capture without comparing or asserting
|
|
33
|
+
- `compare:` option on `screenshot` — `compare: false` captures only
|
|
34
|
+
- `Capybara::Screenshot::Diff.pending_if_new` — mark tests skipped in teardown
|
|
35
|
+
when a screenshot has no committed baseline (Minitest, RSpec, and Cucumber)
|
|
40
36
|
|
|
41
37
|
### Behavior Changes
|
|
42
|
-
- `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- Thread-safe reporter notification with mutex
|
|
46
|
-
- SVN support removed
|
|
47
|
-
- ActiveSupport no longer required
|
|
48
|
-
|
|
49
|
-
### Performance
|
|
50
|
-
- Faster ChunkyPNG shift-detection (eliminated allocations)
|
|
51
|
-
- Cached computations in VIPS driver
|
|
52
|
-
- Memoized region area size
|
|
53
|
-
|
|
54
|
-
### Documentation
|
|
55
|
-
- README restructured (970→149 lines) with 7 dedicated docs/ files
|
|
56
|
-
- CI integration guide, upgrade guide, color comparison guide
|
|
38
|
+
- `assert_matches_screenshot` is now the primary assertion method; `screenshot`
|
|
39
|
+
remains as a convenience wrapper and is safe to override in user test classes —
|
|
40
|
+
the gem no longer calls it internally ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
|
|
57
41
|
|
|
58
42
|
See [CHANGELOG.md](../CHANGELOG.md) for full details.
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
This document describes the internal architecture of `capybara-screenshot-diff` — how screenshots are captured, compared, and reported, and how the components fit together.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────┐
|
|
9
|
+
│ Test Framework │
|
|
10
|
+
│ (Minitest / RSpec / Cucumber / Custom) │
|
|
11
|
+
└──────────────┬──────────────────────────────┬────────────┘
|
|
12
|
+
│ │
|
|
13
|
+
▼ ▼
|
|
14
|
+
┌──────────────────────────┐ ┌──────────────────────────┐
|
|
15
|
+
│ CapybaraScreenshotDiff │ │ CapybaraScreenshotDiff │
|
|
16
|
+
│ ::DSL (screenshot, etc) │ │ ::AssertionRegistry │
|
|
17
|
+
└──────────────┬───────────┘ └──────────────┬───────────┘
|
|
18
|
+
│ │
|
|
19
|
+
▼ ▼
|
|
20
|
+
┌──────────────────────────┐ ┌──────────────────────────┐
|
|
21
|
+
│ ScreenshotMatcher │ │ ScreenshotAssertion │
|
|
22
|
+
│ (capture + compare) │ │ (validate results) │
|
|
23
|
+
└──────┬───────────┬────────┘ └──────────────┬───────────┘
|
|
24
|
+
│ │ │
|
|
25
|
+
▼ ▼ ▼
|
|
26
|
+
┌──────────┐ ┌──────────┐ ┌──────────────────────┐
|
|
27
|
+
│Screenshot│ │Stable │ │ Reporters │
|
|
28
|
+
│er │ │Screenshot│ │ (Default / HTML / │
|
|
29
|
+
│ │ │er │ │ Custom) │
|
|
30
|
+
└─────┬────┘ └──────────┘ └──────────────────────┘
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
┌──────────────────────────────────────────┐
|
|
34
|
+
│ ImageCompare (layered comparison) │
|
|
35
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
|
36
|
+
│ │1. Byte │ │2. Pixel │ │3. Region │ │
|
|
37
|
+
│ │ compare │ │ compare │ │ analyze │ │
|
|
38
|
+
│ └──────────┘ └──────────┘ └──────────┘ │
|
|
39
|
+
└─────────────────────┬────────────────────┘
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
┌──────────────────────────────────────────┐
|
|
43
|
+
│ Drivers (image processing backends) │
|
|
44
|
+
│ ┌──────────┐ ┌──────────────────────┐ │
|
|
45
|
+
│ │ Vips │ │ ChunkyPNG │ │
|
|
46
|
+
│ │ (fast) │ │ (no native deps) │ │
|
|
47
|
+
│ └──────────┘ └──────────────────────┘ │
|
|
48
|
+
└──────────────────────────────────────────┘
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Component Breakdown
|
|
52
|
+
|
|
53
|
+
### 1. DSL Layer (`lib/capybara_screenshot_diff/dsl.rb`)
|
|
54
|
+
|
|
55
|
+
The entry point for test code. `assert_matches_screenshot` is the primary assertion method (captures and compares). `screenshot` is a convenience wrapper with a `compare:` option — `compare: true` (default) delegates to `assert_matches_screenshot`, while `compare: false` delegates to the new `capture_screenshot` method. `capture_screenshot` takes screenshots without assertions. `assert_no_screenshot_changes` keeps its behavior but now delegates to `assert_matches_screenshot` (that redirect is part of the #191 fix). Users can safely override `screenshot` in their test classes without affecting internal gem flow.
|
|
56
|
+
|
|
57
|
+
**Flow:**
|
|
58
|
+
1. Checks if screenshots are `active?` (returns `false` if disabled)
|
|
59
|
+
2. Builds a full screenshot name via `ScreenshotNamer` (handles sections, groups, counters)
|
|
60
|
+
3. Delegates to `ScreenshotMatcher` to capture and prepare comparison
|
|
61
|
+
4. Creates a `ScreenshotAssertion` — either adds it to the thread-local registry (delayed validation) or validates immediately
|
|
62
|
+
|
|
63
|
+
### 2. ScreenshotMatcher (`lib/capybara/screenshot/diff/screenshot_matcher.rb`)
|
|
64
|
+
|
|
65
|
+
The orchestrator that coordinates capture and comparison:
|
|
66
|
+
|
|
67
|
+
1. **Window size check** — verifies browser window is the expected size
|
|
68
|
+
2. **Area calculation** — resolves crop regions and skip areas (supports CSS selectors and coordinates)
|
|
69
|
+
3. **Base screenshot checkout** — retrieves the committed baseline from git via `Vcs.checkout_vcs`
|
|
70
|
+
4. **Capture** — delegates to `Screenshoter` or `StableScreenshoter` depending on `stability_time_limit`
|
|
71
|
+
5. **Comparison** — creates an `ImageCompare` object (lazy — actual comparison happens on first access)
|
|
72
|
+
6. **Assertion** — returns a `ScreenshotAssertion` with the comparison attached
|
|
73
|
+
|
|
74
|
+
**Key design decision:** The "new" screenshot is taken *first*, then compared against the baseline. This means if no baseline exists (first run), we skip comparison entirely and the test passes.
|
|
75
|
+
|
|
76
|
+
### 3. Screenshoter & StableScreenshoter (`lib/capybara/screenshot/diff/screenshoter.rb`, `lib/capybara/screenshot/diff/stable_screenshoter.rb`)
|
|
77
|
+
|
|
78
|
+
**Screenshoter:** The basic capture flow:
|
|
79
|
+
1. Prepares the page (blur active element, hide caret, disable animations, wait for images)
|
|
80
|
+
2. Takes a browser screenshot via `Capybara.current_session.save_screenshot`
|
|
81
|
+
3. Processes the screenshot (resize for retina, apply crop)
|
|
82
|
+
|
|
83
|
+
**StableScreenshoter:** Wraps `Screenshoter` with stability detection:
|
|
84
|
+
1. Takes sequential screenshots at `stability_time_limit` intervals
|
|
85
|
+
2. Compares consecutive attempts for byte-level equality
|
|
86
|
+
3. Returns once two consecutive screenshots are identical
|
|
87
|
+
4. Fails with `UnstableImage` if timeout (`wait`) is reached, generating annotated attempt images for debugging
|
|
88
|
+
|
|
89
|
+
### 4. ImageCompare (`lib/capybara/screenshot/diff/image_compare.rb`)
|
|
90
|
+
|
|
91
|
+
The comparison engine uses a **layered optimization strategy** to balance speed and accuracy:
|
|
92
|
+
|
|
93
|
+
| Layer | Method | What it checks | Speed | When it returns |
|
|
94
|
+
|-------|--------|----------------|-------|-----------------|
|
|
95
|
+
| 1 | `quick_equal?` | File size + byte-level comparison | Fastest | Equal → `true`, Different → Layer 2 |
|
|
96
|
+
| 2 | `quick_equal?` continues | Dimension check + pixel comparison | Fast | Different dimensions → `false`, Same pixels → `true` |
|
|
97
|
+
| 3 | `processed` / `different?` | Full region analysis with tolerance | Slower | Detailed diff with region, heatmap, annotations |
|
|
98
|
+
|
|
99
|
+
**Key details:**
|
|
100
|
+
- `quick_equal?` is designed for fast rejection — it early-returns as soon as a difference is found
|
|
101
|
+
- `different?` triggers the full comparison if not already processed
|
|
102
|
+
- `processed` guarantees the comparison is complete and returns the result with all metadata
|
|
103
|
+
- The `DifferenceFinder` handles the actual pixel analysis, delegating to the driver
|
|
104
|
+
|
|
105
|
+
### 5. Drivers (`lib/capybara/screenshot/diff/drivers/`)
|
|
106
|
+
|
|
107
|
+
Drivers abstract image processing operations. Each driver implements:
|
|
108
|
+
|
|
109
|
+
| Operation | VipsDriver | ChunkyPNGDriver |
|
|
110
|
+
|-----------|-----------|-----------------|
|
|
111
|
+
| `load_images` | Vips::Image from file | ChunkyPNG::Image from blob |
|
|
112
|
+
| `same_dimension?` | Compare width × height | Same |
|
|
113
|
+
| `same_pixels?` | Pixel-level equality | Same |
|
|
114
|
+
| `find_difference_region` | Difference mask → Region | Row-by-row scan → Region |
|
|
115
|
+
| `crop` | Vips image crop | ChunkyPNG crop |
|
|
116
|
+
| `save_image_to` | Vips write_to_file | PNG save |
|
|
117
|
+
| `filter_image_with_median` | Vips median filter | Not supported |
|
|
118
|
+
| `add_black_box` | Draw filled rect | No-op (handled differently) |
|
|
119
|
+
| `merge` | Composite images | Not applicable |
|
|
120
|
+
| `highlight_mask` | Conditional color overlay | Not applicable |
|
|
121
|
+
|
|
122
|
+
**Auto-detection:** `Utils.detect_available_drivers` tries to load `:vips` first (via `ruby-vips` gem), then `:chunky_png`. The `:auto` driver mode picks the first available.
|
|
123
|
+
|
|
124
|
+
### 6. Difference Region Detection
|
|
125
|
+
|
|
126
|
+
**VipsDriver** uses a **difference mask** approach:
|
|
127
|
+
1. Compute absolute difference between images: `(new - base).abs`
|
|
128
|
+
2. Optional: apply perceptual color distance (CIE dE00) instead of raw RGB
|
|
129
|
+
3. Project the mask to find the bounding region of non-zero pixels
|
|
130
|
+
4. Return the tight bounding box of all differences
|
|
131
|
+
|
|
132
|
+
**ChunkyPNGDriver** uses **row-by-row scanning**:
|
|
133
|
+
1. Scan top-to-bottom, left-to-right for first differing pixel
|
|
134
|
+
2. Expand left/right boundaries within each differing row
|
|
135
|
+
3. Extend bottom boundary to cover all differing rows
|
|
136
|
+
4. Supports shift detection (expensive neighbor pixel search)
|
|
137
|
+
|
|
138
|
+
### 7. SnapManager & Snap (`lib/capybara_screenshot_diff/snap_manager.rb`, `lib/capybara_screenshot_diff/snap.rb`)
|
|
139
|
+
|
|
140
|
+
**Snap** represents a single screenshot file with path management:
|
|
141
|
+
- `path` — the actual screenshot file
|
|
142
|
+
- `base_path` — the `.base.ext` VCS checkout
|
|
143
|
+
- `attempt_path` — stability attempt files (`.attempt_00.png`, etc.)
|
|
144
|
+
- Provides cleanup of diff artifacts (`.diff.png`, `.heatmap.diff.png`)
|
|
145
|
+
|
|
146
|
+
**SnapManager** is the factory and path manager:
|
|
147
|
+
- Creates `Snap` instances
|
|
148
|
+
- Handles VCS checkout of baselines
|
|
149
|
+
- Manages file operations (copy, move, cleanup)
|
|
150
|
+
|
|
151
|
+
### 8. VCS (`lib/capybara/screenshot/diff/vcs.rb`)
|
|
152
|
+
|
|
153
|
+
Handles baseline retrieval from git. Uses `git show HEAD:<path>` to extract the committed version. Supports Git LFS via `git lfs smudge`. Returns `false` if the file doesn't exist in VCS (first-run scenario).
|
|
154
|
+
|
|
155
|
+
### 9. Reporters (`lib/capybara/screenshot/diff/reporters/`)
|
|
156
|
+
|
|
157
|
+
**Default reporter:** Generates annotated diff images:
|
|
158
|
+
- `image.diff.png` — new screenshot with diff region outlined in red
|
|
159
|
+
- `image.base.diff.png` — baseline with diff region outlined in red
|
|
160
|
+
- `image.heatmap.diff.png` — heatmap overlay of pixel differences
|
|
161
|
+
|
|
162
|
+
**HTML reporter:** Generates an interactive dashboard (`snap_diff_report.html`) with:
|
|
163
|
+
- Sidebar with thumbnails and search
|
|
164
|
+
- 4 view modes (both/base/new/heatmap)
|
|
165
|
+
- Annotated toggle for showing diff outlines
|
|
166
|
+
- Per-image zoom with synchronized panning across side-by-side views
|
|
167
|
+
- Keyboard navigation and shortcuts
|
|
168
|
+
- Responsive layout for mobile
|
|
169
|
+
|
|
170
|
+
**Custom reporters:** Implement `record(assertions)` and `finalize` methods, then add to `CapybaraScreenshotDiff.reporters`.
|
|
171
|
+
|
|
172
|
+
### 10. Assertion Lifecycle
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
Test begins
|
|
176
|
+
│
|
|
177
|
+
├─ setup: resize_window_if_needed
|
|
178
|
+
│
|
|
179
|
+
├─ test body:
|
|
180
|
+
│ └─ screenshot("name")
|
|
181
|
+
│ ├─ ScreenshotMatcher builds assertion
|
|
182
|
+
│ ├─ delayed=true → add to Thread-local registry
|
|
183
|
+
│ └─ delayed=false → validate immediately
|
|
184
|
+
│
|
|
185
|
+
├─ teardown:
|
|
186
|
+
│ └─ CapybaraScreenshotDiff.verify
|
|
187
|
+
│ ├─ iterates thread-local assertions
|
|
188
|
+
│ ├─ calls validate on each
|
|
189
|
+
│ ├─ raises ExpectationNotMet on first failure
|
|
190
|
+
│ └─ notifies reporters via mutex-protected snapshot
|
|
191
|
+
│
|
|
192
|
+
└─ at_exit:
|
|
193
|
+
└─ CapybaraScreenshotDiff.finalize_reporters!
|
|
194
|
+
├─ Generates HTML report (if reporter registered)
|
|
195
|
+
└─ Prints summary
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 11. Thread Safety
|
|
199
|
+
|
|
200
|
+
| Concern | Mechanism |
|
|
201
|
+
|---------|-----------|
|
|
202
|
+
| Assertion registry | Thread-local storage (`Thread.current[:capybara_screenshot_diff_registry]`) |
|
|
203
|
+
| Reporter notification | Mutex-protected snapshot of reporter list before iteration |
|
|
204
|
+
| HTML reporter internals | Mutex protecting `@failures`, `@total`, `@finalized` |
|
|
205
|
+
| Screenshot naming | Per-thread `ScreenshotNamer` instance |
|
|
206
|
+
| Global configuration | `mattr_accessor` — must be set before tests run, not mutated during parallel execution |
|
|
207
|
+
| File system | Atomic `FileUtils.mv`, unique paths per screenshot name + counter, thread-safe `mkpath` |
|
|
208
|
+
|
|
209
|
+
### 12. Configuration System
|
|
210
|
+
|
|
211
|
+
Configuration uses Ruby's `mattr_accessor` (from ActiveSupport, or pure Ruby fallback) and is organized into two namespaces:
|
|
212
|
+
|
|
213
|
+
**`Capybara::Screenshot`** — capture settings:
|
|
214
|
+
- `window_size`, `stability_time_limit`, `blur_active_element`, `hide_caret`, `disable_animations`
|
|
215
|
+
- `save_path`, `root`, `screenshot_format`, `add_driver_path`, `add_os_path`
|
|
216
|
+
- `enabled`, `capybara_screenshot_options`
|
|
217
|
+
|
|
218
|
+
**`Capybara::Screenshot::Diff`** — comparison settings:
|
|
219
|
+
- `driver`, `tolerance`, `color_distance_limit`, `perceptual_threshold`, `shift_distance_limit`
|
|
220
|
+
- `area_size_limit`, `skip_area`, `fail_if_new`, `fail_on_difference`, `delayed`
|
|
221
|
+
|
|
222
|
+
The `Diff.configure` block helper provides a convenient way to set both namespaces at once.
|
|
223
|
+
|
|
224
|
+
## File Layout
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
lib/
|
|
228
|
+
capybara_screenshot_diff.rb # Core module, mattr_accessor definitions
|
|
229
|
+
capybara/screenshot/diff.rb # Convenience require (loads minitest)
|
|
230
|
+
capybara_screenshot_diff/
|
|
231
|
+
dsl.rb # screenshot(), screenshot_group(), etc.
|
|
232
|
+
minitest.rb # Minitest assertions integration
|
|
233
|
+
rspec.rb # RSpec matcher integration
|
|
234
|
+
cucumber.rb # Cucumber World integration
|
|
235
|
+
static.rb # Non-Rails static site serving
|
|
236
|
+
snap_manager.rb # Screenshot file management
|
|
237
|
+
snap.rb # Single screenshot file abstraction
|
|
238
|
+
screenshot_namer.rb # Name/path generation with sections/groups
|
|
239
|
+
screenshot_assertion.rb # Assertion + registry objects
|
|
240
|
+
attempts_reporter.rb # Debug reporting for unstable captures
|
|
241
|
+
error_with_filtered_backtrace.rb # Error with filtered stack
|
|
242
|
+
backtrace_filter.rb # Library/gem frame filtering
|
|
243
|
+
reporters/
|
|
244
|
+
html.rb # Interactive HTML report reporter
|
|
245
|
+
templates/report.html.erb # HTML report template
|
|
246
|
+
capybara/screenshot/diff/
|
|
247
|
+
version.rb # VERSION constant
|
|
248
|
+
utils.rb # Driver detection
|
|
249
|
+
drivers.rb # Driver factory
|
|
250
|
+
drivers/
|
|
251
|
+
base_driver.rb # Abstract base driver
|
|
252
|
+
vips_driver.rb # VIPS image processing
|
|
253
|
+
chunky_png_driver.rb # ChunkyPNG image processing
|
|
254
|
+
screenshoter.rb # Basic browser screenshot capture
|
|
255
|
+
stable_screenshoter.rb # Stability detection wrapper
|
|
256
|
+
screenshot_matcher.rb # Orchestrator for capture + compare
|
|
257
|
+
image_compare.rb # Layered comparison engine
|
|
258
|
+
comparison.rb # Comparison value object
|
|
259
|
+
difference.rb # Difference result value object
|
|
260
|
+
difference_finder.rb # Core diff analysis logic
|
|
261
|
+
image_preprocessor.rb # Pre-processing (skip areas, median filter)
|
|
262
|
+
area_calculator.rb # Crop/skip area coordinate resolution
|
|
263
|
+
region.rb # Bounding box region value object
|
|
264
|
+
browser_helpers.rb # DOM manipulation helpers
|
|
265
|
+
vcs.rb # Git baseline checkout
|
|
266
|
+
os.rb # OS detection
|
|
267
|
+
cucumber.rb # Deprecated Cucumber entry point
|
|
268
|
+
reporters/
|
|
269
|
+
default.rb # Default annotated-image reporter
|
|
270
|
+
```
|