capybara-screenshot-diff 1.3.0 → 1.3.1
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/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +2 -2
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/lib/capybara/screenshot/diff/image_compare.rb +15 -8
- data/lib/capybara/screenshot/diff/stabilization.rb +22 -4
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60b85259abbdb45d903015705a59c40d376523f4987c0285a0534657a1f71c5a
|
4
|
+
data.tar.gz: 5e5f95c2f086a9ce774c54fae55d4b38fdd8cd401df2ab1912d34e4925952f3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5684af40410133d5ed7c4364433e124af1a6164eb651fa2e3fcfadf171b9f56c0845f541774546c11c80adb18babd45034886241896f4435d61c90476238e92d
|
7
|
+
data.tar.gz: 8ccbadc67bb64ea977247cb5c501380b4c2c6aa70eb784c73d90e087f5e60875636c375c8ceba1e1367b2fed4d36fe80b20c8584510131878f9d69682ce26691
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -19,7 +19,7 @@ Metrics/BlockLength:
|
|
19
19
|
# Offense count: 1
|
20
20
|
# Configuration parameters: CountComments.
|
21
21
|
Metrics/ClassLength:
|
22
|
-
Max:
|
22
|
+
Max: 309
|
23
23
|
|
24
24
|
# Offense count: 5
|
25
25
|
Metrics/CyclomaticComplexity:
|
@@ -33,7 +33,7 @@ Metrics/MethodLength:
|
|
33
33
|
# Offense count: 1
|
34
34
|
# Configuration parameters: CountComments.
|
35
35
|
Metrics/ModuleLength:
|
36
|
-
Max:
|
36
|
+
Max: 123
|
37
37
|
|
38
38
|
# Offense count: 1
|
39
39
|
# Configuration parameters: CountKeywordArgs.
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -274,7 +274,7 @@ configuration options that that are relevant.
|
|
274
274
|
The most likely one you'll want to modify is ...
|
275
275
|
|
276
276
|
```ruby
|
277
|
-
Capybara::Screenshot
|
277
|
+
Capybara::Screenshot.save_path = "other/path"
|
278
278
|
```
|
279
279
|
|
280
280
|
The `save_path` option is relative to `Capybara::Screenshot.root`.
|
@@ -5,12 +5,13 @@ require 'chunky_png'
|
|
5
5
|
module Capybara
|
6
6
|
module Screenshot
|
7
7
|
module Diff
|
8
|
-
# Compare two images and determine if they are equal, different, or within
|
8
|
+
# Compare two images and determine if they are equal, different, or within some comparison
|
9
9
|
# range considering color values and difference area size.
|
10
10
|
class ImageCompare
|
11
11
|
include ChunkyPNG::Color
|
12
12
|
|
13
|
-
attr_reader :annotated_new_file_name, :annotated_old_file_name, :
|
13
|
+
attr_reader :annotated_new_file_name, :annotated_old_file_name, :area_size_limit,
|
14
|
+
:color_distance_limit, :new_file_name, :old_file_name, :shift_distance_limit, :skip_area
|
14
15
|
|
15
16
|
def initialize(new_file_name, old_file_name = nil, dimensions: nil, color_distance_limit: nil,
|
16
17
|
area_size_limit: nil, shift_distance_limit: nil, skip_area: nil)
|
@@ -21,8 +22,8 @@ module Capybara
|
|
21
22
|
@dimensions = dimensions
|
22
23
|
@skip_area = skip_area
|
23
24
|
@old_file_name = old_file_name || "#{new_file_name}~"
|
24
|
-
@annotated_old_file_name = "#{new_file_name.chomp('.png')}
|
25
|
-
@annotated_new_file_name = "#{new_file_name.chomp('.png')}
|
25
|
+
@annotated_old_file_name = "#{new_file_name.chomp('.png')}.committed.png"
|
26
|
+
@annotated_new_file_name = "#{new_file_name.chomp('.png')}.latest.png"
|
26
27
|
reset
|
27
28
|
end
|
28
29
|
|
@@ -97,10 +98,7 @@ module Capybara
|
|
97
98
|
return not_different if @top.nil?
|
98
99
|
return not_different if @area_size_limit && size <= @area_size_limit
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
save_images(@annotated_new_file_name, annotated_new_img,
|
103
|
-
@annotated_old_file_name, annotated_old_img)
|
101
|
+
save_annotated_images(images)
|
104
102
|
true
|
105
103
|
end
|
106
104
|
|
@@ -117,6 +115,8 @@ module Capybara
|
|
117
115
|
end
|
118
116
|
|
119
117
|
def dimensions
|
118
|
+
return unless @left || @top || @right || @bottom
|
119
|
+
|
120
120
|
[@left, @top, @right, @bottom]
|
121
121
|
end
|
122
122
|
|
@@ -136,6 +136,13 @@ module Capybara
|
|
136
136
|
|
137
137
|
private
|
138
138
|
|
139
|
+
def save_annotated_images(images)
|
140
|
+
annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top)
|
141
|
+
|
142
|
+
save_images(@annotated_new_file_name, annotated_new_img,
|
143
|
+
@annotated_old_file_name, annotated_old_img)
|
144
|
+
end
|
145
|
+
|
139
146
|
def calculate_metrics
|
140
147
|
old_file, new_file = load_image_files(@old_file_name, @new_file_name)
|
141
148
|
if old_file == new_file
|
@@ -52,7 +52,9 @@ module Capybara
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
previous_file_name = "#{comparison.new_file_name.chomp('.png')}
|
55
|
+
previous_file_name = "#{comparison.new_file_name.chomp('.png')}" \
|
56
|
+
"_x#{format('%02i', i)}_#{(Time.now - screenshot_started_at).round(1)}s" \
|
57
|
+
"_#{stabilization_comparison.dimensions&.to_s&.gsub(', ', '_') || :initial}.png~"
|
56
58
|
FileUtils.mv comparison.new_file_name, previous_file_name
|
57
59
|
|
58
60
|
check_max_wait_time(comparison, screenshot_started_at,
|
@@ -117,9 +119,25 @@ module Capybara
|
|
117
119
|
def check_max_wait_time(comparison, screenshot_started_at, wait:, shift_distance_limit:)
|
118
120
|
shift_factor = shift_distance_limit ? (shift_distance_limit * 2 + 1) ^ 2 : 1
|
119
121
|
max_wait_time = wait * shift_factor
|
120
|
-
|
121
|
-
|
122
|
-
|
122
|
+
return if (Time.now - screenshot_started_at) < max_wait_time
|
123
|
+
|
124
|
+
# FIXME(uwe): Change to store the failure and only report if the test succeeds functionally.
|
125
|
+
previous_file = comparison.old_file_name
|
126
|
+
stabilization_images(comparison.new_file_name).each do |file_name|
|
127
|
+
if File.exist? previous_file
|
128
|
+
stabilization_comparison =
|
129
|
+
ImageCompare.new(file_name, previous_file,
|
130
|
+
color_distance_limit: comparison.color_distance_limit,
|
131
|
+
shift_distance_limit: comparison.shift_distance_limit,
|
132
|
+
area_size_limit: comparison.area_size_limit, skip_area: comparison.skip_area)
|
133
|
+
assert stabilization_comparison.different?
|
134
|
+
FileUtils.mv stabilization_comparison.annotated_new_file_name, file_name
|
135
|
+
FileUtils.rm stabilization_comparison.annotated_old_file_name
|
136
|
+
end
|
137
|
+
previous_file = file_name
|
138
|
+
end
|
139
|
+
fail("Could not get stable screenshot within #{max_wait_time}s\n" \
|
140
|
+
"#{stabilization_images(comparison.new_file_name).join("\n")}")
|
123
141
|
end
|
124
142
|
|
125
143
|
def assert_images_loaded(timeout:)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-screenshot-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|