image_diff 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/image_diff.gemspec +34 -0
- data/lib/helpers/screenshot.rb +30 -0
- data/lib/image_diff.rb +12 -0
- data/lib/image_diff/differ/differ.rb +51 -0
- data/lib/image_diff/differ/image_diff.rb +43 -0
- data/lib/image_diff/differ/image_magick.rb +20 -0
- data/lib/image_diff/differ/results/list.rb +50 -0
- data/lib/image_diff/differ/results/output.rb +60 -0
- data/lib/image_diff/differ/results/result.rb +45 -0
- data/lib/image_diff/png_snapshot.rb +29 -0
- data/lib/image_diff/snapshot.rb +35 -0
- data/lib/image_diff/version.rb +5 -0
- data/lib/image_diff/writer/writer.rb +16 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e683fbd3804792c92b8e40c260909dcdda3d1ea9654059530ce153fc1f15314
|
4
|
+
data.tar.gz: d43baf340a58f2f64118ab7e13eb1bf34165fed757b9297dca05fb49652c7d2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71a3ab91a47531a9001a7ddb3f3b1600abd23c558d6e866415a5c96880631da6d4194bb2422d1b8ddc2ddd39b6aa52edc7218cc2d8b16a43553fb962063500f2
|
7
|
+
data.tar.gz: ef1f767a4750d154df6ed739ff0263b23c816b3dc243fab0d81b8811895ee96b7270dffeccf061cfbf0f0ff3669c2b1e08c26bbb539c9047062a6a15c690375b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
image_diff (0.1.0)
|
5
|
+
capybara (~> 3.31.0)
|
6
|
+
require_all (= 3.0.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
capybara (3.31.0)
|
15
|
+
addressable
|
16
|
+
mini_mime (>= 0.1.3)
|
17
|
+
nokogiri (~> 1.8)
|
18
|
+
rack (>= 1.6.0)
|
19
|
+
rack-test (>= 0.6.3)
|
20
|
+
regexp_parser (~> 1.5)
|
21
|
+
xpath (~> 3.2)
|
22
|
+
jaro_winkler (1.5.4)
|
23
|
+
mini_mime (1.0.2)
|
24
|
+
mini_portile2 (2.4.0)
|
25
|
+
nokogiri (1.10.9)
|
26
|
+
mini_portile2 (~> 2.4.0)
|
27
|
+
parallel (1.19.1)
|
28
|
+
parser (2.7.1.2)
|
29
|
+
ast (~> 2.4.0)
|
30
|
+
public_suffix (4.0.5)
|
31
|
+
rack (2.2.2)
|
32
|
+
rack-test (1.1.0)
|
33
|
+
rack (>= 1.0, < 3)
|
34
|
+
rainbow (3.0.0)
|
35
|
+
rake (12.3.3)
|
36
|
+
regexp_parser (1.7.0)
|
37
|
+
require_all (3.0.0)
|
38
|
+
rexml (3.2.4)
|
39
|
+
rubocop (0.80.0)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.7.0.1)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
rexml
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
47
|
+
ruby-progressbar (1.10.1)
|
48
|
+
unicode-display_width (1.6.1)
|
49
|
+
xpath (3.2.0)
|
50
|
+
nokogiri (~> 1.8)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
image_diff!
|
57
|
+
rake (~> 12.0)
|
58
|
+
rubocop (= 0.80.0)
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Dan Oades
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# ImageDiff
|
2
|
+
|
3
|
+
Ruby image comparison library for integration with automated Selenium tests and Cucumber. Use ImageDiff to take full page snapshot images of web pages and compare them against recent screenshots from Selenium/Capybara tests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'image_diff', git: 'git@github.com:ITV/image_diff.git'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
ImageDiff uses ImageMagick for screenshot manipulation, install it via HomeBrew:
|
18
|
+
|
19
|
+
```
|
20
|
+
brew install imagemagick
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Set up your Selenium/Cucumber project as usual and add the following profiles to `/config/cucumber.yml`:
|
26
|
+
|
27
|
+
```
|
28
|
+
generate_screenshots: IMAGE_DIFF=generate
|
29
|
+
visual_regression: IMAGE_DIFF=regression
|
30
|
+
```
|
31
|
+
|
32
|
+
Add ImageDiff to `features/support/env.rb`:
|
33
|
+
|
34
|
+
```
|
35
|
+
require 'image_diff'
|
36
|
+
```
|
37
|
+
|
38
|
+
Create a new cucumber hook to execute against tests tagged for visual testing in `features/support/hooks.rb`:
|
39
|
+
|
40
|
+
```
|
41
|
+
After '@visual_test' do |scenario|
|
42
|
+
filename = scenario.location
|
43
|
+
if ENV['IMAGE_DIFF'] == 'generate'
|
44
|
+
# Take a screenshot of the current Selenium/Capybara driver window and save to /reference
|
45
|
+
ImageDiff::PNGSnapshot.new('reference', filename).write
|
46
|
+
else
|
47
|
+
# Take a screenshot of the current Selenium/Capybara driver window and compare to same file in /reference folder
|
48
|
+
# If screenshots differ then a diff.png file will be generated
|
49
|
+
ImageDiff::PNGSnapshot.new('visual_regression', filename).compare
|
50
|
+
ImageDiff::Differ::Results::Output.flush
|
51
|
+
|
52
|
+
# Optional - fail the cucumber test if screenshot difference fails
|
53
|
+
expect(ImageDiff::Differ::Results::List.instance).to(
|
54
|
+
be_empty, 'Visual regression tests failed'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
Tag any cucumber feature tests with '@visual_test' and run the cucumber profile to generate reference screenshots for the test:
|
61
|
+
|
62
|
+
```
|
63
|
+
$ bundle exec cucumber -p generate_screenshots -t @visual_test
|
64
|
+
```
|
65
|
+
|
66
|
+
Replay the test and compare the result against the reference screenshot, if they match then the test will pass if not a diff.png file highlighting the differences will be generated:
|
67
|
+
|
68
|
+
```
|
69
|
+
$ bundle exec cucumber -p visual_regression -t @visual_test
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/itv/imagediff.
|
75
|
+
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'image_diff'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/image_diff.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/image_diff/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'image_diff'
|
7
|
+
spec.version = ImageDiff::VERSION
|
8
|
+
spec.authors = ['']
|
9
|
+
spec.email = ['daniel.oades@itv.com']
|
10
|
+
|
11
|
+
spec.summary = 'Full page screenshot comparison tool'
|
12
|
+
spec.description = 'Full page screenshot comparison tool for use with Capybara and Selenium'
|
13
|
+
spec.homepage = 'https://github.com/ITV/image_diff'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ITV/image_diff'
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency('capybara', '~> 3.31.0')
|
33
|
+
spec.add_dependency('require_all', '3.0.0')
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
# Screenshot helper
|
5
|
+
module Screenshot
|
6
|
+
def resize_window(width, height)
|
7
|
+
Capybara.page.driver.browser.manage.window.resize_to(width, height)
|
8
|
+
end
|
9
|
+
|
10
|
+
def fullpage_height
|
11
|
+
Capybara.page.evaluate_script(%(document.documentElement.offsetHeight + 100;))
|
12
|
+
end
|
13
|
+
|
14
|
+
def fullpage
|
15
|
+
size = Capybara.page.current_window.size
|
16
|
+
resize_window(size[0], fullpage_height)
|
17
|
+
end
|
18
|
+
|
19
|
+
def fullpage_screenshot(filename)
|
20
|
+
size = Capybara.page.current_window.size
|
21
|
+
resize_window(size[0], fullpage_height)
|
22
|
+
screenshot(filename)
|
23
|
+
resize_window(size[0], size[1])
|
24
|
+
end
|
25
|
+
|
26
|
+
def screenshot(filename)
|
27
|
+
Capybara.page.save_screenshot(filename)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/image_diff.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_rel 'results'
|
4
|
+
|
5
|
+
module ImageDiff
|
6
|
+
# Diff YAML files
|
7
|
+
module Differ
|
8
|
+
# TODO: Move this code smell
|
9
|
+
def reference_file
|
10
|
+
path_and_filename.sub(%r{^[^/]*}, 'reference')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Diff class
|
14
|
+
class Diff
|
15
|
+
include Differ::Results
|
16
|
+
|
17
|
+
attr_reader :snapshot
|
18
|
+
|
19
|
+
def initialize(snapshot)
|
20
|
+
@snapshot = snapshot
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def reference
|
25
|
+
@reference ||= @snapshot.reference_file
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Singleton to store differences
|
30
|
+
class Differences
|
31
|
+
extend Forwardable
|
32
|
+
include Singleton
|
33
|
+
|
34
|
+
def_delegators :@list, :map
|
35
|
+
|
36
|
+
def initialize(list = {})
|
37
|
+
@list = list
|
38
|
+
end
|
39
|
+
|
40
|
+
def []=(key, str)
|
41
|
+
@list[key] = str unless str.chomp.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: output failures separately from reference file misses
|
45
|
+
# also produce screenshot on failure
|
46
|
+
def self.result
|
47
|
+
instance.map { |diff| puts(*diff) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_rel 'image_magick'
|
4
|
+
|
5
|
+
# TODO: Refactor out ImageMagick code
|
6
|
+
module ImageDiff
|
7
|
+
module Differ
|
8
|
+
# ImageDiff class
|
9
|
+
class ImageDiff < Diff
|
10
|
+
def result
|
11
|
+
index, debug = ImageMagick.absolute_error(args)
|
12
|
+
send(%i[pass fail][index] || :error, debug)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def comparison
|
18
|
+
File.join(snapshot.fullpath, snapshot.filename.gsub('.png', '_diff.png'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def args
|
22
|
+
[reference, snapshot.path_and_filename, comparison].join(' ')
|
23
|
+
end
|
24
|
+
|
25
|
+
def pass(_debug)
|
26
|
+
File.delete(comparison, snapshot.path_and_filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fail(debug)
|
30
|
+
Results::PixelRegression.new(reference, snapshot, debug, comparison)
|
31
|
+
end
|
32
|
+
|
33
|
+
def error(debug)
|
34
|
+
if debug[/unable to open image/]
|
35
|
+
Results::ReferenceFileNotFound.new(snapshot)
|
36
|
+
else
|
37
|
+
# TODO: This is a failure so should add Result to Results list
|
38
|
+
print %(\033[31m#{debug}\033[0m)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module ImageDiff
|
6
|
+
module Differ
|
7
|
+
# ImageMagick compare interface
|
8
|
+
module ImageMagick
|
9
|
+
CMD = 'compare -metric rmse '
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def absolute_error(args)
|
14
|
+
Open3.popen2e(CMD + args) do |_stdin, stdout_stderr, wait_thr|
|
15
|
+
[wait_thr.value.exitstatus, stdout_stderr.readlines.join("\n")]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_rel 'result'
|
4
|
+
|
5
|
+
module ImageDiff
|
6
|
+
module Differ
|
7
|
+
module Results
|
8
|
+
# Results list
|
9
|
+
class List
|
10
|
+
extend Forwardable
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
def_delegators :@list, :ai, :[], :each_with_object, :empty?
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
clear
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear
|
20
|
+
@list = Hash.new { |hash, key| hash[key] = [] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def filter(method)
|
24
|
+
each_with_object({}) do |(component, results), hash|
|
25
|
+
selected = Filter.apply(results, method)
|
26
|
+
hash[component] = selected unless selected.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def reference_errors
|
31
|
+
filter(:select)
|
32
|
+
end
|
33
|
+
|
34
|
+
def regressions
|
35
|
+
filter(:reject)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Helper class to filter array
|
40
|
+
class Filter
|
41
|
+
KLASS = ImageDiff::Differ::Results::ReferenceFileNotFound
|
42
|
+
LAMBDA = ->(result) { result.is_a?(KLASS) }
|
43
|
+
|
44
|
+
def self.apply(arr, method)
|
45
|
+
arr.send(method, &LAMBDA)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module ImageDiff
|
5
|
+
module Differ
|
6
|
+
module Results
|
7
|
+
# Decorator for Results hash
|
8
|
+
class Output < SimpleDelegator
|
9
|
+
CURRENT_DIR = File.dirname(__FILE__)
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super(List.instance)
|
13
|
+
@regressions = regressions
|
14
|
+
@reference_errors = reference_errors
|
15
|
+
end
|
16
|
+
|
17
|
+
def out
|
18
|
+
render_reference_errors
|
19
|
+
render_regression_errors
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_reference_errors
|
23
|
+
print_str = String.new ''
|
24
|
+
unless @reference_errors.empty?
|
25
|
+
@reference_errors.map do |component, failures|
|
26
|
+
print_str << "The following reference files were not found, you need to generate screenshots before comparing...\n"
|
27
|
+
failures.each do |failure|
|
28
|
+
print_str << "\033[31m#{failure.snapshot.filename}\033[0m\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
print print_str
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_regression_errors
|
36
|
+
print_str = String.new ''
|
37
|
+
unless @regressions.empty?
|
38
|
+
@regressions.map do |component, failures|
|
39
|
+
print_str << "The following screenshots are different from the comparison image, if this expected then regenerate comparison images...\n"
|
40
|
+
failures.each do |failure|
|
41
|
+
print_str << "\033[31m#{failure.output}\033[0m\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
print print_str
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.clear
|
49
|
+
List.instance.clear
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.flush
|
53
|
+
return if List.instance.empty?
|
54
|
+
|
55
|
+
new.out
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImageDiff
|
4
|
+
module Differ
|
5
|
+
module Results
|
6
|
+
# Comparison result
|
7
|
+
class Result
|
8
|
+
attr_reader :snapshot
|
9
|
+
|
10
|
+
def initialize(snapshot)
|
11
|
+
@snapshot = snapshot
|
12
|
+
add_to_results_list
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_to_results_list
|
16
|
+
List.instance[@snapshot.filepath] << self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Reference File Not Found
|
21
|
+
class ReferenceFileNotFound < Result
|
22
|
+
end
|
23
|
+
|
24
|
+
# Pixel Regression
|
25
|
+
class PixelRegression < Result
|
26
|
+
def initialize(reference, snapshot, error, comparison)
|
27
|
+
@error = error
|
28
|
+
@comparison = comparison
|
29
|
+
@reference = reference
|
30
|
+
super(snapshot)
|
31
|
+
end
|
32
|
+
|
33
|
+
def output
|
34
|
+
<<~BODY
|
35
|
+
----------------------
|
36
|
+
Reference file: #{@reference}
|
37
|
+
Screenshot: #{snapshot.filepath}.png
|
38
|
+
Difference: #{@comparison}
|
39
|
+
----------------------
|
40
|
+
BODY
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_rel 'snapshot'
|
4
|
+
|
5
|
+
module ImageDiff
|
6
|
+
# Screenshot class
|
7
|
+
class PNGSnapshot < Snapshot
|
8
|
+
include Helpers::Screenshot
|
9
|
+
|
10
|
+
@id = 'PNG'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :master_screenshot_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def extension
|
17
|
+
'.png'
|
18
|
+
end
|
19
|
+
|
20
|
+
def write
|
21
|
+
fullpage_screenshot(path_and_filename)
|
22
|
+
end
|
23
|
+
|
24
|
+
def compare
|
25
|
+
write
|
26
|
+
ImageDiff.new(self)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_rel 'writer'
|
4
|
+
require_rel 'differ'
|
5
|
+
|
6
|
+
module ImageDiff
|
7
|
+
# Snapshot class
|
8
|
+
class Snapshot
|
9
|
+
include Writer
|
10
|
+
include Differ
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :id
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :snapshot_path, :file
|
17
|
+
|
18
|
+
def initialize(snapshot_path, file)
|
19
|
+
@snapshot_path = snapshot_path
|
20
|
+
@file = file
|
21
|
+
end
|
22
|
+
|
23
|
+
def fullpath
|
24
|
+
FileUtils.mkdir_p(snapshot_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def filepath
|
28
|
+
File.join(fullpath, @file)
|
29
|
+
end
|
30
|
+
|
31
|
+
def filename
|
32
|
+
"#{@file}#{extension}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImageDiff
|
4
|
+
# Write Snapshots to File
|
5
|
+
module Writer
|
6
|
+
def path_and_filename
|
7
|
+
File.join(fullpath, filename)
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
File.open(path_and_filename, 'w') do |file|
|
12
|
+
file.write(content)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ''
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.31.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.31.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: require_all
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
description: Full page screenshot comparison tool for use with Capybara and Selenium
|
42
|
+
email:
|
43
|
+
- daniel.oades@itv.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- image_diff.gemspec
|
57
|
+
- lib/helpers/screenshot.rb
|
58
|
+
- lib/image_diff.rb
|
59
|
+
- lib/image_diff/differ/differ.rb
|
60
|
+
- lib/image_diff/differ/image_diff.rb
|
61
|
+
- lib/image_diff/differ/image_magick.rb
|
62
|
+
- lib/image_diff/differ/results/list.rb
|
63
|
+
- lib/image_diff/differ/results/output.rb
|
64
|
+
- lib/image_diff/differ/results/result.rb
|
65
|
+
- lib/image_diff/png_snapshot.rb
|
66
|
+
- lib/image_diff/snapshot.rb
|
67
|
+
- lib/image_diff/version.rb
|
68
|
+
- lib/image_diff/writer/writer.rb
|
69
|
+
homepage: https://github.com/ITV/image_diff
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata:
|
73
|
+
homepage_uri: https://github.com/ITV/image_diff
|
74
|
+
source_code_uri: https://github.com/ITV/image_diff
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.3.0
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Full page screenshot comparison tool
|
94
|
+
test_files: []
|