-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwindow_helper.rb
57 lines (44 loc) · 1.38 KB
/
window_helper.rb
1
2
3
4
5
6
7
8
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require_relative 'capybara_extensions'
module WindowHelper
def scroll_to_top
return unless jsable_driver?
execute_script "window.scrollTo(0, 0)"
end
def scroll_to_bottom
return unless jsable_driver?
execute_script "window.scrollTo(0, document.body.scrollHeight)"
end
def scroll_to_field(locator)
return unless jsable_driver?
field = find_field locator
element_id = field[:id]
css_selector = "##{element_id}"
scroll_to_element css_selector
end
def scroll_to_element(css_selector)
return unless jsable_driver?
execute_script <<-JS
(function() {
var element = $('#{css_selector}');
var elementScrollOffset = element.offset().top;
var fixedNavHeightAllowance = $('.navbar-fixed-top').outerHeight() || 0;
var totalScrollOffset = elementScrollOffset - fixedNavHeightAllowance;
window.scrollTo(0, totalScrollOffset);
})();
JS
end
def maximize_window
return unless jsable_driver?
available_width, available_height = execute_script <<-JS
if (window.screen) {
return [window.screen.availWidth, window.screen.availHeight];
}
return [0, 0];
JS
return if available_width == 0 || available_height == 0
current_window.resize_to(available_width, available_height)
end
end
RSpec.configure do |config|
config.include WindowHelper, type: :feature
end