9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ui-auto-monkey/tuneup/image_assertion.rb', line 9
def self.assert_image(test_output, ref_images_path, image_name, threshold)
return false unless (test_output && ref_images_path && image_name)
diff_images_path = File.join(test_output, DIFF_IMAGE_FOLDER_NAME)
Dir.mkdir(diff_images_path) unless File.directory?(diff_images_path)
image_file_name = image_name + '.png'
expected_path = File.join(ref_images_path, image_file_name)
diff_path = File.join(diff_images_path, image_file_name)
run_folder_name = find_last_folder(test_output)
received_path = File.join(run_folder_name, image_file_name)
print_status(create_status('started', "Asserting #{image_file_name}."))
if !File.exists?(received_path)
error = "No captured image file found at #{received_path}"
print_status(create_status('failed', error))
return false
elsif !File.exists?(expected_path)
error = "No reference image file found at #{expected_path}"
print_status(create_status('failed', error))
return false
else
result, exit_status = im_compare(expected_path, received_path, diff_path)
if exit_status == 0
return process_imagemagick_result(image_file_name, result, threshold)
elsif exit_status == 1
print_status(create_status('failed', "Images differ, check #{diff_images_path} for details. ImageMagick error: #{result}"))
else
print_status(create_status('failed', "ImageMagick comparison failed: #{result}"))
end
end
end
|