capybara-screenshot-diff 1.3.0 → 1.5.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/.gitattributes +4 -0
- data/.github/workflows/test.yml +138 -0
- data/.gitignore +1 -1
- data/.standard.yml +11 -0
- data/Dockerfile +60 -0
- data/README.md +87 -3
- data/Rakefile +10 -8
- data/bin/console +3 -3
- data/bin/install-vips +11 -0
- data/bin/standardrb +29 -0
- data/capybara-screenshot-diff.gemspec +18 -26
- data/gemfiles/rails42.gemfile +4 -2
- data/gemfiles/rails50.gemfile +3 -2
- data/gemfiles/rails51.gemfile +3 -2
- data/gemfiles/rails52.gemfile +3 -2
- data/gemfiles/rails60_gems.rb +8 -0
- data/gemfiles/rails61_gems.rb +7 -0
- data/gems.rb +29 -0
- data/lib/capybara/screenshot/diff.rb +24 -14
- data/lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb +355 -0
- data/lib/capybara/screenshot/diff/drivers/utils.rb +24 -0
- data/lib/capybara/screenshot/diff/drivers/vips_driver.rb +180 -0
- data/lib/capybara/screenshot/diff/image_compare.rb +144 -288
- data/lib/capybara/screenshot/diff/os.rb +7 -7
- data/lib/capybara/screenshot/diff/stabilization.rb +89 -37
- data/lib/capybara/screenshot/diff/test_methods.rb +46 -55
- data/lib/capybara/screenshot/diff/vcs.rb +8 -3
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- data/matrix_test.rb +20 -22
- metadata +21 -112
- data/.rubocop.yml +0 -62
- data/.rubocop_todo.yml +0 -52
- data/.travis.yml +0 -30
- data/Gemfile +0 -6
- data/gemfiles/common.gemfile +0 -12
- data/gemfiles/rails60.gemfile +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ea29ec1e5ab38bc1c6eb4eafb7f01bb6fbbf2ca85ea7bbbc8f19dc1bbe9f101
|
4
|
+
data.tar.gz: 71150ea0adabe29276710229034975d66ba9d7029913a6af618e3a1b91d2a6bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3019d948c07af6e81fc4b54afc98f1ca17565995e8028edc0120127db530d651dcc2cab950df0696ddcdc4964181d05776cf7fe01e616e6e06225a17ba3fe8a5
|
7
|
+
data.tar.gz: 863ee41be9dc9b37311a14ab9eb279230ed7f123f82adee3e644ab558f60921619106d32e0b125857684baea74deadb18c5b3ea70b5691ed2efbc0fdfddf34c4
|
data/.gitattributes
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ $default-branch ]
|
6
|
+
pull_request_target:
|
7
|
+
branches: [ $default-branch ]
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
env:
|
11
|
+
BUNDLE_GEMFILE: 'gemfiles/rails61_gems.rb'
|
12
|
+
FERRUM_PROCESS_TIMEOUT: '15'
|
13
|
+
WD_CACHE_TIME: '864000' # 10 days
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
lint:
|
17
|
+
name: Lint
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- name: Checkout code
|
22
|
+
uses: actions/checkout@v2
|
23
|
+
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: '2.7'
|
28
|
+
bundler-cache: true
|
29
|
+
|
30
|
+
- name: Run Standard Ruby linter
|
31
|
+
run: bin/standardrb --no-fix --fail-fast
|
32
|
+
|
33
|
+
test:
|
34
|
+
name: Functional Testing
|
35
|
+
runs-on: ubuntu-20.04 # In order to install libvips 8.9+ version
|
36
|
+
|
37
|
+
steps:
|
38
|
+
- name: Checkout code
|
39
|
+
uses: actions/checkout@v2
|
40
|
+
|
41
|
+
- name: Set up Ruby
|
42
|
+
uses: ruby/setup-ruby@v1
|
43
|
+
with:
|
44
|
+
ruby-version: '2.7'
|
45
|
+
bundler-cache: true
|
46
|
+
|
47
|
+
- name: Install libvips
|
48
|
+
run: sudo apt install libvips libvips-dev libvips-tools
|
49
|
+
|
50
|
+
- name: Run Tests with coverage
|
51
|
+
run: bundle exec rake test
|
52
|
+
env:
|
53
|
+
COVERAGE: enabled
|
54
|
+
|
55
|
+
- name: Upload Screenshots
|
56
|
+
if: ${{ always() }}
|
57
|
+
uses: actions/upload-artifact@v2
|
58
|
+
with:
|
59
|
+
path: test/fixtures/app/doc/screenshots/
|
60
|
+
|
61
|
+
- name: Upload Coverage
|
62
|
+
uses: actions/upload-artifact@v2
|
63
|
+
with:
|
64
|
+
name: coverage
|
65
|
+
path: coverage
|
66
|
+
|
67
|
+
matrix:
|
68
|
+
name: Test Integration
|
69
|
+
needs: [ 'test', 'lint' ]
|
70
|
+
runs-on: ubuntu-20.04
|
71
|
+
|
72
|
+
strategy:
|
73
|
+
matrix:
|
74
|
+
ruby-version: [ '2.7', '2.6', '2.5', 'jruby' ]
|
75
|
+
gemfile:
|
76
|
+
- 'rails61_gems.rb'
|
77
|
+
- 'rails60_gems.rb'
|
78
|
+
- 'rails52.gemfile'
|
79
|
+
- 'rails51.gemfile'
|
80
|
+
- 'rails50.gemfile'
|
81
|
+
- 'rails42.gemfile'
|
82
|
+
include:
|
83
|
+
- ruby-version: '3.0'
|
84
|
+
gemfile: 'rails61_gems.rb'
|
85
|
+
- ruby-version: '3.0'
|
86
|
+
gemfile: 'rails60_gems.rb'
|
87
|
+
|
88
|
+
|
89
|
+
env:
|
90
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
|
91
|
+
|
92
|
+
steps:
|
93
|
+
- name: Checkout code
|
94
|
+
uses: actions/checkout@v2
|
95
|
+
|
96
|
+
- name: Set up Ruby
|
97
|
+
uses: ruby/setup-ruby@v1
|
98
|
+
with:
|
99
|
+
ruby-version: ${{ matrix.ruby-version }}
|
100
|
+
bundler-cache: true
|
101
|
+
|
102
|
+
- name: Install libvips
|
103
|
+
run: sudo apt install libvips libvips-dev libvips-tools
|
104
|
+
|
105
|
+
- name: Run tests
|
106
|
+
run: bundle exec rake test
|
107
|
+
|
108
|
+
matrix_screenshot_driver:
|
109
|
+
name: Test Integration
|
110
|
+
needs: [ 'test', 'lint' ]
|
111
|
+
runs-on: ubuntu-20.04
|
112
|
+
|
113
|
+
strategy:
|
114
|
+
matrix:
|
115
|
+
screenshot-driver: [ 'vips', 'chunky_png' ]
|
116
|
+
capybara-driver: [ 'selenium_headless', 'selenium_chrome_headless' ]
|
117
|
+
include:
|
118
|
+
- screenshot-driver: 'chunky_png'
|
119
|
+
capybara-driver: 'cuprite'
|
120
|
+
|
121
|
+
steps:
|
122
|
+
- name: Checkout code
|
123
|
+
uses: actions/checkout@v2
|
124
|
+
|
125
|
+
- name: Set up Ruby
|
126
|
+
uses: ruby/setup-ruby@v1
|
127
|
+
with:
|
128
|
+
ruby-version: '2.7'
|
129
|
+
bundler-cache: true
|
130
|
+
|
131
|
+
- name: Install libvips
|
132
|
+
run: sudo apt install libvips libvips-dev libvips-tools
|
133
|
+
|
134
|
+
- name: Run tests
|
135
|
+
run: bundle exec rake test:integration
|
136
|
+
env:
|
137
|
+
SCREENSHOT_DRIVER: ${{ matrix.screenshot-driver }}
|
138
|
+
CAPYBARA_DRIVER: ${{ matrix.capybara-driver }}
|
data/.gitignore
CHANGED
data/.standard.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
fix: true # default: false
|
2
|
+
parallel: true # default: false
|
3
|
+
format: progress # default: Standard::Formatter
|
4
|
+
ruby_version: 2.5 # default: RUBY_VERSION
|
5
|
+
default_ignores: false # default: true
|
6
|
+
|
7
|
+
ignore: # default: []
|
8
|
+
- 'gemfiles/**/*':
|
9
|
+
- Security/Eval
|
10
|
+
- 'gemfiles/vendor/**/*'
|
11
|
+
- 'vendor/**/*'
|
data/Dockerfile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Usage:
|
2
|
+
#
|
3
|
+
# $ docker build . -t csd
|
4
|
+
# $ docker run -v $(pwd):/app -ti csd rake test
|
5
|
+
|
6
|
+
ARG RUBY_VERSION=2.7.2
|
7
|
+
|
8
|
+
FROM circleci/ruby:2.7.2-node-browsers
|
9
|
+
|
10
|
+
RUN \
|
11
|
+
# Install dependencies
|
12
|
+
sudo apt-get update && \
|
13
|
+
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
|
14
|
+
automake \
|
15
|
+
build-essential \
|
16
|
+
curl \
|
17
|
+
fftw3-dev \
|
18
|
+
gettext \
|
19
|
+
gobject-introspection \
|
20
|
+
gtk-doc-tools \
|
21
|
+
libexif-dev \
|
22
|
+
libfftw3-dev \
|
23
|
+
libgif-dev \
|
24
|
+
libglib2.0-dev \
|
25
|
+
libgsf-1-dev \
|
26
|
+
libgtk2.0-dev \
|
27
|
+
libmagickwand-dev \
|
28
|
+
libmatio-dev \
|
29
|
+
libopenexr-dev \
|
30
|
+
libopenslide-dev \
|
31
|
+
liborc-0.4-dev \
|
32
|
+
libpango1.0-dev \
|
33
|
+
libpoppler-glib-dev \
|
34
|
+
librsvg2-dev \
|
35
|
+
libtiff5-dev \
|
36
|
+
libwebp-dev \
|
37
|
+
libxml2-dev \
|
38
|
+
swig
|
39
|
+
|
40
|
+
|
41
|
+
WORKDIR /app
|
42
|
+
RUN sudo chmod a+w -R /app
|
43
|
+
|
44
|
+
ADD ./bin/install-vips /app/bin/
|
45
|
+
RUN sudo /app/bin/install-vips
|
46
|
+
|
47
|
+
ADD ./lib/capybara/screenshot/diff/version.rb /app/lib/capybara/screenshot/diff/
|
48
|
+
ADD ./capybara-screenshot-diff.gemspec /app/
|
49
|
+
ADD ./gems.rb /app/
|
50
|
+
|
51
|
+
RUN bundle install
|
52
|
+
|
53
|
+
RUN \
|
54
|
+
# Clean up
|
55
|
+
sudo apt-get remove -y curl automake build-essential && \
|
56
|
+
sudo apt-get autoremove -y && \
|
57
|
+
sudo apt-get autoclean && \
|
58
|
+
sudo apt-get clean && \
|
59
|
+
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
60
|
+
|
data/README.md
CHANGED
@@ -27,6 +27,10 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
$ gem install capybara-screenshot-diff
|
29
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
|
+
|
30
34
|
## Usage
|
31
35
|
|
32
36
|
### Minitest
|
@@ -164,6 +168,24 @@ doc
|
|
164
168
|
```
|
165
169
|
|
166
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
|
+
|
167
189
|
|
168
190
|
### Multiple Capybara drivers
|
169
191
|
|
@@ -274,7 +296,7 @@ configuration options that that are relevant.
|
|
274
296
|
The most likely one you'll want to modify is ...
|
275
297
|
|
276
298
|
```ruby
|
277
|
-
Capybara::Screenshot
|
299
|
+
Capybara::Screenshot.save_path = "other/path"
|
278
300
|
```
|
279
301
|
|
280
302
|
The `save_path` option is relative to `Capybara::Screenshot.root`.
|
@@ -434,10 +456,70 @@ If you need to ignore multiple areas, you can supply an array of arrays:
|
|
434
456
|
screenshot 'index', skip_area: [[0, 0, 64, 48], [17, 6, 27, 16]]
|
435
457
|
```
|
436
458
|
|
459
|
+
### Available Image Processing Drivers
|
460
|
+
|
461
|
+
There are several image processing supported by this gem.
|
462
|
+
There are several options to setup active driver: `:auto`, `:chunky_png` and `:vips`.
|
463
|
+
|
464
|
+
* `:auto` - will try to load `:vips` if there is gem `ruby-vips`, in other cases will load `:chunky_png`
|
465
|
+
* `:chunky_png` and `:vips` will load correspondent driver
|
466
|
+
|
467
|
+
### Enable VIPS image processing
|
468
|
+
|
469
|
+
[Vips](https://www.rubydoc.info/gems/ruby-vips/Vips/Image) driver provides a faster comparison,
|
470
|
+
and could be enabled by adding `ruby-vips` to `Gemfile`.
|
471
|
+
|
472
|
+
If need to setup explicitly Vips driver, there are several ways to do this:
|
473
|
+
|
474
|
+
* Globally: `Capybara::Screenshot::Diff.driver = :vips`
|
475
|
+
* Per screenshot option: `screenshot 'index', driver: :vips`
|
476
|
+
|
477
|
+
With enabled VIPS there are new alternatives to process differences, which easier to find and support.
|
478
|
+
For example, `shift_distance_limit` is very heavy operation. Instead better to use `median_filter_window_size`.
|
479
|
+
|
480
|
+
#### Tolerance level (vips only)
|
481
|
+
|
482
|
+
You can set a “tolerance” anywhere from 0% to 100%. This is the amount of change that's allowable.
|
483
|
+
If the screenshot has changed by more than that amount, it'll flag it as a failure.
|
484
|
+
|
485
|
+
This is alternative to "Allowed difference size", only the difference that area calculates including valid pixels.
|
486
|
+
But "tolerance" compares only different pixels.
|
487
|
+
|
488
|
+
You can use the `tolerance` option to the `screenshot` method to set level:
|
489
|
+
|
490
|
+
```ruby
|
491
|
+
test 'unstable area' do
|
492
|
+
visit '/'
|
493
|
+
screenshot 'index', tolerance: 0.3
|
494
|
+
end
|
495
|
+
```
|
496
|
+
|
497
|
+
You can also set this globally:
|
498
|
+
|
499
|
+
```ruby
|
500
|
+
Capybara::Screenshot::Diff.tolerance = 0.3
|
501
|
+
```
|
502
|
+
|
503
|
+
#### Median filter size (vips only)
|
504
|
+
|
505
|
+
This is an alternative to "Allowed shift distance", but much faster.
|
506
|
+
You can find more about this strategy on [Median Filter](https://en.wikipedia.org/wiki/Median_filter).
|
507
|
+
Think about this like smoothing of the image, before comparison.
|
508
|
+
|
509
|
+
You can use the `median_filter_window_size` option to the `screenshot` method to set level:
|
510
|
+
|
511
|
+
```ruby
|
512
|
+
test 'unstable area' do
|
513
|
+
visit '/'
|
514
|
+
screenshot 'index', median_filter_window_size: 2
|
515
|
+
end
|
516
|
+
```
|
437
517
|
|
438
518
|
## Development
|
439
519
|
|
440
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
520
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
521
|
+
Then, run `rake test` to run the tests.
|
522
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
441
523
|
|
442
524
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
443
525
|
|
@@ -445,7 +527,9 @@ To release a new version, update the version number in `lib/capybara/screenshot/
|
|
445
527
|
|
446
528
|
## Contributing
|
447
529
|
|
448
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff.
|
530
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff.
|
531
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
532
|
+
and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
449
533
|
|
450
534
|
|
451
535
|
## License
|
data/Rakefile
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
5
|
|
6
6
|
task default: :test
|
7
7
|
|
8
8
|
Rake::TestTask.new(:test) do |t|
|
9
|
-
t.libs <<
|
10
|
-
t.libs <<
|
11
|
-
t.test_files = FileList[
|
9
|
+
t.libs << "test"
|
10
|
+
t.libs << "lib"
|
11
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
Rake::TestTask.new("test:integration") do |t|
|
15
|
+
t.libs << "test"
|
16
|
+
t.libs << "lib"
|
17
|
+
t.test_files = FileList["test/integration/**/*_test.rb"]
|
18
|
+
end
|
data/bin/console
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "bundler/setup"
|
5
|
+
require "capybara/screenshot/diff"
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -11,5 +11,5 @@ require 'capybara/screenshot/diff'
|
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
|
-
require
|
14
|
+
require "irb"
|
15
15
|
IRB.start
|
data/bin/install-vips
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
version=${VIPS_VERSION:-8.10.0}
|
6
|
+
|
7
|
+
wget "https://github.com/libvips/libvips/releases/download/v$version/vips-$version.tar.gz"
|
8
|
+
tar xf "vips-$version.tar.gz"
|
9
|
+
cd "vips-$version"
|
10
|
+
CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 ./configure --enable-debug=no --without-python "$*"
|
11
|
+
make && make install && ldconfig
|
data/bin/standardrb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("standard", "standardrb")
|