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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c6352942319e9568eee4ea1bbeb19b969996e3d
4
- data.tar.gz: 11aa06f7cc11de87e47199b0765149641866e2d7
3
+ metadata.gz: 290fd85dbec79c15456ca64597df0c3d36954352
4
+ data.tar.gz: cb0bee66fb36a7f57c6f4ae7273a95a2dc268e31
5
5
  SHA512:
6
- metadata.gz: 7d778a1238befd79de6b935f33c1c4ae025fe29336a41302f726b0da0f9f67df6e2d36e27c0abc7b9f82cc8ae302f866df645bd03800b8e23927018b9fdadd04
7
- data.tar.gz: ae45c3aa0c59af81b9a5425a22df522693ee597836693ca43b5ab54144b9808202ed49645d3dc3285abfd62623fe99ace0e6a5eee54acd95172da8964e6c9b4b
6
+ metadata.gz: b5fdb785c1cf6db0f3e40c858b6d679d8b172b0751d5fb91543f26e0efa8597bc77a686991936fce544c9ff762e63fa515b3ac382d9def8b2da1d50950873378
7
+ data.tar.gz: 294d1f43adcc23ae124e7219ae7c05dadffe205c7754f438329906a5d6a0d1dc69567b09c209152619506360cb858a6e3ca9c2750aabd795e45cf70a18747891
data/README.md CHANGED
@@ -8,3 +8,4 @@ Browsery is a browser automation test framework built on top of minitest and sel
8
8
  Add this line to your Gemfile and run `bundle install`:
9
9
 
10
10
  gem 'browsery'
11
+
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
@@ -55,6 +55,6 @@ require_relative 'connector'
55
55
  require_relative 'page_objects'
56
56
  require_relative 'parallel'
57
57
  require_relative 'settings'
58
-
58
+ require_relative 'diff_image'
59
59
  require_relative 'test_case'
60
60
  require_relative 'console'
@@ -77,6 +77,10 @@ module Browsery
77
77
  hsh.fetch(:rerun_failure)
78
78
  end
79
79
 
80
+ def visual_regression
81
+ hsh.fetch(:visual_regression)
82
+ end
83
+
80
84
  def seed
81
85
  hsh.fetch(:seed, nil).to_i
82
86
  end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Browsery
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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.3.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-02-16 00:00:00.000000000 Z
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