browsery 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/browsery.gemspec +1 -0
- data/lib/browsery/diff_image.rb +48 -0
- data/lib/browsery/init.rb +1 -1
- data/lib/browsery/settings.rb +4 -0
- data/lib/browsery/utils/page_object_helper.rb +19 -0
- data/lib/browsery/version.rb +1 -1
- data/lib/minitest/browsery_settings_plugin.rb +8 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290fd85dbec79c15456ca64597df0c3d36954352
|
4
|
+
data.tar.gz: cb0bee66fb36a7f57c6f4ae7273a95a2dc268e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fdb785c1cf6db0f3e40c858b6d679d8b172b0751d5fb91543f26e0efa8597bc77a686991936fce544c9ff762e63fa515b3ac382d9def8b2da1d50950873378
|
7
|
+
data.tar.gz: 294d1f43adcc23ae124e7219ae7c05dadffe205c7754f438329906a5d6a0d1dc69567b09c209152619506360cb858a6e3ca9c2750aabd795e45cf70a18747891
|
data/README.md
CHANGED
data/browsery.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency 'minitest', '~>5.4.0'
|
25
25
|
s.add_dependency 'selenium-webdriver', '~> 2.46'
|
26
26
|
s.add_dependency 'rest-client', '~> 1.8'
|
27
|
+
s.add_dependency 'chunky_png', '~> 1.3'
|
27
28
|
|
28
29
|
s.add_development_dependency 'rake'
|
29
30
|
s.add_development_dependency 'yard'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'chunky_png'
|
2
|
+
include ChunkyPNG::Color
|
3
|
+
|
4
|
+
module Browsery
|
5
|
+
class DiffImage
|
6
|
+
|
7
|
+
def initialize(base_image, new_image)
|
8
|
+
@base_image = ChunkyPNG::Image.from_file(base_image)
|
9
|
+
@new_image = ChunkyPNG::Image.from_file(new_image)
|
10
|
+
@diff_image = ChunkyPNG::Image.new(@base_image.width, @new_image.width, BLACK)
|
11
|
+
end
|
12
|
+
|
13
|
+
def calculate_changes
|
14
|
+
diff = []
|
15
|
+
|
16
|
+
@base_image.height.times do |y|
|
17
|
+
@base_image.row(y).each_with_index do |pixel, x|
|
18
|
+
unless pixel == @new_image[x,y]
|
19
|
+
score = Math.sqrt(
|
20
|
+
(r(@new_image[x,y]) - r(pixel)) ** 2 +
|
21
|
+
(g(@new_image[x,y]) - g(pixel)) ** 2 +
|
22
|
+
(b(@new_image[x,y]) - b(pixel)) ** 2
|
23
|
+
) / Math.sqrt(MAX ** 2 * 3)
|
24
|
+
diff << score
|
25
|
+
end
|
26
|
+
@diff_image[x,y] = rgb(
|
27
|
+
r(pixel) + r(@new_image[x,y]) - 2 * [r(pixel), r(@new_image[x,y])].min,
|
28
|
+
g(pixel) + g(@new_image[x,y]) - 2 * [g(pixel), g(@new_image[x,y])].min,
|
29
|
+
b(pixel) + b(@new_image[x,y]) - 2 * [b(pixel), b(@new_image[x,y])].min
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
total_pixels = @base_image.pixels.length
|
35
|
+
diff_percentage = diff.empty? ? 0 : diff.inject {|sum, value| sum + value} / total_pixels
|
36
|
+
puts "pixels (total): #{total_pixels}"
|
37
|
+
puts "pixels changed: #{diff.length}"
|
38
|
+
puts "image changed (%): #{diff_percentage * 100} %"
|
39
|
+
|
40
|
+
diff_percentage
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_diff(diff_image)
|
44
|
+
@diff_image.save(diff_image)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/browsery/init.rb
CHANGED
data/lib/browsery/settings.rb
CHANGED
@@ -220,6 +220,25 @@ module Browsery
|
|
220
220
|
calling_page.class.to_s.split('::').last.downcase
|
221
221
|
end
|
222
222
|
|
223
|
+
def visual_regression(test_step_id)
|
224
|
+
if Browsery.settings.visual_regression
|
225
|
+
if File.exist?("visual_regression/#{test_step_id}-base.png")
|
226
|
+
base_image_path = "visual_regression/#{test_step_id}-base.png"
|
227
|
+
new_image_path = @driver.save_screenshot("visual_regression/#{test_step_id}-new.png")
|
228
|
+
diff_image = Browsery::DiffImage.new(base_image_path, new_image_path)
|
229
|
+
diff_percentage = diff_image.calculate_changes
|
230
|
+
if diff_percentage > Browsery.settings.visual_regression
|
231
|
+
diff_image_path = "visual_regression/#{test_step_id}-diff.png"
|
232
|
+
diff_image.save(diff_image_path)
|
233
|
+
puts "failed at visual regression, diff image saved - #{diff_image_path}"
|
234
|
+
fail
|
235
|
+
end
|
236
|
+
else
|
237
|
+
@driver.save_screenshot("visual_regression/#{test_step_id}-base.png")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
223
242
|
private
|
224
243
|
|
225
244
|
# @param eg. (:css, 'button.cancel') or (*BUTTON_SUBMIT_SEARCH)
|
data/lib/browsery/version.rb
CHANGED
@@ -78,6 +78,14 @@ module Minitest
|
|
78
78
|
integer_value = value.nil? ? 1 : value.to_i
|
79
79
|
options[:rerun_failure] = integer_value
|
80
80
|
end
|
81
|
+
|
82
|
+
options[:visual_regression] = false
|
83
|
+
parser.on('-V', '--visual-regression [TOLERANCE]', 'Enable visual regression,
|
84
|
+
can optionally set tolerance level in percentage(0 tolerance by default),
|
85
|
+
eg. -V 0.01 fails a test if visual difference is larger than 1%') do |value|
|
86
|
+
float_value = value.nil? ? 0 : value.to_f
|
87
|
+
options[:visual_regression] = float_value
|
88
|
+
end
|
81
89
|
end
|
82
90
|
|
83
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browsery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peijie Hu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: chunky_png
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rake
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +167,7 @@ files:
|
|
153
167
|
- lib/browsery.rb
|
154
168
|
- lib/browsery/connector.rb
|
155
169
|
- lib/browsery/console.rb
|
170
|
+
- lib/browsery/diff_image.rb
|
156
171
|
- lib/browsery/init.rb
|
157
172
|
- lib/browsery/logger.rb
|
158
173
|
- lib/browsery/page_objects.rb
|