capybara-screenshot-diff 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +0 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +207 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capybara-screenshot-diff.gemspec +38 -0
- data/lib/capybara/screenshot/diff.rb +18 -0
- data/lib/capybara/screenshot/diff/capybara_setup.rb +108 -0
- data/lib/capybara/screenshot/diff/image_compare.rb +120 -0
- data/lib/capybara/screenshot/diff/version.rb +8 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c7078265d4d0fc01429989f9b8d67a60773ccab
|
4
|
+
data.tar.gz: 0bee455268a6e5ecf65549a22ff35c85c5b56327
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9003b9fb66fa3e2206ee771d288963d26a85a2bb26b0d643dc357b5647e5b5915083b44e547daf6e2cafa4aba5791853b9496c8dce3a79372214da1a50a13343
|
7
|
+
data.tar.gz: 8fcfca1b48a99fa3b14b8b1270d48af12ecd1dc9f30ffc002c0fdaaff79fdfb728cb3e6516fb2724aec7ca921ede6dc00a9165607c2d4f7e024776f446423aec
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
File without changes
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Uwe Kubosch
|
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,207 @@
|
|
1
|
+
# Capybara::Screenshot::Diff
|
2
|
+
|
3
|
+
Ever wondered what your project looked like two years ago? To answer that, you
|
4
|
+
start taking screen shots during your tests. Capybara provides the
|
5
|
+
`save_screenshot` method for this. Very good.
|
6
|
+
|
7
|
+
Ever introduced a graphical chnage unintended? Never want it to happen again?
|
8
|
+
Then this gem is gfor you! Use this gem to detect changes in your pages by
|
9
|
+
taking screen shots and comparing them to the previous revision.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'capybara-screenshot-diff'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install capybara-screenshot-diff
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Add `screenshot '<my_feature>'` to your tests. The screenshot will be saved in
|
30
|
+
the `doc/screenshots` directory.
|
31
|
+
|
32
|
+
Change your existing `save_screenshot` calls to `screenshot`
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
test 'my useful feature' do
|
36
|
+
visit '/'
|
37
|
+
screenshot 'welcome_index'
|
38
|
+
click_button 'Useful feature'
|
39
|
+
screenshot 'feature_index'
|
40
|
+
click_button 'Perform action'
|
41
|
+
screenshot 'action_performed'
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This will produce a sequence of images like this
|
46
|
+
|
47
|
+
```
|
48
|
+
doc
|
49
|
+
screenshots
|
50
|
+
action_performed
|
51
|
+
feature_index
|
52
|
+
welcome_index
|
53
|
+
```
|
54
|
+
|
55
|
+
To store the screen shot history, add the `doc/screenshots` directory to your
|
56
|
+
version control system (git, svn, etc).
|
57
|
+
|
58
|
+
### Screenshot groups
|
59
|
+
|
60
|
+
Commonly it is useful to group screenshots around a feature, and record them as
|
61
|
+
a sequence. To do this, add a `screenshot_group` call to the start of your
|
62
|
+
test.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
test 'my useful feature' do
|
66
|
+
screenshot_group 'useful_feature'
|
67
|
+
visit '/'
|
68
|
+
screenshot 'welcome_index'
|
69
|
+
click_button 'Useful feature'
|
70
|
+
screenshot 'feature_index'
|
71
|
+
click_button 'Perform action'
|
72
|
+
screenshot 'action_performed'
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
This will produce a sequence of images like this
|
77
|
+
|
78
|
+
```
|
79
|
+
doc
|
80
|
+
screenshots
|
81
|
+
useful_feature
|
82
|
+
00-welcome_index
|
83
|
+
01-feature_index
|
84
|
+
02-action_performed
|
85
|
+
```
|
86
|
+
|
87
|
+
### Multiple Capybara drivers
|
88
|
+
|
89
|
+
Often it is useful to test your app using different browsers. To avoid the
|
90
|
+
screenshots for different Capybara drivers to overwrite each other, set
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Capybara::Screenshot.add_driver_path = true
|
94
|
+
```
|
95
|
+
|
96
|
+
The example above will then save your screenshots like this
|
97
|
+
(for poltergeist and selenium):
|
98
|
+
|
99
|
+
```
|
100
|
+
doc
|
101
|
+
screenshots
|
102
|
+
poltergeist
|
103
|
+
useful_feature
|
104
|
+
00-welcome_index
|
105
|
+
01-feature_index
|
106
|
+
02-action_performed
|
107
|
+
selenium
|
108
|
+
useful_feature
|
109
|
+
00-welcome_index
|
110
|
+
01-feature_index
|
111
|
+
02-action_performed
|
112
|
+
```
|
113
|
+
|
114
|
+
### Multiple OSs
|
115
|
+
|
116
|
+
If you run your tests on multiple operating systems, you will most likely find
|
117
|
+
the screen shots differ. To avoid the screenshots for different OSs to
|
118
|
+
overwrite each other, set
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
Capybara::Screenshot.add_os_path = true
|
122
|
+
```
|
123
|
+
|
124
|
+
The example above will then save your screenshots like this
|
125
|
+
(for Linux and Windows):
|
126
|
+
|
127
|
+
```
|
128
|
+
doc
|
129
|
+
screenshots
|
130
|
+
linux
|
131
|
+
useful_feature
|
132
|
+
00-welcome_index
|
133
|
+
01-feature_index
|
134
|
+
02-action_performed
|
135
|
+
windows
|
136
|
+
useful_feature
|
137
|
+
00-welcome_index
|
138
|
+
01-feature_index
|
139
|
+
02-action_performed
|
140
|
+
```
|
141
|
+
|
142
|
+
If you combine this config with the `add_driver_path` config, the driver will be
|
143
|
+
put in front of the OS name.
|
144
|
+
|
145
|
+
### Screen size
|
146
|
+
|
147
|
+
You can specify the desired screen size using
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
Capybara::Screenshot.window_size = [1024, 768]
|
151
|
+
```
|
152
|
+
|
153
|
+
This will force the screen shots to the given size, and skip taking screen shots
|
154
|
+
unless the desired window size can be achieved.
|
155
|
+
|
156
|
+
### Disabling screen shots
|
157
|
+
|
158
|
+
If you want to skip taking screen shots, set
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Capybara::Screenshot.enabled = false
|
162
|
+
```
|
163
|
+
|
164
|
+
You can of course set this by an environment variable
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
Capybara::Screenshot.enabled = ENV['TAKE_SCREENSHOTS']
|
168
|
+
```
|
169
|
+
|
170
|
+
### Disabling diff
|
171
|
+
|
172
|
+
If you want to skip the assertion for change in the screen shot, set
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
Capybara::Screenshot::Diff.enabled = false
|
176
|
+
```
|
177
|
+
|
178
|
+
Using an environment variable
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
Capybara::Screenshot::Diff.enabled = ENV['COMPARE_SCREENSHOTS']
|
182
|
+
```
|
183
|
+
|
184
|
+
### Screen shot save path
|
185
|
+
|
186
|
+
If you would like the screen shots to be saved in a different location set
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
Capybara::Screenshot.save_path = "#{Rails.root}/doc/gui"
|
190
|
+
```
|
191
|
+
|
192
|
+
|
193
|
+
## Development
|
194
|
+
|
195
|
+
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.
|
196
|
+
|
197
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `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).
|
198
|
+
|
199
|
+
## Contributing
|
200
|
+
|
201
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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.
|
202
|
+
|
203
|
+
|
204
|
+
## License
|
205
|
+
|
206
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
207
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
task default: [:test, :rubocop]
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'test'
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
Rake::Task[:test].enhance [:rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'capybara/screenshot/diff'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capybara/screenshot/diff/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'capybara-screenshot-diff'
|
8
|
+
spec.version = Capybara::Screenshot::Diff::VERSION
|
9
|
+
spec.authors = ['Uwe Kubosch']
|
10
|
+
spec.email = ['uwe@kubosch.no']
|
11
|
+
|
12
|
+
spec.summary = 'Track your GUI changes with diff assertions'
|
13
|
+
spec.description = 'Save screen shots and track changes with graphical diff'
|
14
|
+
spec.homepage = 'https://github.com/donv/capybara-screenshot-diff'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
21
|
+
else
|
22
|
+
fail 'RubyGems 2.0 or newer is required to protect against public gem push.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0")
|
26
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'capybara', '~> 2.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
spec.add_development_dependency 'minitest-reporters'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.39'
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'capybara/screenshot/diff/version'
|
2
|
+
require 'capybara/screenshot/diff/image_compare'
|
3
|
+
require 'capybara/screenshot/diff/capybara_setup'
|
4
|
+
|
5
|
+
module Capybara
|
6
|
+
module Screenshot
|
7
|
+
mattr_accessor :enabled
|
8
|
+
mattr_accessor :window_size
|
9
|
+
mattr_accessor :add_driver_path
|
10
|
+
mattr_accessor :add_os_path
|
11
|
+
|
12
|
+
# Module to track screen shot changes
|
13
|
+
module Diff
|
14
|
+
mattr_accessor :enabled
|
15
|
+
self.enabled = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/screenshot/diff/image_compare'
|
3
|
+
|
4
|
+
# Add the `screenshot`method to ActionDispatch::IntegrationTest
|
5
|
+
class ActionDispatch::IntegrationTest
|
6
|
+
ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
7
|
+
SILENCE_ERRORS = ON_WINDOWS ? '2>nul' : '2>/dev/null'
|
8
|
+
|
9
|
+
def self.os_name
|
10
|
+
case RbConfig::CONFIG['host_os']
|
11
|
+
when /darwin/
|
12
|
+
'macos'
|
13
|
+
when /mswin|mingw|cygwin/
|
14
|
+
'windows'
|
15
|
+
when /linux/
|
16
|
+
'linux'
|
17
|
+
else
|
18
|
+
'unknown'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.screenshot_dir
|
23
|
+
parts = ['doc/screenshots']
|
24
|
+
parts << Capybara.default_driver.to_s if Capybara::Screenshot.add_driver_path
|
25
|
+
parts << os_name if Capybara::Screenshot.add_os_path
|
26
|
+
File.join parts
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.screenshot_dir_abs
|
30
|
+
"#{Rails.root}/#{screenshot_dir}".freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
setup do
|
34
|
+
if Capybara::Screenshot.window_size
|
35
|
+
if Capybara.default_driver == :selenium
|
36
|
+
page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
|
37
|
+
else
|
38
|
+
page.driver.resize(*Capybara::Screenshot.window_size)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
teardown do
|
44
|
+
if Capybara::Screenshot::Diff.enabled && @test_screenshots
|
45
|
+
@test_screenshots.each { |args| assert_image_not_changed(*args) }
|
46
|
+
end
|
47
|
+
fail(@test_screenshot_errors.join("\n\n")) if @test_screenshot_errors
|
48
|
+
end
|
49
|
+
|
50
|
+
def screenshot_group(name)
|
51
|
+
@screenshot_group = name
|
52
|
+
@screenshot_counter = 0
|
53
|
+
FileUtils.rm_rf "#{self.class.screenshot_dir_abs}/#{name}" if name.present?
|
54
|
+
end
|
55
|
+
|
56
|
+
def screenshot(name)
|
57
|
+
return unless Capybara::Screenshot.enabled || (Capybara::Screenshot.enabled.nil? && Capybara::Screenshot::Diff.enabled)
|
58
|
+
if Capybara.default_driver == :selenium && Capybara::Screenshot.window_size
|
59
|
+
return unless page.driver.browser.manage.window
|
60
|
+
.size == Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
|
61
|
+
end
|
62
|
+
if @screenshot_counter
|
63
|
+
name = "#{'%02i' % @screenshot_counter}_#{name}"
|
64
|
+
@screenshot_counter += 1
|
65
|
+
end
|
66
|
+
name = "#{@screenshot_group}/#{name}" if @screenshot_group.present?
|
67
|
+
file_name = "#{self.class.screenshot_dir_abs}/#{name}.png"
|
68
|
+
org_name = "#{self.class.screenshot_dir_abs}/#{name}_0.png~"
|
69
|
+
new_name = "#{self.class.screenshot_dir_abs}/#{name}_1.png~"
|
70
|
+
|
71
|
+
FileUtils.mkdir_p File.dirname(file_name)
|
72
|
+
svn_file_name = "#{self.class.screenshot_dir_abs}/.svn/text-base/#{name}.png.svn-base"
|
73
|
+
if File.exist?(svn_file_name)
|
74
|
+
committed_file_name = svn_file_name
|
75
|
+
else
|
76
|
+
svn_info = `svn info #{file_name} #{SILENCE_ERRORS}`
|
77
|
+
if svn_info.present?
|
78
|
+
wc_root = svn_info.slice /(?<=Working Copy Root Path: ).*$/
|
79
|
+
checksum = svn_info.slice /(?<=Checksum: ).*$/
|
80
|
+
if checksum
|
81
|
+
committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
committed_file_name = org_name
|
85
|
+
`git show HEAD~0:#{self.class.screenshot_dir}/#{name}.png > #{committed_file_name} #{SILENCE_ERRORS}`
|
86
|
+
if File.size(committed_file_name) == 0
|
87
|
+
FileUtils.rm_f committed_file_name
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
old_file_size = nil
|
92
|
+
loop do
|
93
|
+
page.save_screenshot(file_name)
|
94
|
+
break if old_file_size == File.size(file_name)
|
95
|
+
old_file_size = File.size(file_name)
|
96
|
+
sleep 0.5
|
97
|
+
end
|
98
|
+
return unless File.exist?(committed_file_name)
|
99
|
+
(@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
|
100
|
+
end
|
101
|
+
|
102
|
+
def assert_image_not_changed(caller, name, file_name, committed_file_name, new_name, org_name)
|
103
|
+
if Capybara::Screenshot::Diff::ImageCompare.compare(file_name, committed_file_name, Capybara::Screenshot.window_size)
|
104
|
+
(@test_screenshot_errors ||= []) <<
|
105
|
+
"Screenshot does not match for #{name.inspect}\n#{file_name}\n#{org_name}\n#{new_name}\nat #{caller}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'chunky_png'
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module Screenshot
|
5
|
+
module Diff
|
6
|
+
class ImageCompare
|
7
|
+
include ChunkyPNG::Color
|
8
|
+
|
9
|
+
def self.compare(file_name, old_file_name, dimensions = nil)
|
10
|
+
name = file_name.chomp('.png')
|
11
|
+
org_file_name = "#{name}_0.png~"
|
12
|
+
new_file_name = "#{name}_1.png~"
|
13
|
+
|
14
|
+
return nil unless File.exist? old_file_name
|
15
|
+
|
16
|
+
images = load_images(old_file_name, file_name)
|
17
|
+
|
18
|
+
unless images
|
19
|
+
clean_tmp_files(new_file_name, org_file_name)
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
crop_images(images, dimensions) if dimensions
|
24
|
+
org_img = images.first
|
25
|
+
new_img = images.last
|
26
|
+
if sizes_changed?(org_img, new_img, name)
|
27
|
+
save_images(new_file_name, new_img, org_file_name, org_img)
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
|
31
|
+
if org_img.pixels == new_img.pixels
|
32
|
+
clean_tmp_files(new_file_name, org_file_name)
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
|
36
|
+
bottom, left, right, top = find_diff_rectangle(org_img, new_img)
|
37
|
+
draw_rectangles(images, bottom, left, right, top)
|
38
|
+
save_images(new_file_name, new_img, org_file_name, org_img)
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.save_images(new_file_name, new_img, org_file_name, org_img)
|
43
|
+
org_img.save(org_file_name)
|
44
|
+
new_img.save(new_file_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.clean_tmp_files(new_file_name, org_file_name)
|
48
|
+
File.delete(org_file_name) if File.exists?(org_file_name)
|
49
|
+
File.delete(new_file_name) if File.exists?(new_file_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def self.load_images(old_file_name, file_name)
|
55
|
+
old_file = File.read(old_file_name)
|
56
|
+
new_file = File.read(file_name)
|
57
|
+
|
58
|
+
return false if old_file == new_file
|
59
|
+
|
60
|
+
[ChunkyPNG::Image.from_blob(old_file), ChunkyPNG::Image.from_blob(new_file)]
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.sizes_changed?(org_image, new_image, name)
|
64
|
+
if org_image.dimension != new_image.dimension
|
65
|
+
puts "Image size has changed for #{name}: #{[org_image, new_image].map { |i| "#{i.width}x#{i.height}" }.join(' => ')}"
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.crop_images(images, dimensions)
|
71
|
+
images.map! do |i|
|
72
|
+
if i.dimension.to_a == dimensions || i.width < dimensions[0] || i.height < dimensions[1]
|
73
|
+
i
|
74
|
+
else
|
75
|
+
i.crop(0, 0, *dimensions)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.draw_rectangles(images, bottom, left, right, top)
|
81
|
+
(1..2).each do |i|
|
82
|
+
images.each do |image|
|
83
|
+
image.rect(left - 1, top - 1, right + 1, bottom + 1, ChunkyPNG::Color.rgb(255, 0, 0))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.find_diff_rectangle(org_img, new_img)
|
89
|
+
top = bottom = nil
|
90
|
+
left = org_img.width
|
91
|
+
right = -1
|
92
|
+
org_img.height.times do |y|
|
93
|
+
(0...left).find do |x|
|
94
|
+
if org_img[x, y] != new_img[x, y]
|
95
|
+
top ||= y
|
96
|
+
bottom = y
|
97
|
+
left = x
|
98
|
+
right = x if x > right
|
99
|
+
end
|
100
|
+
end
|
101
|
+
(org_img.width - 1).step(right + 1, -1).find do |x|
|
102
|
+
if org_img[x, y] != new_img[x, y]
|
103
|
+
bottom = y
|
104
|
+
right = x
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
(org_img.height - 1).step(bottom + 1, -1).find do |y|
|
109
|
+
((left + 1)..(right - 1)).find do |x|
|
110
|
+
if org_img[x, y] != new_img[x, y]
|
111
|
+
bottom = y
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return bottom, left, right, top
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-screenshot-diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Uwe Kubosch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-20 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.39'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.39'
|
97
|
+
description: Save screen shots and track changes with graphical diff
|
98
|
+
email:
|
99
|
+
- uwe@kubosch.no
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".rubocop_todo.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- capybara-screenshot-diff.gemspec
|
115
|
+
- lib/capybara/screenshot/diff.rb
|
116
|
+
- lib/capybara/screenshot/diff/capybara_setup.rb
|
117
|
+
- lib/capybara/screenshot/diff/image_compare.rb
|
118
|
+
- lib/capybara/screenshot/diff/version.rb
|
119
|
+
homepage: https://github.com/donv/capybara-screenshot-diff
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org/
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Track your GUI changes with diff assertions
|
144
|
+
test_files: []
|