class CapybaraScreenshotDiff::AttemptsReporter
Public Class Methods
Source
# File lib/capybara_screenshot_diff/attempts_reporter.rb, line 7 def initialize(snapshot, comparison_options, stability_options = {}) @snapshot = snapshot @comparison_options = comparison_options @wait = stability_options[:wait] end
Public Instance Methods
Source
# File lib/capybara_screenshot_diff/attempts_reporter.rb, line 21 def build_comparison_for(attempt_path, previous_attempt_path) Capybara::Screenshot::Diff::ImageCompare.new(attempt_path, previous_attempt_path, @comparison_options) end
Source
# File lib/capybara_screenshot_diff/attempts_reporter.rb, line 13 def generate attempts_screenshot_paths = @snapshot.find_attempts_paths annotate_attempts(attempts_screenshot_paths) "Could not get stable screenshot within #{@wait}s:\n#{attempts_screenshot_paths.join("\n")}" end
Private Instance Methods
Source
# File lib/capybara_screenshot_diff/attempts_reporter.rb, line 27 def annotate_attempts(attempts_screenshot_paths) previous_file = nil attempts_screenshot_paths.reverse_each do |file_name| if previous_file && File.exist?(previous_file) attempts_comparison = build_comparison_for(file_name, previous_file) if attempts_comparison.different? FileUtils.mv(attempts_comparison.reporter.annotated_base_image_path, previous_file, force: true) else warn "[capybara-screenshot-diff] Some attempts was stable, but mistakenly marked as not: " \ "#{previous_file} and #{file_name} are equal" end FileUtils.rm(attempts_comparison.reporter.annotated_image_path, force: true) end previous_file = file_name end previous_file end