capybara-screenshot-diff 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +3 -3
- data/README.md +21 -2
- data/lib/capybara/screenshot/diff/image_compare.rb +8 -0
- data/lib/capybara/screenshot/diff/stabilization.rb +3 -2
- data/lib/capybara/screenshot/diff/test_methods.rb +14 -16
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- data/lib/capybara/screenshot/diff.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea2eb0302f1b07c925218f42f50e34a92ea53d6a
|
4
|
+
data.tar.gz: bf0641106aec6b525fd13912b7863b616a8d16df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61c6f15802542903bee2236fb7b72b65fae467b45e885515f15bac7da2dd60d4faa6a2b03e9de90450a1f66710c9c853c31c75e284befae8adab177d89cf3ac4
|
7
|
+
data.tar.gz: d1a8ac84a126b5227d00e43e37115a27547ca9877d4e6ec4da0cd1c37980899b8da441e39c50c6de51775359604c99a497a6a0101f589e75e23b123bebcc35f6
|
data/.rubocop_todo.yml
CHANGED
@@ -13,11 +13,11 @@ Metrics/AbcSize:
|
|
13
13
|
# Offense count: 1
|
14
14
|
# Configuration parameters: CountComments.
|
15
15
|
Metrics/ClassLength:
|
16
|
-
Max:
|
16
|
+
Max: 181
|
17
17
|
|
18
18
|
# Offense count: 3
|
19
19
|
Metrics/CyclomaticComplexity:
|
20
|
-
Max:
|
20
|
+
Max: 10
|
21
21
|
|
22
22
|
# Offense count: 9
|
23
23
|
# Configuration parameters: CountComments.
|
@@ -26,4 +26,4 @@ Metrics/MethodLength:
|
|
26
26
|
|
27
27
|
# Offense count: 2
|
28
28
|
Metrics/PerceivedComplexity:
|
29
|
-
Max:
|
29
|
+
Max: 10
|
data/README.md
CHANGED
@@ -259,8 +259,8 @@ This will remove the focus from the active element, removing the blinking cursor
|
|
259
259
|
### Allowed color distance
|
260
260
|
|
261
261
|
Sometimes you want to allow small differences in the images. For example, Chrome renders the same
|
262
|
-
page slightly differently sometimes. You can set set the difference threshold for the
|
263
|
-
using the `color_distance_limit` option to the `screenshot` method:
|
262
|
+
page slightly differently sometimes. You can set set the color difference threshold for the
|
263
|
+
comparison using the `color_distance_limit` option to the `screenshot` method:
|
264
264
|
|
265
265
|
```ruby
|
266
266
|
test 'color threshold' do
|
@@ -276,6 +276,25 @@ Capybara::Screenshot::Diff.color_distance_limit = 42
|
|
276
276
|
```
|
277
277
|
|
278
278
|
|
279
|
+
### Allowed difference size
|
280
|
+
|
281
|
+
You can set set a threshold for the differing area size for the comparison
|
282
|
+
using the `area_size_limit` option to the `screenshot` method:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
test 'area threshold' do
|
286
|
+
visit '/'
|
287
|
+
screenshot 'index', area_size_limit: 17
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
The difference is calculated as `width * height`. You can also set this globally:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
Capybara::Screenshot::Diff.area_size_limit = 42
|
295
|
+
```
|
296
|
+
|
297
|
+
|
279
298
|
## Development
|
280
299
|
|
281
300
|
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.
|
@@ -24,6 +24,7 @@ module Capybara
|
|
24
24
|
def reset
|
25
25
|
@max_color_distance = @color_distance_limit ? 0 : nil
|
26
26
|
@left = @top = @right = @bottom = nil
|
27
|
+
@_old_filesize = nil
|
27
28
|
end
|
28
29
|
|
29
30
|
# Compare the two image files and return `true` or `false` as quickly as possible.
|
@@ -47,6 +48,11 @@ module Capybara
|
|
47
48
|
|
48
49
|
return true if @top.nil?
|
49
50
|
|
51
|
+
if @area_size_limit
|
52
|
+
@left, @top, @right, @bottom = find_diff_rectangle(old_img, new_img)
|
53
|
+
return true if size <= @area_size_limit
|
54
|
+
end
|
55
|
+
|
50
56
|
false
|
51
57
|
end
|
52
58
|
|
@@ -78,6 +84,8 @@ module Capybara
|
|
78
84
|
|
79
85
|
return not_different if @top.nil?
|
80
86
|
|
87
|
+
return not_different if @area_size_limit && size <= @area_size_limit
|
88
|
+
|
81
89
|
annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top)
|
82
90
|
|
83
91
|
save_images(@annotated_new_file_name, annotated_new_img,
|
@@ -60,7 +60,7 @@ module Capybara
|
|
60
60
|
# ODOT
|
61
61
|
end
|
62
62
|
|
63
|
-
def take_stable_screenshot(comparison)
|
63
|
+
def take_stable_screenshot(comparison, color_distance_limit: , area_size_limit: )
|
64
64
|
input = prepare_page_for_screenshot
|
65
65
|
previous_file_name = comparison.old_file_name
|
66
66
|
screenshot_started_at = last_image_change_at = Time.now
|
@@ -76,7 +76,8 @@ module Capybara
|
|
76
76
|
|
77
77
|
if previous_file_name
|
78
78
|
stabilization_comparison =
|
79
|
-
|
79
|
+
ImageCompare.new(comparison.new_file_name, previous_file_name,
|
80
|
+
color_distance_limit: color_distance_limit, area_size_limit: area_size_limit)
|
80
81
|
if stabilization_comparison.quick_equal?
|
81
82
|
if (Time.now - last_image_change_at) > Capybara::Screenshot.stability_time_limit
|
82
83
|
clean_stabilization_images(comparison.new_file_name)
|
@@ -7,15 +7,13 @@ require_relative 'image_compare'
|
|
7
7
|
require_relative 'stabilization'
|
8
8
|
require_relative 'vcs'
|
9
9
|
|
10
|
-
# TODO(uwe): Move this code to module Capybara::Screenshot::Diff::TestMethods,
|
11
|
-
# and use Module#prepend/include to insert.
|
12
10
|
# Add the `screenshot` method to ActionDispatch::IntegrationTest
|
13
11
|
module Capybara
|
14
12
|
module Screenshot
|
15
13
|
module Diff
|
16
14
|
module TestMethods
|
17
|
-
include
|
18
|
-
include
|
15
|
+
include Stabilization
|
16
|
+
include Vcs
|
19
17
|
|
20
18
|
def initialize(*)
|
21
19
|
super
|
@@ -38,7 +36,7 @@ module Capybara
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def screenshot_dir
|
41
|
-
File.join [
|
39
|
+
File.join [Screenshot.screenshot_area] + group_parts
|
42
40
|
end
|
43
41
|
|
44
42
|
def current_capybara_driver_class
|
@@ -61,36 +59,36 @@ module Capybara
|
|
61
59
|
def screenshot_group(name)
|
62
60
|
@screenshot_group = name.to_s
|
63
61
|
@screenshot_counter = 0
|
64
|
-
return unless
|
62
|
+
return unless Screenshot.active? && name.present?
|
65
63
|
FileUtils.rm_rf screenshot_dir
|
66
64
|
end
|
67
65
|
|
68
|
-
def screenshot(name, color_distance_limit:
|
69
|
-
area_size_limit:
|
70
|
-
return unless
|
66
|
+
def screenshot(name, color_distance_limit: Diff.color_distance_limit,
|
67
|
+
area_size_limit: Diff.area_size_limit)
|
68
|
+
return unless Screenshot.active?
|
71
69
|
return if window_size_is_wrong?
|
72
70
|
if @screenshot_counter
|
73
71
|
name = "#{format('%02i', @screenshot_counter)}_#{name}"
|
74
72
|
@screenshot_counter += 1
|
75
73
|
end
|
76
74
|
name = full_name(name)
|
77
|
-
file_name = "#{
|
75
|
+
file_name = "#{Screenshot.screenshot_area_abs}/#{name}.png"
|
78
76
|
|
79
77
|
FileUtils.mkdir_p File.dirname(file_name)
|
80
|
-
comparison =
|
81
|
-
|
82
|
-
area_size_limit: area_size_limit)
|
78
|
+
comparison = ImageCompare.new(file_name, dimensions: Screenshot.window_size,
|
79
|
+
color_distance_limit: color_distance_limit, area_size_limit: area_size_limit)
|
83
80
|
checkout_vcs(name, comparison)
|
84
|
-
take_stable_screenshot(comparison
|
81
|
+
take_stable_screenshot(comparison, color_distance_limit: color_distance_limit,
|
82
|
+
area_size_limit: area_size_limit)
|
85
83
|
return unless comparison.old_file_exists?
|
86
84
|
(@test_screenshots ||= []) << [caller(1..1).first, name, comparison]
|
87
85
|
end
|
88
86
|
|
89
87
|
def window_size_is_wrong?
|
90
|
-
selenium? &&
|
88
|
+
selenium? && Screenshot.window_size &&
|
91
89
|
(!page.driver.chrome? || ON_WINDOWS) && # TODO(uwe): Allow for Chrome when it works
|
92
90
|
page.driver.browser.manage.window.size !=
|
93
|
-
Selenium::WebDriver::Dimension.new(*
|
91
|
+
Selenium::WebDriver::Dimension.new(*Screenshot.window_size)
|
94
92
|
end
|
95
93
|
|
96
94
|
def assert_image_not_changed(caller, name, comparison)
|
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: 0.9.
|
4
|
+
version: 0.9.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: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|