Module: Capybara::Screenshot::Diff::Stabilization
- Includes:
- Os
- Included in:
- TestMethods
- Defined in:
- lib/capybara/screenshot/diff/stabilization.rb
Constant Summary
collapse
- IMAGE_WAIT_SCRIPT =
<<-JS.strip_heredoc.freeze
function pending_image() {
var images = document.images;
for (var i = 0; i < images.length; i++) {
if (!images[i].complete) {
return images[i].src;
}
}
return false;
}()
JS
- HIDE_CARET_SCRIPT =
<<~JS
if (!document.getElementById('csdHideCaretStyle')) {
let style = document.createElement('style');
style.setAttribute('id', 'csdHideCaretStyle');
document.head.appendChild(style);
let styleSheet = style.sheet;
styleSheet.insertRule("* { caret-color: transparent !important; }", 0);
}
JS
Constants included
from Os
Os::ON_LINUX, Os::ON_MAC, Os::ON_WINDOWS
Instance Method Summary
collapse
Methods included from Os
#os_name
Instance Method Details
#notice_how_to_avoid_this ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/capybara/screenshot/diff/stabilization.rb', line 76
def notice_how_to_avoid_this
unless @_csd_retina_warned
warn "Halving retina screenshot. " \
'You should add "force-device-scale-factor=1" to your Chrome chromeOptions args.'
@_csd_retina_warned = true
end
end
|
#take_stable_screenshot(comparison, stability_time_limit:, wait:) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/capybara/screenshot/diff/stabilization.rb', line 33
def take_stable_screenshot(comparison, stability_time_limit:, wait:)
previous_file_name = comparison.old_file_name
screenshot_started_at = last_image_change_at = Time.now
clean_stabilization_images(comparison.new_file_name)
1.step do |i|
take_right_size_screenshot(comparison)
if comparison.quick_equal?
clean_stabilization_images(comparison.new_file_name)
break
end
comparison.reset
if previous_file_name
stabilization_comparison = make_stabilization_comparison_from(
comparison,
comparison.new_file_name,
previous_file_name
)
if stabilization_comparison.quick_equal?
if (Time.now - last_image_change_at) > stability_time_limit
clean_stabilization_images(comparison.new_file_name)
break
end
next
else
last_image_change_at = Time.now
end
end
previous_file_name = "#{comparison.new_file_name.chomp(".png")}" \
"_x#{format("%02i", i)}_#{(Time.now - screenshot_started_at).round(1)}s" \
"_#{stabilization_comparison.difference_region&.to_s&.gsub(", ", "_") || :initial}.png~"
FileUtils.mv comparison.new_file_name, previous_file_name
check_max_wait_time(
comparison,
screenshot_started_at,
max_wait_time: max_wait_time(comparison.shift_distance_limit, wait)
)
end
end
|