capybara-screenshot-diff 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +6 -49
- data/.travis.yml +4 -5
- data/README.md +1 -1
- data/Rakefile +2 -3
- data/capybara-screenshot-diff.gemspec +1 -1
- data/lib/capybara/screenshot/diff/capybara_setup.rb +137 -129
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18cb8f36eeb03d05da4cd3300a91e7f871724a77
|
4
|
+
data.tar.gz: 2bbdc4d01d53b5bad98f43b16cec3557a167811b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46673760287a2ff760f261e089ef75ed469cc83c05148a7dc4ca2791d8d5967f862bbffb45bf670c0e5bde9b50cb2cd42598679814b9cac88920a3bf333b7d5
|
7
|
+
data.tar.gz: 4048618b8364260ba070a1a320d44adf494f1af02344ae26a9d2a21d9a38f90ae3c9d4800c878234e20b494ac0c2af9e8bfaff1ad9689d35cf6a173bed2bdaf0
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,31 +1,23 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-
|
3
|
+
# on 2016-12-23 14:12:31 +0100 using RuboCop version 0.46.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
Style/TrivialAccessors:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
# Offense count: 2
|
13
|
-
Lint/AmbiguousRegexpLiteral:
|
14
|
-
Exclude:
|
15
|
-
- 'lib/capybara/screenshot/diff/capybara_setup.rb'
|
16
|
-
|
17
9
|
# Offense count: 3
|
18
10
|
Metrics/AbcSize:
|
19
|
-
Max:
|
11
|
+
Max: 45
|
20
12
|
|
21
13
|
# Offense count: 1
|
22
14
|
Metrics/CyclomaticComplexity:
|
23
|
-
Max:
|
15
|
+
Max: 12
|
24
16
|
|
25
|
-
# Offense count:
|
17
|
+
# Offense count: 4
|
26
18
|
# Configuration parameters: CountComments.
|
27
19
|
Metrics/MethodLength:
|
28
|
-
Max:
|
20
|
+
Max: 36
|
29
21
|
|
30
22
|
# Offense count: 1
|
31
23
|
# Configuration parameters: CountKeywordArgs.
|
@@ -34,22 +26,7 @@ Metrics/ParameterLists:
|
|
34
26
|
|
35
27
|
# Offense count: 1
|
36
28
|
Metrics/PerceivedComplexity:
|
37
|
-
Max:
|
38
|
-
|
39
|
-
# Offense count: 1
|
40
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
41
|
-
# SupportedStyles: nested, compact
|
42
|
-
Style/ClassAndModuleChildren:
|
43
|
-
Exclude:
|
44
|
-
- 'lib/capybara/screenshot/diff/capybara_setup.rb'
|
45
|
-
|
46
|
-
# Offense count: 2
|
47
|
-
Style/Documentation:
|
48
|
-
Exclude:
|
49
|
-
- 'spec/**/*'
|
50
|
-
- 'test/**/*'
|
51
|
-
- 'lib/capybara/screenshot/diff.rb'
|
52
|
-
- 'lib/capybara/screenshot/diff/image_compare.rb'
|
29
|
+
Max: 14
|
53
30
|
|
54
31
|
# Offense count: 1
|
55
32
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
@@ -57,23 +34,3 @@ Style/Documentation:
|
|
57
34
|
Style/FormatString:
|
58
35
|
Exclude:
|
59
36
|
- 'lib/capybara/screenshot/diff/capybara_setup.rb'
|
60
|
-
|
61
|
-
# Offense count: 1
|
62
|
-
# Configuration parameters: MinBodyLength.
|
63
|
-
Style/GuardClause:
|
64
|
-
Exclude:
|
65
|
-
- 'capybara-screenshot-diff.gemspec'
|
66
|
-
|
67
|
-
# Offense count: 1
|
68
|
-
# Cop supports --auto-correct.
|
69
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
70
|
-
# SupportedStyles: aligned, indented
|
71
|
-
Style/MultilineMethodCallIndentation:
|
72
|
-
Enabled: false
|
73
|
-
|
74
|
-
# Offense count: 1
|
75
|
-
# Cop supports --auto-correct.
|
76
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
77
|
-
# SupportedStyles: aligned, indented
|
78
|
-
Style/MultilineOperationIndentation:
|
79
|
-
Enabled: false
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -251,7 +251,7 @@ To release a new version, update the version number in `lib/capybara/screenshot/
|
|
251
251
|
|
252
252
|
## Contributing
|
253
253
|
|
254
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
254
|
+
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.
|
255
255
|
|
256
256
|
|
257
257
|
## License
|
data/Rakefile
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
-
require 'rubocop/rake_task'
|
4
3
|
|
5
|
-
task default:
|
4
|
+
task default: :test
|
6
5
|
|
7
6
|
Rake::TestTask.new(:test) do |t|
|
8
7
|
t.libs << 'test'
|
@@ -10,6 +9,6 @@ Rake::TestTask.new(:test) do |t|
|
|
10
9
|
t.test_files = FileList['test/**/*_test.rb']
|
11
10
|
end
|
12
11
|
|
12
|
+
require 'rubocop/rake_task'
|
13
13
|
RuboCop::RakeTask.new
|
14
|
-
|
15
14
|
Rake::Task[:test].enhance [:'rubocop:auto_correct']
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'actionpack', '
|
21
|
+
spec.add_runtime_dependency 'actionpack', '>= 4.1', '<5.1'
|
22
22
|
spec.add_runtime_dependency 'capybara', '~> 2.0'
|
23
23
|
spec.add_runtime_dependency 'chunky_png', '~> 1.3'
|
24
24
|
|
@@ -7,132 +7,139 @@ require 'action_dispatch'
|
|
7
7
|
# and use Module#prepend/include to insert.
|
8
8
|
# Add the `screenshot` method to ActionDispatch::IntegrationTest
|
9
9
|
# rubocop:disable Metrics/ClassLength
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
10
|
+
module ActionDispatch
|
11
|
+
class IntegrationTest
|
12
|
+
ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
13
|
+
SILENCE_ERRORS = ON_WINDOWS ? '2>nul' : '2>/dev/null'
|
14
|
+
|
15
|
+
def self.os_name
|
16
|
+
case RbConfig::CONFIG['host_os']
|
17
|
+
when /darwin/
|
18
|
+
'macos'
|
19
|
+
when /mswin|mingw|cygwin/
|
20
|
+
'windows'
|
21
|
+
when /linux/
|
22
|
+
'linux'
|
23
|
+
else
|
24
|
+
'unknown'
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def self.screenshot_root
|
29
|
+
Capybara::Screenshot.screenshot_root ||
|
29
30
|
(defined?(Rails.root) && Rails.root) || File.expand_path('.')
|
30
|
-
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def self.screenshot_area
|
34
|
+
parts = ['doc/screenshots']
|
35
|
+
parts << Capybara.default_driver.to_s if Capybara::Screenshot.add_driver_path
|
36
|
+
parts << os_name if Capybara::Screenshot.add_os_path
|
37
|
+
File.join parts
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def self.screenshot_area_abs
|
41
|
+
"#{screenshot_root}/#{screenshot_area}".freeze
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def initialize(*)
|
45
|
+
super
|
46
|
+
@screenshot_counter = nil
|
47
|
+
@screenshot_group = nil
|
48
|
+
@screenshot_section = nil
|
49
|
+
@test_screenshot_errors = nil
|
50
|
+
@test_screenshots = nil
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
def group_parts
|
54
|
+
parts = []
|
55
|
+
parts << @screenshot_section if @screenshot_section.present?
|
56
|
+
parts << @screenshot_group if @screenshot_group.present?
|
57
|
+
parts
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def full_name(name)
|
61
|
+
File.join group_parts.<<(name).map(&:to_s)
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def screenshot_dir
|
65
|
+
File.join [self.class.screenshot_area] + group_parts
|
66
|
+
end
|
67
|
+
|
68
|
+
setup do
|
69
|
+
if Capybara::Screenshot.window_size
|
70
|
+
if Capybara.default_driver == :selenium
|
71
|
+
page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
|
72
|
+
elsif Capybara.default_driver == :poltergeist
|
73
|
+
page.driver.resize(*Capybara::Screenshot.window_size)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
66
77
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
|
71
|
-
elsif Capybara.default_driver == :poltergeist
|
72
|
-
page.driver.resize(*Capybara::Screenshot.window_size)
|
78
|
+
teardown do
|
79
|
+
if Capybara::Screenshot::Diff.enabled && @test_screenshots
|
80
|
+
@test_screenshots.each { |args| assert_image_not_changed(*args) }
|
73
81
|
end
|
82
|
+
fail(@test_screenshot_errors.join("\n\n")) if @test_screenshot_errors
|
74
83
|
end
|
75
|
-
end
|
76
84
|
|
77
|
-
|
78
|
-
|
79
|
-
@test_screenshots.each { |args| assert_image_not_changed(*args) }
|
85
|
+
def screenshot_section(name)
|
86
|
+
@screenshot_section = name.to_s
|
80
87
|
end
|
81
|
-
fail(@test_screenshot_errors.join("\n\n")) if @test_screenshot_errors
|
82
|
-
end
|
83
88
|
|
84
|
-
|
85
|
-
|
86
|
-
|
89
|
+
def screenshot_group(name)
|
90
|
+
@screenshot_group = name.to_s
|
91
|
+
@screenshot_counter = 0
|
92
|
+
return unless Capybara::Screenshot.active? && name.present?
|
93
|
+
FileUtils.rm_rf screenshot_dir
|
94
|
+
end
|
87
95
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
96
|
+
def screenshot(name)
|
97
|
+
return unless Capybara::Screenshot.active?
|
98
|
+
if Capybara.default_driver == :selenium && Capybara::Screenshot.window_size
|
99
|
+
return unless page.driver.browser.manage.window
|
100
|
+
.size == Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
|
101
|
+
end
|
102
|
+
if @screenshot_counter
|
103
|
+
name = "#{'%02i' % @screenshot_counter}_#{name}"
|
104
|
+
@screenshot_counter += 1
|
105
|
+
end
|
106
|
+
name = full_name(name)
|
107
|
+
file_name = "#{self.class.screenshot_area_abs}/#{name}.png"
|
108
|
+
org_name = "#{self.class.screenshot_area_abs}/#{name}_0.png~"
|
109
|
+
new_name = "#{self.class.screenshot_area_abs}/#{name}_1.png~"
|
110
|
+
|
111
|
+
FileUtils.mkdir_p File.dirname(file_name)
|
112
|
+
committed_file_name = check_vcs(name, file_name, org_name)
|
113
|
+
take_stable_screenshot(file_name)
|
114
|
+
return unless committed_file_name && File.exist?(committed_file_name)
|
115
|
+
(@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
|
116
|
+
end
|
94
117
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
.size == Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
|
100
|
-
end
|
101
|
-
if @screenshot_counter
|
102
|
-
name = "#{'%02i' % @screenshot_counter}_#{name}"
|
103
|
-
@screenshot_counter += 1
|
104
|
-
end
|
105
|
-
name = full_name(name)
|
106
|
-
file_name = "#{self.class.screenshot_area_abs}/#{name}.png"
|
107
|
-
org_name = "#{self.class.screenshot_area_abs}/#{name}_0.png~"
|
108
|
-
new_name = "#{self.class.screenshot_area_abs}/#{name}_1.png~"
|
109
|
-
|
110
|
-
FileUtils.mkdir_p File.dirname(file_name)
|
111
|
-
svn_file_name = "#{self.class.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
|
112
|
-
if File.exist?(svn_file_name)
|
113
|
-
committed_file_name = svn_file_name
|
114
|
-
else
|
115
|
-
svn_info = `svn info #{file_name} #{SILENCE_ERRORS}`
|
116
|
-
if svn_info.present?
|
117
|
-
wc_root = svn_info.slice(/(?<=Working Copy Root Path: ).*$/)
|
118
|
-
checksum = svn_info.slice(/(?<=Checksum: ).*$/)
|
119
|
-
if checksum
|
120
|
-
committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
|
121
|
-
end
|
118
|
+
def check_vcs(name, file_name, org_name)
|
119
|
+
svn_file_name = "#{self.class.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
|
120
|
+
if File.exist?(svn_file_name)
|
121
|
+
committed_file_name = svn_file_name
|
122
122
|
else
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
svn_info = `svn info #{file_name} #{SILENCE_ERRORS}`
|
124
|
+
if svn_info.present?
|
125
|
+
wc_root = svn_info.slice(/(?<=Working Copy Root Path: ).*$/)
|
126
|
+
checksum = svn_info.slice(/(?<=Checksum: ).*$/)
|
127
|
+
if checksum
|
128
|
+
committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
|
129
|
+
end
|
130
|
+
else
|
131
|
+
committed_file_name = org_name
|
132
|
+
redirect_target = "#{committed_file_name} #{SILENCE_ERRORS}"
|
133
|
+
`git show HEAD~0:#{self.class.screenshot_area}/#{name}.png > #{redirect_target}`
|
134
|
+
if File.size(committed_file_name) == 0
|
135
|
+
FileUtils.rm_f committed_file_name
|
136
|
+
end
|
127
137
|
end
|
128
138
|
end
|
139
|
+
committed_file_name
|
129
140
|
end
|
130
|
-
take_stable_screenshot(file_name)
|
131
|
-
return unless committed_file_name && File.exist?(committed_file_name)
|
132
|
-
(@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
|
133
|
-
end
|
134
141
|
|
135
|
-
|
142
|
+
IMAGE_WAIT_SCRIPT = <<EOF.freeze
|
136
143
|
function pending_image() {
|
137
144
|
var images = document.images;
|
138
145
|
for (var i = 0; i < images.length; i++) {
|
@@ -144,36 +151,37 @@ function pending_image() {
|
|
144
151
|
}()
|
145
152
|
EOF
|
146
153
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
154
|
+
def assert_images_loaded(timeout: Capybara.default_max_wait_time)
|
155
|
+
return unless respond_to? :evaluate_script
|
156
|
+
start = Time.now
|
157
|
+
loop do
|
158
|
+
pending_image = evaluate_script IMAGE_WAIT_SCRIPT
|
159
|
+
break unless pending_image
|
160
|
+
assert (Time.now - start) < timeout,
|
161
|
+
"Image not loaded after #{timeout}s: #{pending_image.inspect}"
|
162
|
+
sleep 0.1
|
163
|
+
end
|
156
164
|
end
|
157
|
-
end
|
158
165
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
166
|
+
def take_stable_screenshot(file_name)
|
167
|
+
assert_images_loaded
|
168
|
+
old_file_size = nil
|
169
|
+
loop do
|
170
|
+
save_screenshot(file_name)
|
171
|
+
break unless Capybara::Screenshot.stability_time_limit
|
172
|
+
new_file_size = File.size(file_name)
|
173
|
+
break if new_file_size == old_file_size
|
174
|
+
old_file_size = new_file_size
|
175
|
+
sleep Capybara::Screenshot.stability_time_limit
|
176
|
+
end
|
169
177
|
end
|
170
|
-
end
|
171
178
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
179
|
+
def assert_image_not_changed(caller, name, file_name, committed_file_name, new_name, org_name)
|
180
|
+
if Capybara::Screenshot::Diff::ImageCompare.compare(committed_file_name, file_name,
|
181
|
+
Capybara::Screenshot.window_size)
|
182
|
+
(@test_screenshot_errors ||= []) <<
|
176
183
|
"Screenshot does not match for '#{name}'\n#{file_name}\n#{org_name}\n#{new_name}\nat #{caller}"
|
184
|
+
end
|
177
185
|
end
|
178
186
|
end
|
179
187
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-screenshot-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: capybara
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|