capybara-screenshot-diff 0.6.0 → 0.7.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: 3417ac0f41265b198a6807b0ae2ea3fe24d4fcae
4
- data.tar.gz: efcc110c396d89cf8ed51e982c57cc1a6c3e9b4b
3
+ metadata.gz: c51c0b3910c0d9084516caa214cc4def9f3555e5
4
+ data.tar.gz: d6a6c7b9c780bba92792dea8d18ad5e6a4309004
5
5
  SHA512:
6
- metadata.gz: 0d1aecff95b1e1eb031397488bec689f4f1410de71a093914fc2601932237abfb8de30dce236ececb641c0b85dae350d012b6881a5e69c01b1f0eafea300fae9
7
- data.tar.gz: 19bb7deb896fe5de11c94ca2d1c4309dba6a774603b859050ff1a6c31a3cc07c5b5e1cdac4355b35b154cea3db5bbf108cd3572e6b32a75845104b4935922d89
6
+ metadata.gz: ff97131d3381c1db29293d78c70d090ef0f08e31878f2c680305bf2e0205d79257acfee39769b0025d75a56137ed6ef31338333ac682571c2856118cffb3560c
7
+ data.tar.gz: 55375885f91dff602b8744a46254261597fc19d1066057e350623bcb96152f0c28853be88b4436920c91e54e9d8f084c913454e4c23148bd0f3bb986e5331c61
data/.rubocop_todo.yml CHANGED
@@ -16,12 +16,12 @@ Layout/IndentHeredoc:
16
16
 
17
17
  # Offense count: 7
18
18
  Metrics/AbcSize:
19
- Max: 26
19
+ Max: 28
20
20
 
21
21
  # Offense count: 1
22
22
  # Configuration parameters: CountComments.
23
23
  Metrics/ClassLength:
24
- Max: 186
24
+ Max: 188
25
25
 
26
26
  # Offense count: 2
27
27
  Metrics/CyclomaticComplexity:
data/README.md CHANGED
@@ -243,10 +243,24 @@ Capybara::Screenshot.stability_time_limit = 0.5
243
243
 
244
244
 
245
245
 
246
+ ### Removing focus from the active element
247
+
248
+ In Chrome the screenshot includes the blinking input cursor. This can make it impossible to get a
249
+ stable screenshot. To get around this you can set the `blur_active_element` option:
250
+
251
+ ```ruby
252
+ Capybara::Screenshot.blur_active_element = true
253
+ ```
254
+
255
+ This will remove the focus from the active element, removing the blinking cursor.
256
+
257
+
258
+
246
259
  ### Allowed color distance
247
260
 
248
- Sometimes you want to allow small differences in the images. You can set set the difference
249
- threshold for the comparison using the `color_distance_limit` option to the `screenshot` method:
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 comparison
263
+ using the `color_distance_limit` option to the `screenshot` method:
250
264
 
251
265
  ```ruby
252
266
  test 'color threshold' do
@@ -6,6 +6,7 @@ module Capybara
6
6
  module Screenshot
7
7
  mattr_accessor :add_driver_path
8
8
  mattr_accessor :add_os_path
9
+ mattr_accessor :blur_active_element
9
10
  mattr_accessor :enabled
10
11
  mattr_accessor :screenshot_root
11
12
  mattr_accessor :stability_time_limit
@@ -196,6 +196,7 @@ EOF
196
196
 
197
197
  private def take_stable_screenshot(comparison)
198
198
  assert_images_loaded
199
+ execute_script('document.activeElement.blur()') if Capybara::Screenshot.blur_active_element
199
200
  previous_file_size = comparison.old_file_size
200
201
  screeenshot_started_at = last_image_change_at = Time.now
201
202
  loop do
@@ -236,7 +237,7 @@ EOF
236
237
 
237
238
  def assert_image_not_changed(caller, name, comparison)
238
239
  return unless comparison.different?
239
- "Screenshot does not match for '#{name}' (area: #{comparison.size} #{comparison.dimensions}" \
240
+ "Screenshot does not match for '#{name}' (area: #{comparison.size}px #{comparison.dimensions}" \
240
241
  ", max_color_distance: #{comparison.max_color_distance.round(1)})\n" \
241
242
  "#{comparison.new_file_name}\n#{comparison.annotated_old_file_name}\n" \
242
243
  "#{comparison.annotated_new_file_name}\n" \
@@ -29,7 +29,7 @@ module Capybara
29
29
  end
30
30
 
31
31
  def reset
32
- @max_color_distance = 0 if @color_distance_limit
32
+ @max_color_distance = @color_distance_limit ? 0 : nil
33
33
  @left = @top = @right = @bottom = nil
34
34
  end
35
35
 
@@ -229,13 +229,12 @@ module Capybara
229
229
  private def same_color?(old_img, new_img, x, y)
230
230
  org_color = old_img[x, y]
231
231
  new_color = new_img[x, y]
232
- if @color_distance_limit && @color_distance_limit > 0
233
- distance = ChunkyPNG::Color.euclidean_distance_rgba(org_color, new_color)
234
- @max_color_distance = distance if distance > @max_color_distance
235
- distance <= @color_distance_limit
236
- else
237
- org_color == new_color
238
- end
232
+ return true if org_color == new_color
233
+
234
+ distance = ChunkyPNG::Color.euclidean_distance_rgba(org_color, new_color)
235
+ @max_color_distance = distance if !@max_color_distance || distance > @max_color_distance
236
+
237
+ @color_distance_limit && @color_distance_limit > 0 && distance <= @color_distance_limit
239
238
  end
240
239
  end
241
240
  end
@@ -3,7 +3,7 @@
3
3
  module Capybara
4
4
  module Screenshot
5
5
  module Diff
6
- VERSION = '0.6.0'.freeze
6
+ VERSION = '0.7.0'.freeze
7
7
  end
8
8
  end
9
9
  end
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.6.0
4
+ version: 0.7.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: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack