Module: Capybara::Screenshot::Diff::TestMethods
Constant Summary
BrowserHelpers::FIND_ACTIVE_ELEMENT_SCRIPT, BrowserHelpers::GET_BOUNDING_CLIENT_RECT_SCRIPT, BrowserHelpers::HIDE_CARET_SCRIPT, BrowserHelpers::IMAGE_WAIT_SCRIPT
Constants included
from Vcs
Vcs::SILENCE_ERRORS
Constants included
from Os
Os::ON_LINUX, Os::ON_MAC, Os::ON_WINDOWS
Instance Method Summary
collapse
#all_visible_regions_for, #blur_from_focused_element, #bounds_for_css, #current_capybara_driver_class, #hide_caret, #pending_image_to_load, #rect_for, #region_for, #selenium?, #window_size_is_wrong?
Methods included from Vcs
#checkout_vcs, #restore_git_revision
#notice_how_to_avoid_this, #take_stable_screenshot
Methods included from Os
#os_name
Instance Method Details
#assert_image_not_changed(caller, name, comparison) ⇒ Object
95
96
97
98
99
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 95
def assert_image_not_changed(caller, name, comparison)
return unless comparison.different?
"Screenshot does not match for '#{name}' #{comparison.error_message}\nat #{caller}"
end
|
#full_name(name) ⇒ Object
39
40
41
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 39
def full_name(name)
File.join group_parts.push(name).map(&:to_s)
end
|
#group_parts ⇒ Object
32
33
34
35
36
37
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 32
def group_parts
parts = []
parts << @screenshot_section if @screenshot_section.present?
parts << @screenshot_group if @screenshot_group.present?
parts
end
|
#initialize ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 23
def initialize(*)
super
@screenshot_counter = nil
@screenshot_group = nil
@screenshot_section = nil
@test_screenshot_errors = nil
@test_screenshots = nil
end
|
#screenshot(name, skip_stack_frames: 0, **options) ⇒ Boolean
Returns whether a screenshot was taken.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 60
def screenshot(name, skip_stack_frames: 0, **options)
return false unless Screenshot.active?
return false if window_size_is_wrong?
driver_options = Diff.default_options.merge(options)
stability_time_limit = driver_options[:stability_time_limit]
wait = driver_options[:wait]
crop = calculate_crop_region(driver_options)
if @screenshot_counter
name = "#{format("%02i", @screenshot_counter)}_#{name}"
@screenshot_counter += 1
end
name = full_name(name)
file_name = "#{Screenshot.screenshot_area_abs}/#{name}.png"
create_output_directory_for(file_name)
comparison = ImageCompare.new(file_name, nil, driver_options)
checkout_vcs(name, comparison.old_file_name, comparison.new_file_name)
take_screenshot(comparison, crop, stability_time_limit, wait)
return false unless comparison.old_file_exists?
if driver_options[:skip_area]
comparison.skip_area = calculate_skip_area(driver_options[:skip_area], crop)
end
(@test_screenshots ||= []) << [caller[skip_stack_frames], name, comparison]
true
end
|
#screenshot_dir ⇒ Object
43
44
45
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 43
def screenshot_dir
File.join [Screenshot.screenshot_area] + group_parts
end
|
#screenshot_group(name) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 51
def screenshot_group(name)
@screenshot_group = name.to_s
@screenshot_counter = 0
return unless Screenshot.active? && name.present?
FileUtils.rm_rf screenshot_dir
end
|
#screenshot_section(name) ⇒ Object
47
48
49
|
# File 'lib/capybara/screenshot/diff/test_methods.rb', line 47
def screenshot_section(name)
@screenshot_section = name.to_s
end
|