lib/capybara/screenshot/diff/screenshoter.rb in capybara-screenshot-diff-1.9.0 vs lib/capybara/screenshot/diff/screenshoter.rb in capybara-screenshot-diff-1.9.2

- old
+ new

@@ -4,15 +4,14 @@ require_relative "browser_helpers" module Capybara module Screenshot class Screenshoter - attr_reader :capture_options, :comparison_options, :driver + attr_reader :capture_options, :driver def initialize(capture_options, driver) @capture_options = capture_options - @comparison_options = comparison_options @driver = driver end def crop @capture_options[:crop] @@ -20,40 +19,22 @@ def wait @capture_options[:wait] end - def screenshot_format - @capture_options[:screenshot_format] || "png" - end - def capybara_screenshot_options @capture_options[:capybara_screenshot_options] || {} end - def self.attempts_screenshot_paths(base_file) - extname = Pathname.new(base_file).extname - Dir["#{base_file.to_s.chomp(extname)}.attempt_*#{extname}"].sort - end - - def self.cleanup_attempts_screenshots(base_file) - FileUtils.rm_rf attempts_screenshot_paths(base_file) - end - # Try to get screenshot from browser. # On `stability_time_limit` it checks that page stop updating by comparison several screenshot attempts # On reaching `wait` limit then it has been failed. On failing we annotate screenshot attempts to help to debug - def take_comparison_screenshot(screenshot_path) - capture_screenshot_at(screenshot_path) - - Screenshoter.cleanup_attempts_screenshots(screenshot_path) + def take_comparison_screenshot(snapshot) + capture_screenshot_at(snapshot) + snapshot.cleanup_attempts end - def self.gen_next_attempt_path(screenshot_path, iteration) - screenshot_path.sub_ext(format(".attempt_%02i#{screenshot_path.extname}", iteration)) - end - PNG_EXTENSION = ".png" def take_screenshot(screenshot_path) blurred_input = prepare_page_for_screenshot(timeout: wait) @@ -121,21 +102,13 @@ process_screenshot(tmpfile.path, screenshot_path) ensure File.unlink(tmpfile) if tmpfile end - def capture_screenshot_at(screenshot_path) - new_screenshot_path = Screenshoter.gen_next_attempt_path(screenshot_path, 0) - take_and_process_screenshot(new_screenshot_path, screenshot_path) - end + def capture_screenshot_at(snapshot) + take_screenshot(snapshot.next_attempt_path!) - def take_and_process_screenshot(new_screenshot_path, screenshot_path) - take_screenshot(new_screenshot_path) - move_screenshot_to(new_screenshot_path, screenshot_path) - end - - def move_screenshot_to(new_screenshot_path, screenshot_path) - FileUtils.mv(new_screenshot_path, screenshot_path, force: true) + snapshot.commit_last_attempt end def resize_if_needed(saved_image) expected_image_width = Screenshot.window_size[0] return saved_image if driver.width_for(saved_image) < expected_image_width * 2