lib/capybara/screenshot/diff/stabilization.rb in capybara-screenshot-diff-1.2.1 vs lib/capybara/screenshot/diff/stabilization.rb in capybara-screenshot-diff-1.3.0

- old
+ new

@@ -19,12 +19,12 @@ return false; }() JS def take_stable_screenshot(comparison, color_distance_limit:, shift_distance_limit:, - area_size_limit:, skip_area:, stability_time_limit:) - blurred_input = prepare_page_for_screenshot + area_size_limit:, skip_area:, stability_time_limit:, wait:) + blurred_input = prepare_page_for_screenshot(timeout: wait) previous_file_name = comparison.old_file_name screenshot_started_at = last_image_change_at = Time.now 1.step do |i| take_right_size_screenshot(comparison) @@ -54,11 +54,11 @@ previous_file_name = "#{comparison.new_file_name.chomp('.png')}_x#{format('%02i', i)}.png~" FileUtils.mv comparison.new_file_name, previous_file_name check_max_wait_time(comparison, screenshot_started_at, - shift_distance_limit: shift_distance_limit) + wait: wait, shift_distance_limit: shift_distance_limit) end ensure blurred_input&.click end @@ -87,12 +87,12 @@ def clean_stabilization_images(base_file) FileUtils.rm stabilization_images(base_file) end - def prepare_page_for_screenshot - assert_images_loaded + def prepare_page_for_screenshot(timeout:) + assert_images_loaded(timeout: timeout) if Capybara::Screenshot.blur_active_element active_element = execute_script(<<-JS) ae = document.activeElement; if (ae.nodeName == "INPUT" || ae.nodeName == "TEXTAREA") { ae.blur(); @@ -112,18 +112,18 @@ # TODO(uwe): Remove when chromedriver takes right size screenshots reduce_retina_image_size(comparison.new_file_name) # ODOT end - def check_max_wait_time(comparison, screenshot_started_at, shift_distance_limit:) + def check_max_wait_time(comparison, screenshot_started_at, wait:, shift_distance_limit:) shift_factor = shift_distance_limit ? (shift_distance_limit * 2 + 1) ^ 2 : 1 - max_wait_time = Capybara.default_max_wait_time * shift_factor + max_wait_time = wait * shift_factor assert((Time.now - screenshot_started_at) < max_wait_time, "Could not get stable screenshot within #{max_wait_time}s\n" \ "#{stabilization_images(comparison.new_file_name).join("\n")}") end - def assert_images_loaded(timeout: Capybara.default_max_wait_time) + def assert_images_loaded(timeout:) return unless respond_to? :evaluate_script start = Time.now loop do pending_image = evaluate_script IMAGE_WAIT_SCRIPT