capybara-screenshot-diff 1.1.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4b74b3421312a6837944115244ae03eb5b59b65b28dd21fed17ad9f13672b32
4
- data.tar.gz: 9d60292db9261447214601ff3e498adb81cb5ce51899db8c19f18ac66ea53d6c
3
+ metadata.gz: 36a36588af46fa270b2ceefd1961ff3d5c1038c19207228d318335bc89bfb25a
4
+ data.tar.gz: dfc8f5c3e53a90d20a0495aa711de8673f911921ccf8a80f2f65424ea80aba2a
5
5
  SHA512:
6
- metadata.gz: c529cfbf50e5b11251d4c44115713a99aac84c712dc62770d6cdc735adeba814ffc62e68acaa2fdf8e77fc6171b37269b37fbb2d669915a80a44c4d9ef7a523a
7
- data.tar.gz: 9b6f02f0c296a53fca5acba02b36b838bc83ac8616606029f44122a08537b930e122ce1398ec152f2dfc02e65b207042ba24c37f899cb7d6586c2588c6cd60f6
6
+ metadata.gz: 297bfe8a02628427201a60a3c3411f10310baa9e6501af8564b8b7b752aabb8f0e6ebd287eb2e8b20e0c8e3818c00badb7ef2978c8b471958fca16fe4b6d1bfd
7
+ data.tar.gz: 6bd4276e3cf6f1f8a5b2d59eaf8d4121c49c598824463b7112f83f7434d9b744724edf95cd933c3ea2a61e4946926cdfac1b4745536952cbde48ebcb31532be6
@@ -0,0 +1,4 @@
1
+ *.gemspec diff=ruby
2
+ *.rake diff=ruby
3
+ *.rb diff=ruby
4
+ *.md diff=md
@@ -0,0 +1,129 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ $default-branch ]
6
+ pull_request:
7
+
8
+ env:
9
+ BUNDLE_GEMFILE: 'gemfiles/rails61_gems.rb'
10
+ FERRUM_PROCESS_TIMEOUT: '15'
11
+ WD_CACHE_TIME: '864000' # 10 days
12
+
13
+ jobs:
14
+ lint:
15
+ name: Lint
16
+ runs-on: ubuntu-latest
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v2
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: '2.7'
26
+ bundler-cache: true
27
+
28
+ - name: Run Standard Ruby linter
29
+ run: bin/standardrb --no-fix --fail-fast
30
+
31
+ test:
32
+ name: Functional Testing
33
+ runs-on: ubuntu-20.04 # In order to install libvips 8.9+ version
34
+
35
+ steps:
36
+ - name: Checkout code
37
+ uses: actions/checkout@v2
38
+
39
+ - name: Set up Ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: '2.7'
43
+ bundler-cache: true
44
+
45
+ - name: Install libvips
46
+ run: sudo apt install libvips libvips-dev libvips-tools
47
+
48
+ - name: Run Tests with coverage
49
+ run: bundle exec rake test
50
+ env:
51
+ COVERAGE: enabled
52
+
53
+ - name: Upload Screenshots
54
+ if: ${{ always() }}
55
+ uses: actions/upload-artifact@v2
56
+ with:
57
+ path: test/fixtures/app/doc/screenshots/
58
+
59
+ - name: Upload Coverage
60
+ uses: actions/upload-artifact@v2
61
+ with:
62
+ name: coverage
63
+ path: coverage
64
+
65
+ matrix:
66
+ name: Test Integration
67
+ needs: [ 'test', 'lint' ]
68
+ runs-on: ubuntu-20.04
69
+
70
+ strategy:
71
+ matrix:
72
+ ruby-version: [ '2.7', '2.6', '2.5', 'jruby' ]
73
+ gemfile:
74
+ - 'rails61_gems.rb'
75
+ - 'rails60_gems.rb'
76
+ - 'rails52.gemfile'
77
+ - 'rails51.gemfile'
78
+ - 'rails50.gemfile'
79
+ - 'rails42.gemfile'
80
+ env:
81
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
82
+
83
+ steps:
84
+ - name: Checkout code
85
+ uses: actions/checkout@v2
86
+
87
+ - name: Set up Ruby
88
+ uses: ruby/setup-ruby@v1
89
+ with:
90
+ ruby-version: ${{ matrix.ruby-version }}
91
+ bundler-cache: true
92
+
93
+ - name: Install libvips
94
+ run: sudo apt install libvips libvips-dev libvips-tools
95
+
96
+ - name: Run tests
97
+ run: bundle exec rake test
98
+
99
+ matrix_screenshot_driver:
100
+ name: Test Integration
101
+ needs: [ 'test', 'lint' ]
102
+ runs-on: ubuntu-20.04
103
+
104
+ strategy:
105
+ matrix:
106
+ screenshot-driver: [ 'vips', 'chunky_png' ]
107
+ capybara-driver: [ 'selenium_headless', 'selenium_chrome_headless' ]
108
+ include:
109
+ - screenshot-driver: 'chunky_png'
110
+ capybara-driver: 'cuprite'
111
+
112
+ steps:
113
+ - name: Checkout code
114
+ uses: actions/checkout@v2
115
+
116
+ - name: Set up Ruby
117
+ uses: ruby/setup-ruby@v1
118
+ with:
119
+ ruby-version: '2.7'
120
+ bundler-cache: true
121
+
122
+ - name: Install libvips
123
+ run: sudo apt install libvips libvips-dev libvips-tools
124
+
125
+ - name: Run tests
126
+ run: bundle exec rake test:integration
127
+ env:
128
+ SCREENSHOT_DRIVER: ${{ matrix.screenshot-driver }}
129
+ CAPYBARA_DRIVER: ${{ matrix.capybara-driver }}
data/.gitignore CHANGED
@@ -2,11 +2,11 @@
2
2
  /.bundle/
3
3
  /.idea
4
4
  /.yardoc
5
- /Gemfile.lock
6
5
  /_yardoc/
7
6
  /coverage/
8
7
  /doc/
9
8
  /gemfiles/*.lock
9
+ /gems.locked
10
10
  /pkg/
11
11
  /spec/reports/
12
12
  /tmp/
@@ -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/**/*'
@@ -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::Diff.save_path = "other/path"
299
+ Capybara::Screenshot.save_path = "other/path"
278
300
  ```
279
301
 
280
302
  The `save_path` option is relative to `Capybara::Screenshot.root`.
@@ -295,10 +317,29 @@ shot will be taken and compared to the first. This is repeated until two
295
317
  subsequent screen shots are identical.
296
318
 
297
319
  ```ruby
298
- Capybara::Screenshot.stability_time_limit = 0.5
320
+ Capybara::Screenshot.stability_time_limit = 0.1
299
321
  ```
300
322
 
323
+ This can be overridden on a single screenshot:
301
324
 
325
+ ```ruby
326
+ test 'stability_time_limit' do
327
+ visit '/'
328
+ screenshot 'index', stability_time_limit: 0.5
329
+ end
330
+ ```
331
+
332
+ ### Maximum wait limit
333
+
334
+ When the `stability_time_limit` is set, but no stable screenshot can be taken, a timeout occurs.
335
+ The timeout occurs after `Capybara.default_max_wait_time`, but can be overridden by an option.
336
+
337
+ ```ruby
338
+ test 'max wait time' do
339
+ visit '/'
340
+ screenshot 'index', wait: 20.seconds
341
+ end
342
+ ```
302
343
 
303
344
  ### Removing focus from the active element
304
345
 
@@ -415,10 +456,70 @@ If you need to ignore multiple areas, you can supply an array of arrays:
415
456
  screenshot 'index', skip_area: [[0, 0, 64, 48], [17, 6, 27, 16]]
416
457
  ```
417
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
+ ```
418
517
 
419
518
  ## Development
420
519
 
421
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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.
422
523
 
423
524
  To install this gem onto your local machine, run `bundle exec rake install`.
424
525
 
@@ -426,7 +527,9 @@ To release a new version, update the version number in `lib/capybara/screenshot/
426
527
 
427
528
  ## Contributing
428
529
 
429
- Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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.
430
533
 
431
534
 
432
535
  ## License
data/Rakefile CHANGED
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
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 << 'test'
10
- t.libs << 'lib'
11
- t.test_files = FileList['test/**/*_test.rb']
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList["test/**/*_test.rb"]
12
12
  end
13
13
 
14
- require 'rubocop/rake_task'
15
- RuboCop::RakeTask.new
16
- task test: %i[rubocop:auto_correct]
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
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'capybara/screenshot/diff'
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 'irb'
14
+ require "irb"
15
15
  IRB.start
@@ -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