capybara-screenshot-diff 1.2.1 → 1.3.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
  SHA256:
3
- metadata.gz: fd19e8c2bc84aa9f1339d82fc20b16767337d3518364e1a658f73fd832488a6b
4
- data.tar.gz: 584607e9e33873c9b5411320f721ad350d125b7d8acc3ae03d98371c8ffe86a2
3
+ metadata.gz: 6e4f48d95925d0da6d7b8afcb53b0179c0477fb034ea88e9e2dde8db02d4fb61
4
+ data.tar.gz: 9c6c456601df79a02b4b647f3c0cca0c0439194534c73522054c87d39926b89c
5
5
  SHA512:
6
- metadata.gz: e71fcea0778aff709d4857706d6b880fd8ea5336886025c12fb8cc9573a350010df137a1bf44f797e49b9e6aa8bd53e05153e90f729d648fce62e3f51a103160
7
- data.tar.gz: febeb583ce4dbd4a2f125103cd86b48a2d9dcace05a7158dc5f1cabf6f807031ca0e4619fffaf41a18e8277354c0567fa31abd8e220a9fbc4a6bf1d85170f53b
6
+ metadata.gz: 54f1f31ec364031eed15cadd22a3e2305874802480efb9ca0b0b2c35a6954293b31552971751f143fc2a6056a96d6d49df31f0c16c3d2785491ed7664f3b1f7c
7
+ data.tar.gz: 872732c38c6f1822b68d56b94b27c5aeba37ffd1f39379a4e15f76b8ed248d62c787514daa724ed10f22cda1f56b4442dd0753889fc28b99d2fb8299be16c821
data/README.md CHANGED
@@ -307,6 +307,17 @@ test 'stability_time_limit' do
307
307
  end
308
308
  ```
309
309
 
310
+ ### Maximum wait limit
311
+
312
+ When the `stability_time_limit` is set, but no stable screenshot can be taken, a timeout occurs.
313
+ The timeout occurs after `Capybara.default_max_wait_time`, but can be overridden by an option.
314
+
315
+ ```ruby
316
+ test 'max wait time' do
317
+ visit '/'
318
+ screenshot 'index', wait: 20.seconds
319
+ end
320
+ ```
310
321
 
311
322
  ### Removing focus from the active element
312
323
 
@@ -21,8 +21,8 @@ module Capybara
21
21
  JS
22
22
 
23
23
  def take_stable_screenshot(comparison, color_distance_limit:, shift_distance_limit:,
24
- area_size_limit:, skip_area:, stability_time_limit:)
25
- blurred_input = prepare_page_for_screenshot
24
+ area_size_limit:, skip_area:, stability_time_limit:, wait:)
25
+ blurred_input = prepare_page_for_screenshot(timeout: wait)
26
26
  previous_file_name = comparison.old_file_name
27
27
  screenshot_started_at = last_image_change_at = Time.now
28
28
  1.step do |i|
@@ -56,7 +56,7 @@ module Capybara
56
56
  FileUtils.mv comparison.new_file_name, previous_file_name
57
57
 
58
58
  check_max_wait_time(comparison, screenshot_started_at,
59
- shift_distance_limit: shift_distance_limit)
59
+ wait: wait, shift_distance_limit: shift_distance_limit)
60
60
  end
61
61
  ensure
62
62
  blurred_input&.click
@@ -89,8 +89,8 @@ module Capybara
89
89
  FileUtils.rm stabilization_images(base_file)
90
90
  end
91
91
 
92
- def prepare_page_for_screenshot
93
- assert_images_loaded
92
+ def prepare_page_for_screenshot(timeout:)
93
+ assert_images_loaded(timeout: timeout)
94
94
  if Capybara::Screenshot.blur_active_element
95
95
  active_element = execute_script(<<-JS)
96
96
  ae = document.activeElement;
@@ -114,15 +114,15 @@ module Capybara
114
114
  # ODOT
115
115
  end
116
116
 
117
- def check_max_wait_time(comparison, screenshot_started_at, shift_distance_limit:)
117
+ def check_max_wait_time(comparison, screenshot_started_at, wait:, shift_distance_limit:)
118
118
  shift_factor = shift_distance_limit ? (shift_distance_limit * 2 + 1) ^ 2 : 1
119
- max_wait_time = Capybara.default_max_wait_time * shift_factor
119
+ max_wait_time = wait * shift_factor
120
120
  assert((Time.now - screenshot_started_at) < max_wait_time,
121
121
  "Could not get stable screenshot within #{max_wait_time}s\n" \
122
122
  "#{stabilization_images(comparison.new_file_name).join("\n")}")
123
123
  end
124
124
 
125
- def assert_images_loaded(timeout: Capybara.default_max_wait_time)
125
+ def assert_images_loaded(timeout:)
126
126
  return unless respond_to? :evaluate_script
127
127
 
128
128
  start = Time.now
@@ -71,7 +71,8 @@ module Capybara
71
71
  def screenshot(name, area_size_limit: Diff.area_size_limit,
72
72
  color_distance_limit: Diff.color_distance_limit,
73
73
  shift_distance_limit: Diff.shift_distance_limit, skip_area: Diff.skip_area,
74
- stability_time_limit: Screenshot.stability_time_limit)
74
+ stability_time_limit: Screenshot.stability_time_limit,
75
+ wait: Capybara.default_max_wait_time)
75
76
  return unless Screenshot.active?
76
77
  return if window_size_is_wrong?
77
78
 
@@ -94,7 +95,8 @@ module Capybara
94
95
  shift_distance_limit: shift_distance_limit,
95
96
  area_size_limit: area_size_limit,
96
97
  skip_area: skip_area,
97
- stability_time_limit: stability_time_limit)
98
+ stability_time_limit: stability_time_limit,
99
+ wait: wait)
98
100
  return unless comparison.old_file_exists?
99
101
 
100
102
  (@test_screenshots ||= []) << [caller(1..1).first, name, comparison]
@@ -3,7 +3,7 @@
3
3
  module Capybara
4
4
  module Screenshot
5
5
  module Diff
6
- VERSION = '1.2.1'
6
+ VERSION = '1.3.0'
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: 1.2.1
4
+ version: 1.3.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: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack