capybara-screenshot-diff 1.7.0 → 1.8.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/Rakefile +29 -0
- data/capybara-screenshot-diff.gemspec +7 -4
- data/gems.rb +8 -2
- data/lib/capybara/screenshot/diff/browser_helpers.rb +29 -28
- data/lib/capybara/screenshot/diff/cucumber.rb +11 -0
- data/lib/capybara/screenshot/diff/difference.rb +63 -0
- data/lib/capybara/screenshot/diff/drivers/base_driver.rb +42 -0
- data/lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb +188 -260
- data/lib/capybara/screenshot/diff/drivers/utils.rb +16 -0
- data/lib/capybara/screenshot/diff/drivers/vips_driver.rb +53 -103
- data/lib/capybara/screenshot/diff/drivers.rb +16 -0
- data/lib/capybara/screenshot/diff/image_compare.rb +125 -154
- data/lib/capybara/screenshot/diff/os.rb +1 -1
- data/lib/capybara/screenshot/diff/screenshot_matcher.rb +128 -0
- data/lib/capybara/screenshot/diff/screenshoter.rb +137 -0
- data/lib/capybara/screenshot/diff/stabilization.rb +0 -184
- data/lib/capybara/screenshot/diff/stable_screenshoter.rb +106 -0
- data/lib/capybara/screenshot/diff/test_methods.rb +51 -90
- data/lib/capybara/screenshot/diff/vcs.rb +44 -22
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- data/lib/capybara/screenshot/diff.rb +13 -17
- data/sig/capybara/screenshot/diff/diff.rbs +28 -0
- data/sig/capybara/screenshot/diff/difference.rbs +33 -0
- data/sig/capybara/screenshot/diff/drivers/base_driver.rbs +63 -0
- data/sig/capybara/screenshot/diff/drivers/browser_helpers.rbs +36 -0
- data/sig/capybara/screenshot/diff/drivers/chunky_png_driver.rbs +89 -0
- data/sig/capybara/screenshot/diff/drivers/utils.rbs +13 -0
- data/sig/capybara/screenshot/diff/drivers/vips_driver.rbs +25 -0
- data/sig/capybara/screenshot/diff/image_compare.rbs +93 -0
- data/sig/capybara/screenshot/diff/os.rbs +11 -0
- data/sig/capybara/screenshot/diff/region.rbs +43 -0
- data/sig/capybara/screenshot/diff/screenshot_matcher.rbs +60 -0
- data/sig/capybara/screenshot/diff/screenshoter.rbs +48 -0
- data/sig/capybara/screenshot/diff/stable_screenshoter.rbs +29 -0
- data/sig/capybara/screenshot/diff/test_methods.rbs +39 -0
- data/sig/capybara/screenshot/diff/vcs.rbs +17 -0
- metadata +36 -27
- data/.gitattributes +0 -4
- data/.github/dependabot.yml +0 -8
- data/.github/workflows/lint.yml +0 -25
- data/.github/workflows/test.yml +0 -138
- data/.gitignore +0 -14
- data/.standard.yml +0 -12
- data/CONTRIBUTING.md +0 -24
- data/Dockerfile +0 -59
- data/README.md +0 -567
- data/bin/bundle +0 -114
- data/bin/console +0 -15
- data/bin/install-vips +0 -11
- data/bin/rake +0 -27
- data/bin/setup +0 -8
- data/bin/standardrb +0 -29
- data/gemfiles/rails60_gems.rb +0 -8
- data/gemfiles/rails61_gems.rb +0 -7
- data/gemfiles/rails70_gems.rb +0 -7
- data/tmp/.keep +0 -0
data/.standard.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
fix: true # default: false
|
2
|
-
parallel: true # default: false
|
3
|
-
format: progress # default: Standard::Formatter
|
4
|
-
ruby_version: 2.7 # default: RUBY_VERSION
|
5
|
-
default_ignores: false # default: true
|
6
|
-
|
7
|
-
ignore: # default: []
|
8
|
-
- 'bin/**/*'
|
9
|
-
- 'gemfiles/vendor/**/*'
|
10
|
-
- 'gemfiles/**/*':
|
11
|
-
- Security/Eval
|
12
|
-
- 'vendor/**/*'
|
data/CONTRIBUTING.md
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
Contributing
|
2
|
-
============
|
3
|
-
|
4
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff.
|
5
|
-
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected
|
6
|
-
to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
7
|
-
|
8
|
-
## Testing
|
9
|
-
|
10
|
-
Run the tests before committing using Rake
|
11
|
-
|
12
|
-
rake
|
13
|
-
|
14
|
-
### Matrix testing
|
15
|
-
|
16
|
-
Run the tests for a matrix of configurations of Ruby implementations and Rails versions
|
17
|
-
|
18
|
-
./matrix_text.rb
|
19
|
-
|
20
|
-
## Merging to master
|
21
|
-
|
22
|
-
Before merging to `master`,
|
23
|
-
please have a member of the project review your changes,
|
24
|
-
and make sure the tests are green.
|
data/Dockerfile
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# Usage:
|
2
|
-
#
|
3
|
-
# $ docker build . -t csd
|
4
|
-
# $ docker run -v $(pwd):/app -ti csd rake test
|
5
|
-
|
6
|
-
FROM jetthoughts/cimg-ruby:3.1-chrome
|
7
|
-
|
8
|
-
RUN \
|
9
|
-
# Install dependencies
|
10
|
-
sudo apt-get update && \
|
11
|
-
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
|
12
|
-
automake \
|
13
|
-
build-essential \
|
14
|
-
curl \
|
15
|
-
fftw3-dev \
|
16
|
-
gettext \
|
17
|
-
gobject-introspection \
|
18
|
-
gtk-doc-tools \
|
19
|
-
libexif-dev \
|
20
|
-
libfftw3-dev \
|
21
|
-
libgif-dev \
|
22
|
-
libglib2.0-dev \
|
23
|
-
libgsf-1-dev \
|
24
|
-
libgtk2.0-dev \
|
25
|
-
libmagickwand-dev \
|
26
|
-
libmatio-dev \
|
27
|
-
libopenexr-dev \
|
28
|
-
libopenslide-dev \
|
29
|
-
liborc-0.4-dev \
|
30
|
-
libpango1.0-dev \
|
31
|
-
libpoppler-glib-dev \
|
32
|
-
librsvg2-dev \
|
33
|
-
libtiff5-dev \
|
34
|
-
libwebp-dev \
|
35
|
-
libxml2-dev \
|
36
|
-
swig
|
37
|
-
|
38
|
-
|
39
|
-
WORKDIR /app
|
40
|
-
RUN sudo chmod a+w -R /app
|
41
|
-
|
42
|
-
ADD ./bin/install-vips /app/bin/
|
43
|
-
RUN sudo /app/bin/install-vips
|
44
|
-
|
45
|
-
ADD ./lib/capybara/screenshot/diff/version.rb /app/lib/capybara/screenshot/diff/
|
46
|
-
ADD ./capybara-screenshot-diff.gemspec /app/
|
47
|
-
ADD ./gems.rb /app/
|
48
|
-
ADD ./Rakefile /app/
|
49
|
-
|
50
|
-
RUN bundle install
|
51
|
-
|
52
|
-
RUN \
|
53
|
-
# Clean up
|
54
|
-
sudo apt-get remove -y curl automake build-essential && \
|
55
|
-
sudo apt-get autoremove -y && \
|
56
|
-
sudo apt-get autoclean && \
|
57
|
-
sudo apt-get clean && \
|
58
|
-
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
59
|
-
|
data/README.md
DELETED
@@ -1,567 +0,0 @@
|
|
1
|
-
[](https://github.com/donv/capybara-screenshot-diff/actions/workflows/test.yml)
|
2
|
-
|
3
|
-
# Capybara::Screenshot::Diff
|
4
|
-
|
5
|
-
Ever wondered what your project looked like two years ago? To answer that, you
|
6
|
-
start taking screen shots during your tests. Capybara provides the
|
7
|
-
`save_screenshot` method for this. Very good.
|
8
|
-
|
9
|
-
Ever introduced a graphical change unintended? Never want it to happen again?
|
10
|
-
Then this gem is for you! Use this gem to detect changes in your pages by
|
11
|
-
taking screen shots and comparing them to the previous revision.
|
12
|
-
|
13
|
-
## Installation
|
14
|
-
|
15
|
-
Add these lines to your application's Gemfile:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
gem 'capybara-screenshot-diff'
|
19
|
-
gem 'oily_png', platform: :ruby
|
20
|
-
```
|
21
|
-
|
22
|
-
And then execute:
|
23
|
-
|
24
|
-
$ bundle
|
25
|
-
|
26
|
-
Or install it yourself as:
|
27
|
-
|
28
|
-
$ gem install capybara-screenshot-diff
|
29
|
-
|
30
|
-
### Requirements
|
31
|
-
|
32
|
-
* [for :vips driver] libvips 8.9 or later, see the [libvips install instructions](https://libvips.github.io/libvips/install.html)
|
33
|
-
|
34
|
-
## Usage
|
35
|
-
|
36
|
-
### Minitest
|
37
|
-
|
38
|
-
In your test class, include the `Capybara::Screenshot::Diff` module:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
42
|
-
include Capybara::Screenshot::Diff
|
43
|
-
# ...
|
44
|
-
end
|
45
|
-
```
|
46
|
-
|
47
|
-
### RSpec
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
describe 'Permissions admin', type: :feature, js: true do
|
51
|
-
|
52
|
-
include Capybara::Screenshot::Diff
|
53
|
-
|
54
|
-
it 'works with permissions' do
|
55
|
-
visit('/')
|
56
|
-
screenshot 'home_page'
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
```
|
61
|
-
But it's better to include it within your *_helper.rb file so that it can used anywhere in your feature specs.
|
62
|
-
```ruby
|
63
|
-
# spec/feature_helper.rb
|
64
|
-
require 'capybara/screenshot/diff'
|
65
|
-
|
66
|
-
RSpec.configure do |config|
|
67
|
-
config.include Capybara::Screenshot::Diff
|
68
|
-
end
|
69
|
-
```
|
70
|
-
|
71
|
-
### Taking screenshots
|
72
|
-
|
73
|
-
Add `screenshot '<my_feature>'` to your tests. The screenshot will be saved in
|
74
|
-
the `doc/screenshots` directory.
|
75
|
-
|
76
|
-
Change your existing `save_screenshot` calls to `screenshot`
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
test 'my useful feature' do
|
80
|
-
visit '/'
|
81
|
-
screenshot 'welcome_index'
|
82
|
-
click_button 'Useful feature'
|
83
|
-
screenshot 'feature_index'
|
84
|
-
click_button 'Perform action'
|
85
|
-
screenshot 'action_performed'
|
86
|
-
end
|
87
|
-
```
|
88
|
-
|
89
|
-
This will produce a sequence of images like this
|
90
|
-
|
91
|
-
```
|
92
|
-
doc
|
93
|
-
screenshots
|
94
|
-
action_performed
|
95
|
-
feature_index
|
96
|
-
welcome_index
|
97
|
-
```
|
98
|
-
|
99
|
-
To store the screen shot history, add the `doc/screenshots` directory to your
|
100
|
-
version control system (git, svn, etc).
|
101
|
-
|
102
|
-
Screen shots are compared to the previously COMMITTED version of the same screen shot.
|
103
|
-
|
104
|
-
### Screenshot groups
|
105
|
-
|
106
|
-
Commonly it is useful to group screenshots around a feature, and record them as
|
107
|
-
a sequence. To do this, add a `screenshot_group` call to the start of your
|
108
|
-
test.
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
test 'my useful feature' do
|
112
|
-
screenshot_group 'useful_feature'
|
113
|
-
visit '/'
|
114
|
-
screenshot 'welcome_index'
|
115
|
-
click_button 'Useful feature'
|
116
|
-
screenshot 'feature_index'
|
117
|
-
click_button 'Perform action'
|
118
|
-
screenshot 'action_performed'
|
119
|
-
end
|
120
|
-
```
|
121
|
-
|
122
|
-
This will produce a sequence of images like this
|
123
|
-
|
124
|
-
```
|
125
|
-
doc
|
126
|
-
screenshots
|
127
|
-
useful_feature
|
128
|
-
00-welcome_index
|
129
|
-
01-feature_index
|
130
|
-
02-action_performed
|
131
|
-
```
|
132
|
-
|
133
|
-
**All files in the screenshot group directory will be deleted when
|
134
|
-
`screenshot_group` is called.**
|
135
|
-
|
136
|
-
|
137
|
-
#### Screenshot sections
|
138
|
-
|
139
|
-
You can introduce another level above the screenshot group called a
|
140
|
-
`screenshot_section`. The section name is inserted just before the group name
|
141
|
-
in the save path. If called in the setup of the test, all screenshots in
|
142
|
-
that test will get the same prefix:
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
setup do
|
146
|
-
screenshot_section 'my_feature'
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'my subfeature' do
|
150
|
-
screenshot_group 'subfeature'
|
151
|
-
visit '/feature'
|
152
|
-
click_button 'Interesting button'
|
153
|
-
screenshot 'subfeature_index'
|
154
|
-
click_button 'Perform action'
|
155
|
-
screenshot 'action_performed'
|
156
|
-
end
|
157
|
-
```
|
158
|
-
|
159
|
-
This will produce a sequence of images like this
|
160
|
-
|
161
|
-
```
|
162
|
-
doc
|
163
|
-
screenshots
|
164
|
-
my_feature
|
165
|
-
subfeature
|
166
|
-
00-subfeature_index
|
167
|
-
01-action_performed
|
168
|
-
```
|
169
|
-
|
170
|
-
|
171
|
-
#### Setting `screenshot_section` and/or `screenshot_group` for all tests
|
172
|
-
|
173
|
-
Setting the `screenshot_section` and/or `screenshot_group` for all tests can be
|
174
|
-
done in the super class setup:
|
175
|
-
|
176
|
-
```ruby
|
177
|
-
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
178
|
-
setup do
|
179
|
-
screenshot_section class_name.underscore.sub(/(_feature|_system)?_test$/, '')
|
180
|
-
screenshot_group name[5..-1]
|
181
|
-
end
|
182
|
-
end
|
183
|
-
```
|
184
|
-
|
185
|
-
`screenshot_section` and/or `screenshot_group` can still be overridden in each
|
186
|
-
test.
|
187
|
-
|
188
|
-
|
189
|
-
### Capturing one area instead of the whole page
|
190
|
-
|
191
|
-
You can crop images before comparison to be run, by providing region to crop as `[left, top, right, bottom]` or by css selector like `body .tag`
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
test 'the cool' do
|
195
|
-
visit '/feature'
|
196
|
-
screenshot 'cool_element', crop: '#my_element'
|
197
|
-
end
|
198
|
-
```
|
199
|
-
|
200
|
-
|
201
|
-
### Multiple Capybara drivers
|
202
|
-
|
203
|
-
Often it is useful to test your app using different browsers. To avoid the
|
204
|
-
screenshots for different Capybara drivers to overwrite each other, set
|
205
|
-
|
206
|
-
```ruby
|
207
|
-
Capybara::Screenshot.add_driver_path = true
|
208
|
-
```
|
209
|
-
|
210
|
-
The example above will then save your screenshots like this
|
211
|
-
(for poltergeist and selenium):
|
212
|
-
|
213
|
-
```
|
214
|
-
doc
|
215
|
-
screenshots
|
216
|
-
poltergeist
|
217
|
-
useful_feature
|
218
|
-
00-welcome_index
|
219
|
-
01-feature_index
|
220
|
-
02-action_performed
|
221
|
-
selenium
|
222
|
-
useful_feature
|
223
|
-
00-welcome_index
|
224
|
-
01-feature_index
|
225
|
-
02-action_performed
|
226
|
-
```
|
227
|
-
|
228
|
-
### Multiple OSs
|
229
|
-
|
230
|
-
If you run your tests on multiple operating systems, you will most likely find
|
231
|
-
the screen shots differ. To avoid the screenshots for different OSs to
|
232
|
-
overwrite each other, set
|
233
|
-
|
234
|
-
```ruby
|
235
|
-
Capybara::Screenshot.add_os_path = true
|
236
|
-
```
|
237
|
-
|
238
|
-
The example above will then save your screenshots like this
|
239
|
-
(for Linux and Windows):
|
240
|
-
|
241
|
-
```
|
242
|
-
doc
|
243
|
-
screenshots
|
244
|
-
linux
|
245
|
-
useful_feature
|
246
|
-
00-welcome_index
|
247
|
-
01-feature_index
|
248
|
-
02-action_performed
|
249
|
-
windows
|
250
|
-
useful_feature
|
251
|
-
00-welcome_index
|
252
|
-
01-feature_index
|
253
|
-
02-action_performed
|
254
|
-
```
|
255
|
-
|
256
|
-
If you combine this config with the `add_driver_path` config, the driver will be
|
257
|
-
put in front of the OS name.
|
258
|
-
|
259
|
-
### Screen size
|
260
|
-
|
261
|
-
You can specify the desired screen size using
|
262
|
-
|
263
|
-
```ruby
|
264
|
-
Capybara::Screenshot.window_size = [1024, 768]
|
265
|
-
```
|
266
|
-
|
267
|
-
This will force the screen shots to the given size, and skip taking screen shots
|
268
|
-
unless the desired window size can be achieved.
|
269
|
-
|
270
|
-
### Disabling screen shots
|
271
|
-
|
272
|
-
If you want to skip taking screen shots, set
|
273
|
-
|
274
|
-
```ruby
|
275
|
-
Capybara::Screenshot.enabled = false
|
276
|
-
```
|
277
|
-
|
278
|
-
You can of course set this by an environment variable
|
279
|
-
|
280
|
-
```ruby
|
281
|
-
Capybara::Screenshot.enabled = ENV['TAKE_SCREENSHOTS']
|
282
|
-
```
|
283
|
-
|
284
|
-
### Disabling diff
|
285
|
-
|
286
|
-
If you want to skip the assertion for change in the screen shot, set
|
287
|
-
|
288
|
-
```ruby
|
289
|
-
Capybara::Screenshot::Diff.enabled = false
|
290
|
-
```
|
291
|
-
|
292
|
-
Using an environment variable
|
293
|
-
|
294
|
-
```ruby
|
295
|
-
Capybara::Screenshot::Diff.enabled = ENV['COMPARE_SCREENSHOTS']
|
296
|
-
```
|
297
|
-
|
298
|
-
### Screen shot save path
|
299
|
-
|
300
|
-
By default, `Capybara::Screenshot::Diff` saves screenshots to a
|
301
|
-
`doc/screenshots` folder, relative to either `Rails.root` (if you're in Rails),
|
302
|
-
or your current directory otherwise.
|
303
|
-
|
304
|
-
If you want to change where screenshots are saved to, then there are two
|
305
|
-
configuration options that that are relevant.
|
306
|
-
|
307
|
-
The most likely one you'll want to modify is ...
|
308
|
-
|
309
|
-
```ruby
|
310
|
-
Capybara::Screenshot.save_path = "other/path"
|
311
|
-
```
|
312
|
-
|
313
|
-
The `save_path` option is relative to `Capybara::Screenshot.root`.
|
314
|
-
|
315
|
-
`Capybara::Screenshot.root` defaults to either `Rails.root` (if you're in
|
316
|
-
Rails) or your current directory. You can change it to something entirely
|
317
|
-
different if necessary, such as when using an alternative web framework.
|
318
|
-
|
319
|
-
```ruby
|
320
|
-
Capybara::Screenshot.root = Hanami.root
|
321
|
-
```
|
322
|
-
|
323
|
-
### Screen shot stability
|
324
|
-
|
325
|
-
To ensure that animations are finished before saving a screen shot, you can add
|
326
|
-
a stability time limit. If the stability time limit is set, a second screen
|
327
|
-
shot will be taken and compared to the first. This is repeated until two
|
328
|
-
subsequent screen shots are identical.
|
329
|
-
|
330
|
-
```ruby
|
331
|
-
Capybara::Screenshot.stability_time_limit = 0.1
|
332
|
-
```
|
333
|
-
|
334
|
-
This can be overridden on a single screenshot:
|
335
|
-
|
336
|
-
```ruby
|
337
|
-
test 'stability_time_limit' do
|
338
|
-
visit '/'
|
339
|
-
screenshot 'index', stability_time_limit: 0.5
|
340
|
-
end
|
341
|
-
```
|
342
|
-
|
343
|
-
### Maximum wait limit
|
344
|
-
|
345
|
-
When the `stability_time_limit` is set, but no stable screenshot can be taken, a timeout occurs.
|
346
|
-
The timeout occurs after `Capybara.default_max_wait_time`, but can be overridden by an option.
|
347
|
-
|
348
|
-
```ruby
|
349
|
-
test 'max wait time' do
|
350
|
-
visit '/'
|
351
|
-
screenshot 'index', wait: 20.seconds
|
352
|
-
end
|
353
|
-
```
|
354
|
-
|
355
|
-
### Hiding the caret for active input elements
|
356
|
-
|
357
|
-
In Chrome the screenshot includes the blinking input cursor. This can make it impossible to get a
|
358
|
-
stable screenshot. To get around this you can set the `hide caret` option:
|
359
|
-
|
360
|
-
```ruby
|
361
|
-
Capybara::Screenshot.hide_caret = true
|
362
|
-
```
|
363
|
-
|
364
|
-
This will make the cursor (caret) transparent (invisible), so the blinking does not delay the screen shot.
|
365
|
-
|
366
|
-
|
367
|
-
### Removing focus from the active element
|
368
|
-
|
369
|
-
Another way to avoid the cursor blinking is to set the `blur_active_element` option:
|
370
|
-
|
371
|
-
```ruby
|
372
|
-
Capybara::Screenshot.blur_active_element = true
|
373
|
-
```
|
374
|
-
|
375
|
-
This will remove the focus from the active element, removing the blinking cursor.
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
### Allowed color distance
|
380
|
-
|
381
|
-
Sometimes you want to allow small differences in the images. For example, Chrome renders the same
|
382
|
-
page slightly differently sometimes. You can set set the color difference threshold for the
|
383
|
-
comparison using the `color_distance_limit` option to the `screenshot` method:
|
384
|
-
|
385
|
-
```ruby
|
386
|
-
test 'color threshold' do
|
387
|
-
visit '/'
|
388
|
-
screenshot 'index', color_distance_limit: 30
|
389
|
-
end
|
390
|
-
```
|
391
|
-
|
392
|
-
The difference is calculated as the eucledian distance. You can also set this globally:
|
393
|
-
|
394
|
-
```ruby
|
395
|
-
Capybara::Screenshot::Diff.color_distance_limit = 42
|
396
|
-
```
|
397
|
-
|
398
|
-
|
399
|
-
### Allowed shift distance
|
400
|
-
|
401
|
-
Sometimes you want to allow small movements in the images. For example, jquer-tablesorter
|
402
|
-
renders the same table slightly differently sometimes. You can set set the shift distance
|
403
|
-
threshold for the comparison using the `shift_distance_limit` option to the `screenshot`
|
404
|
-
method:
|
405
|
-
|
406
|
-
```ruby
|
407
|
-
test 'color threshold' do
|
408
|
-
visit '/'
|
409
|
-
screenshot 'index', shift_distance_limit: 2
|
410
|
-
end
|
411
|
-
```
|
412
|
-
|
413
|
-
The difference is calculated as maximum distance in either the X or the Y axis.
|
414
|
-
You can also set this globally:
|
415
|
-
|
416
|
-
```ruby
|
417
|
-
Capybara::Screenshot::Diff.shift_distance_limit = 1
|
418
|
-
```
|
419
|
-
|
420
|
-
**Note:** For each increase in `shift_distance_limit` more pixels are searched for a matching color value, and
|
421
|
-
this will impact performance **severely** if a match cannot be found.
|
422
|
-
|
423
|
-
If `shift_distance_limit` is `nil` shift distance is not measured. If `shift_distance_limit` is set,
|
424
|
-
even to `0`, shift distance is measured and reported on image differences.
|
425
|
-
|
426
|
-
### Allowed difference size
|
427
|
-
|
428
|
-
You can set set a threshold for the differing area size for the comparison
|
429
|
-
using the `area_size_limit` option to the `screenshot` method:
|
430
|
-
|
431
|
-
```ruby
|
432
|
-
test 'area threshold' do
|
433
|
-
visit '/'
|
434
|
-
screenshot 'index', area_size_limit: 17
|
435
|
-
end
|
436
|
-
```
|
437
|
-
|
438
|
-
The difference is calculated as `width * height`. You can also set this globally:
|
439
|
-
|
440
|
-
```ruby
|
441
|
-
Capybara::Screenshot::Diff.area_size_limit = 42
|
442
|
-
```
|
443
|
-
|
444
|
-
|
445
|
-
### Skipping an area
|
446
|
-
|
447
|
-
Sometimes you have expected change that you want to ignore.
|
448
|
-
You can use the `skip_area` option with `[left, top, right, bottom]`
|
449
|
-
or css selector like `'#footer'` or `'.container .skipped_element'` to the `screenshot` method to ignore an area:
|
450
|
-
|
451
|
-
```ruby
|
452
|
-
test 'unstable area' do
|
453
|
-
visit '/'
|
454
|
-
screenshot 'index', skip_area: [[17, 6, 27, 16], '.container .skipped_element', '#footer']
|
455
|
-
end
|
456
|
-
```
|
457
|
-
|
458
|
-
The arguments are `[left, top, right, bottom]` for the area you want to ignore. You can also set this globally:
|
459
|
-
|
460
|
-
```ruby
|
461
|
-
Capybara::Screenshot::Diff.skip_area = [0, 0, 64, 48]
|
462
|
-
```
|
463
|
-
|
464
|
-
If you need to ignore multiple areas:
|
465
|
-
|
466
|
-
```ruby
|
467
|
-
screenshot 'index', skip_area: [[0, 0, 64, 48], [17, 6, 27, 16], 'css_selector .element']
|
468
|
-
```
|
469
|
-
|
470
|
-
### Available Image Processing Drivers
|
471
|
-
|
472
|
-
There are several image processing supported by this gem.
|
473
|
-
There are several options to setup active driver: `:auto`, `:chunky_png` and `:vips`.
|
474
|
-
|
475
|
-
* `:auto` - will try to load `:vips` if there is gem `ruby-vips`, in other cases will load `:chunky_png`
|
476
|
-
* `:chunky_png` and `:vips` will load correspondent driver
|
477
|
-
|
478
|
-
### Enable VIPS image processing
|
479
|
-
|
480
|
-
[Vips](https://www.rubydoc.info/gems/ruby-vips/Vips/Image) driver provides a faster comparison,
|
481
|
-
and could be enabled by adding `ruby-vips` to `Gemfile`.
|
482
|
-
|
483
|
-
If need to setup explicitly Vips driver, there are several ways to do this:
|
484
|
-
|
485
|
-
* Globally: `Capybara::Screenshot::Diff.driver = :vips`
|
486
|
-
* Per screenshot option: `screenshot 'index', driver: :vips`
|
487
|
-
|
488
|
-
With enabled VIPS there are new alternatives to process differences, which easier to find and support.
|
489
|
-
For example, `shift_distance_limit` is very heavy operation. Instead better to use `median_filter_window_size`.
|
490
|
-
|
491
|
-
#### Tolerance level (vips only)
|
492
|
-
|
493
|
-
You can set a “tolerance” anywhere from 0% to 100%. This is the amount of change that's allowable.
|
494
|
-
If the screenshot has changed by more than that amount, it'll flag it as a failure.
|
495
|
-
|
496
|
-
This is alternative to "Allowed difference size", only the difference that area calculates including valid pixels.
|
497
|
-
But "tolerance" compares only different pixels.
|
498
|
-
|
499
|
-
You can use the `tolerance` option to the `screenshot` method to set level:
|
500
|
-
|
501
|
-
```ruby
|
502
|
-
test 'unstable area' do
|
503
|
-
visit '/'
|
504
|
-
screenshot 'index', tolerance: 0.3
|
505
|
-
end
|
506
|
-
```
|
507
|
-
|
508
|
-
You can also set this globally:
|
509
|
-
|
510
|
-
```ruby
|
511
|
-
Capybara::Screenshot::Diff.tolerance = 0.3
|
512
|
-
```
|
513
|
-
|
514
|
-
#### Median filter size (vips only)
|
515
|
-
|
516
|
-
This is an alternative to "Allowed shift distance", but much faster.
|
517
|
-
You can find more about this strategy on [Median Filter](https://en.wikipedia.org/wiki/Median_filter).
|
518
|
-
Think about this like smoothing of the image, before comparison.
|
519
|
-
|
520
|
-
You can use the `median_filter_window_size` option to the `screenshot` method to set level:
|
521
|
-
|
522
|
-
```ruby
|
523
|
-
test 'unstable area' do
|
524
|
-
visit '/'
|
525
|
-
screenshot 'index', median_filter_window_size: 2
|
526
|
-
end
|
527
|
-
```
|
528
|
-
|
529
|
-
### Skipping stack frames in the error output
|
530
|
-
|
531
|
-
If you would like to override the `screenshot` method or for some other reason would like to skip stack
|
532
|
-
frames when reporting image differences, you can use the `skip_stack_frames` option:
|
533
|
-
|
534
|
-
```ruby
|
535
|
-
test 'test visiting the index' do
|
536
|
-
visit root_path
|
537
|
-
screenshot :index
|
538
|
-
end
|
539
|
-
|
540
|
-
private
|
541
|
-
|
542
|
-
def screenshot(name, **options)
|
543
|
-
super(name, skip_stack_frames: 1, **options)
|
544
|
-
end
|
545
|
-
```
|
546
|
-
|
547
|
-
## Development
|
548
|
-
|
549
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
550
|
-
Then, run `rake test` to run the tests.
|
551
|
-
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
552
|
-
|
553
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
554
|
-
|
555
|
-
To release a new version, update the version number in `lib/capybara/screenshot/diff/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
556
|
-
|
557
|
-
## Contributing
|
558
|
-
|
559
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff.
|
560
|
-
This project is intended to be a safe, welcoming space for collaboration,
|
561
|
-
and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
562
|
-
|
563
|
-
|
564
|
-
## License
|
565
|
-
|
566
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
567
|
-
|