capybara 3.35.0 → 3.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +168 -5
- data/README.md +199 -39
- data/lib/capybara/config.rb +16 -4
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/driver/node.rb +5 -1
- data/lib/capybara/dsl.rb +4 -10
- data/lib/capybara/helpers.rb +9 -14
- data/lib/capybara/minitest/spec.rb +18 -6
- data/lib/capybara/minitest.rb +14 -1
- data/lib/capybara/node/actions.rb +14 -9
- data/lib/capybara/node/base.rb +2 -1
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/element.rb +13 -2
- data/lib/capybara/node/finders.rb +11 -2
- data/lib/capybara/node/matchers.rb +25 -0
- data/lib/capybara/node/simple.rb +5 -1
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +2 -1
- data/lib/capybara/queries/base_query.rb +2 -2
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +40 -11
- data/lib/capybara/queries/sibling_query.rb +2 -1
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +64 -8
- data/lib/capybara/rack_test/driver.rb +4 -4
- data/lib/capybara/rack_test/form.rb +29 -7
- data/lib/capybara/rack_test/node.rb +32 -33
- data/lib/capybara/registration_container.rb +2 -5
- data/lib/capybara/registrations/drivers.rb +7 -7
- data/lib/capybara/registrations/servers.rb +37 -16
- data/lib/capybara/result.rb +2 -2
- data/lib/capybara/rspec/matcher_proxies.rb +6 -6
- data/lib/capybara/rspec/matchers/base.rb +8 -6
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/rspec/matchers/have_selector.rb +9 -17
- data/lib/capybara/rspec/matchers.rb +21 -16
- data/lib/capybara/selector/builders/css_builder.rb +1 -1
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +6 -6
- data/lib/capybara/selector/definition/button.rb +10 -5
- data/lib/capybara/selector/definition/checkbox.rb +1 -1
- data/lib/capybara/selector/definition/file_field.rb +1 -1
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +2 -1
- data/lib/capybara/selector/definition/radio_button.rb +1 -1
- data/lib/capybara/selector/definition/table.rb +1 -1
- data/lib/capybara/selector/definition/table_row.rb +2 -2
- data/lib/capybara/selector/definition.rb +4 -2
- data/lib/capybara/selector/filter_set.rb +4 -7
- data/lib/capybara/selector/regexp_disassembler.rb +2 -5
- data/lib/capybara/selector/selector.rb +5 -1
- data/lib/capybara/selector.rb +252 -0
- data/lib/capybara/selenium/driver.rb +31 -54
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +1 -1
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -5
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -7
- data/lib/capybara/selenium/extensions/html5_drag.rb +5 -4
- data/lib/capybara/selenium/node.rb +60 -38
- data/lib/capybara/selenium/nodes/chrome_node.rb +4 -16
- data/lib/capybara/selenium/nodes/edge_node.rb +19 -13
- data/lib/capybara/selenium/nodes/firefox_node.rb +3 -3
- data/lib/capybara/selenium/nodes/safari_node.rb +4 -4
- data/lib/capybara/selenium/patches/atoms.rb +1 -1
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
- data/lib/capybara/server/animation_disabler.rb +40 -23
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/server.rb +1 -1
- data/lib/capybara/session/config.rb +4 -2
- data/lib/capybara/session.rb +34 -34
- data/lib/capybara/spec/public/test.js +4 -0
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +11 -15
- data/lib/capybara/spec/session/assert_text_spec.rb +17 -17
- data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
- data/lib/capybara/spec/session/check_spec.rb +10 -0
- data/lib/capybara/spec/session/choose_spec.rb +6 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
- data/lib/capybara/spec/session/click_link_spec.rb +12 -1
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +15 -1
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +2 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -2
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/has_button_spec.rb +30 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +3 -3
- data/lib/capybara/spec/session/has_element_spec.rb +47 -0
- data/lib/capybara/spec/session/has_field_spec.rb +25 -1
- data/lib/capybara/spec/session/has_link_spec.rb +40 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +10 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +15 -0
- data/lib/capybara/spec/session/has_table_spec.rb +13 -2
- data/lib/capybara/spec/session/has_text_spec.rb +6 -14
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -0
- data/lib/capybara/spec/session/node_spec.rb +88 -1
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +13 -0
- data/lib/capybara/spec/session/scroll_spec.rb +7 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +1 -1
- data/lib/capybara/spec/session/visit_spec.rb +20 -0
- data/lib/capybara/spec/session/window/window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/session/within_spec.rb +13 -0
- data/lib/capybara/spec/spec_helper.rb +12 -5
- data/lib/capybara/spec/test_app.rb +91 -14
- data/lib/capybara/spec/views/animated.erb +1 -1
- data/lib/capybara/spec/views/form.erb +34 -4
- data/lib/capybara/spec/views/frame_child.erb +1 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +1 -1
- data/lib/capybara/spec/views/offset.erb +2 -1
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +2 -2
- data/lib/capybara/spec/views/scroll.erb +2 -1
- data/lib/capybara/spec/views/spatial.erb +1 -1
- data/lib/capybara/spec/views/with_animation.erb +2 -3
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +2 -2
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +2 -2
- data/lib/capybara/spec/views/with_html.erb +5 -3
- data/lib/capybara/spec/views/with_jquery_animation.erb +1 -1
- data/lib/capybara/spec/views/with_js.erb +2 -3
- data/lib/capybara/spec/views/with_jstree.erb +1 -1
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/spec/views/with_shadow.erb +31 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +2 -2
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +1 -1
- data/lib/capybara.rb +30 -30
- data/spec/basic_node_spec.rb +16 -3
- data/spec/capybara_spec.rb +12 -0
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +1 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +5 -3
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/minitest_spec.rb +12 -1
- data/spec/minitest_spec_spec.rb +4 -0
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +30 -12
- data/spec/result_spec.rb +41 -35
- data/spec/rspec/features_spec.rb +3 -3
- data/spec/rspec/scenarios_spec.rb +2 -2
- data/spec/rspec/shared_spec_matchers.rb +27 -3
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +3 -3
- data/spec/sauce_spec_chrome.rb +5 -5
- data/spec/selector_spec.rb +4 -4
- data/spec/selenium_spec_chrome.rb +20 -18
- data/spec/selenium_spec_chrome_remote.rb +15 -19
- data/spec/selenium_spec_edge.rb +19 -6
- data/spec/selenium_spec_firefox.rb +26 -8
- data/spec/selenium_spec_firefox_remote.rb +18 -4
- data/spec/selenium_spec_ie.rb +7 -8
- data/spec/selenium_spec_safari.rb +34 -20
- data/spec/server_spec.rb +19 -7
- data/spec/shared_selenium_node.rb +0 -4
- data/spec/shared_selenium_session.rb +22 -14
- data/spec/spec_helper.rb +36 -3
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +1 -1
- metadata +49 -30
- data/lib/capybara/selenium/logger_suppressor.rb +0 -34
- data/lib/capybara/selenium/patches/action_pauser.rb +0 -26
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -65,6 +65,24 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
65
65
|
it 'should not affect other selectors when enable_aria_role: false' do
|
66
66
|
expect(@session).to have_button('Click me!', enable_aria_role: false)
|
67
67
|
end
|
68
|
+
|
69
|
+
context 'with focused:', requires: [:active_element] do
|
70
|
+
it 'should be true if a field has focus when focused: true' do
|
71
|
+
@session.send_keys(:tab)
|
72
|
+
|
73
|
+
expect(@session).to have_button('A Button', focused: true)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should be true if a field does not have focus when focused: false' do
|
77
|
+
expect(@session).to have_button('A Button', focused: false)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should raise an error if an invalid option is passed' do
|
82
|
+
expect do
|
83
|
+
expect(@session).to have_button('A Button', invalid: true)
|
84
|
+
end.to raise_error(ArgumentError, 'Invalid option(s) :invalid, should be one of :above, :below, :left_of, :right_of, :near, :count, :minimum, :maximum, :between, :text, :id, :class, :style, :visible, :obscured, :exact, :exact_text, :normalize_ws, :match, :wait, :filter_set, :focused, :disabled, :name, :value, :title, :type')
|
85
|
+
end
|
68
86
|
end
|
69
87
|
|
70
88
|
Capybara::SpecHelper.spec '#has_no_button?' do
|
@@ -117,4 +135,16 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
117
135
|
it 'should not affect other selectors when enable_aria_role: false' do
|
118
136
|
expect(@session).to have_no_button('Junk button that does not exist', enable_aria_role: false)
|
119
137
|
end
|
138
|
+
|
139
|
+
context 'with focused:', requires: [:active_element] do
|
140
|
+
it 'should be true if a button does not have focus when focused: true' do
|
141
|
+
expect(@session).to have_no_button('A Button', focused: true)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should be false if a button has focus when focused: false' do
|
145
|
+
@session.send_keys(:tab)
|
146
|
+
|
147
|
+
expect(@session).to have_no_button('A Button', focused: false)
|
148
|
+
end
|
149
|
+
end
|
120
150
|
end
|
@@ -16,8 +16,8 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
16
16
|
|
17
17
|
it 'should not raise an error when non-http' do
|
18
18
|
@session.reset_session!
|
19
|
-
expect(@session.has_current_path?(/monkey/)).to
|
20
|
-
expect(@session.has_current_path?('/with_js')).to
|
19
|
+
expect(@session.has_current_path?(/monkey/)).to be false
|
20
|
+
expect(@session.has_current_path?('/with_js')).to be false
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should handle non-escaped query options' do
|
@@ -75,7 +75,7 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
75
75
|
@session.visit('/with_js?test=test')
|
76
76
|
expect(@session).to have_current_path('/with_js?test=test')
|
77
77
|
expect(@session).to have_current_path('/with_js', ignore_query: true)
|
78
|
-
uri =
|
78
|
+
uri = Addressable::URI.parse(@session.current_url)
|
79
79
|
uri.query = nil
|
80
80
|
expect(@session).to have_current_path(uri.to_s, ignore_query: true)
|
81
81
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#has_element?' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be true if the given element is on the page' do
|
9
|
+
expect(@session).to have_element('a', id: 'foo')
|
10
|
+
expect(@session).to have_element('a', text: 'A link', href: '/with_simple_html')
|
11
|
+
expect(@session).to have_element('a', text: :'A link', href: :'/with_simple_html')
|
12
|
+
expect(@session).to have_element('a', text: 'A link', href: %r{/with_simple_html})
|
13
|
+
expect(@session).to have_element('a', text: 'labore', target: '_self')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be false if the given element is not on the page' do
|
17
|
+
expect(@session).not_to have_element('a', text: 'monkey')
|
18
|
+
expect(@session).not_to have_element('a', text: 'A link', href: '/nonexistent-href')
|
19
|
+
expect(@session).not_to have_element('a', text: 'A link', href: /nonexistent/)
|
20
|
+
expect(@session).not_to have_element('a', text: 'labore', target: '_blank')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should notify if an invalid locator is specified' do
|
24
|
+
allow(Capybara::Helpers).to receive(:warn).and_return(nil)
|
25
|
+
@session.has_element?(@session)
|
26
|
+
expect(Capybara::Helpers).to have_received(:warn).with(/Called from: .+/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Capybara::SpecHelper.spec '#has_no_element?' do
|
31
|
+
before do
|
32
|
+
@session.visit('/with_html')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should be false if the given element is on the page' do
|
36
|
+
expect(@session).not_to have_no_element('a', id: 'foo')
|
37
|
+
expect(@session).not_to have_no_element('a', text: 'A link', href: '/with_simple_html')
|
38
|
+
expect(@session).not_to have_no_element('a', text: 'labore', target: '_self')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should be true if the given element is not on the page' do
|
42
|
+
expect(@session).to have_no_element('a', text: 'monkey')
|
43
|
+
expect(@session).to have_no_element('a', text: 'A link', href: '/nonexistent-href')
|
44
|
+
expect(@session).to have_no_element('a', text: 'A link', href: %r{/nonexistent-href})
|
45
|
+
expect(@session).to have_no_element('a', text: 'labore', target: '_blank')
|
46
|
+
end
|
47
|
+
end
|
@@ -110,6 +110,18 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
context 'with focused:', requires: [:active_element] do
|
114
|
+
it 'should be true if a field has focus' do
|
115
|
+
2.times { @session.send_keys(:tab) }
|
116
|
+
|
117
|
+
expect(@session).to have_field('An Input', focused: true)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should be false if a field does not have focus' do
|
121
|
+
expect(@session).to have_field('An Input', focused: false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
113
125
|
context 'with valid', requires: [:js] do
|
114
126
|
it 'should be true if field is valid' do
|
115
127
|
@session.fill_in 'required', with: 'something'
|
@@ -184,6 +196,18 @@ Capybara::SpecHelper.spec '#has_no_field' do
|
|
184
196
|
expect(@session).to have_no_field('Languages', type: 'textarea')
|
185
197
|
end
|
186
198
|
end
|
199
|
+
|
200
|
+
context 'with focused:', requires: [:active_element] do
|
201
|
+
it 'should be true if a field does not have focus when focused: true' do
|
202
|
+
expect(@session).to have_no_field('An Input', focused: true)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should be false if a field has focus when focused: true' do
|
206
|
+
2.times { @session.send_keys(:tab) }
|
207
|
+
|
208
|
+
expect(@session).not_to have_no_field('An Input', focused: true)
|
209
|
+
end
|
210
|
+
end
|
187
211
|
end
|
188
212
|
|
189
213
|
Capybara::SpecHelper.spec '#has_checked_field?' do
|
@@ -359,7 +383,7 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|
359
383
|
end
|
360
384
|
|
361
385
|
it 'should support locator-less usage' do
|
362
|
-
expect(@session.has_no_unchecked_field?(disabled: false, id: 'form_disabled_unchecked_checkbox')).to
|
386
|
+
expect(@session.has_no_unchecked_field?(disabled: false, id: 'form_disabled_unchecked_checkbox')).to be true
|
363
387
|
expect(@session).to have_no_unchecked_field(disabled: false, id: 'form_disabled_unchecked_checkbox')
|
364
388
|
end
|
365
389
|
end
|
@@ -11,12 +11,38 @@ Capybara::SpecHelper.spec '#has_link?' do
|
|
11
11
|
expect(@session).to have_link('A link', href: '/with_simple_html')
|
12
12
|
expect(@session).to have_link(:'A link', href: :'/with_simple_html')
|
13
13
|
expect(@session).to have_link('A link', href: %r{/with_simple_html})
|
14
|
+
expect(@session).to have_link('labore', target: '_self')
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'should be false if the given link is not on the page' do
|
17
18
|
expect(@session).not_to have_link('monkey')
|
18
19
|
expect(@session).not_to have_link('A link', href: '/nonexistent-href')
|
19
20
|
expect(@session).not_to have_link('A link', href: /nonexistent/)
|
21
|
+
expect(@session).not_to have_link('labore', target: '_blank')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should notify if an invalid locator is specified' do
|
25
|
+
allow(Capybara::Helpers).to receive(:warn).and_return(nil)
|
26
|
+
@session.has_link?(@session)
|
27
|
+
expect(Capybara::Helpers).to have_received(:warn).with(/Called from: .+/)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with focused:', requires: [:active_element] do
|
31
|
+
it 'should be true if the given link is on the page and has focus' do
|
32
|
+
@session.send_keys(:tab)
|
33
|
+
|
34
|
+
expect(@session).to have_link('labore', focused: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should be false if the given link is on the page and does not have focus' do
|
38
|
+
expect(@session).to have_link('labore', focused: false)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should raise an error if an invalid option is passed' do
|
43
|
+
expect do
|
44
|
+
expect(@session).to have_link('labore', invalid: true)
|
45
|
+
end.to raise_error(ArgumentError, 'Invalid option(s) :invalid, should be one of :above, :below, :left_of, :right_of, :near, :count, :minimum, :maximum, :between, :text, :id, :class, :style, :visible, :obscured, :exact, :exact_text, :normalize_ws, :match, :wait, :filter_set, :focused, :href, :alt, :title, :target, :download')
|
20
46
|
end
|
21
47
|
end
|
22
48
|
|
@@ -29,11 +55,25 @@ Capybara::SpecHelper.spec '#has_no_link?' do
|
|
29
55
|
expect(@session).not_to have_no_link('foo')
|
30
56
|
expect(@session).not_to have_no_link('awesome title')
|
31
57
|
expect(@session).not_to have_no_link('A link', href: '/with_simple_html')
|
58
|
+
expect(@session).not_to have_no_link('labore', target: '_self')
|
32
59
|
end
|
33
60
|
|
34
61
|
it 'should be true if the given link is not on the page' do
|
35
62
|
expect(@session).to have_no_link('monkey')
|
36
63
|
expect(@session).to have_no_link('A link', href: '/nonexistent-href')
|
37
64
|
expect(@session).to have_no_link('A link', href: %r{/nonexistent-href})
|
65
|
+
expect(@session).to have_no_link('labore', target: '_blank')
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with focused:', requires: [:active_element] do
|
69
|
+
it 'should be true if the given link is on the page and has focus' do
|
70
|
+
expect(@session).to have_no_link('labore', focused: true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should be false if the given link is on the page and does not have focus' do
|
74
|
+
@session.send_keys(:tab)
|
75
|
+
|
76
|
+
expect(@session).to have_no_link('labore', focused: false)
|
77
|
+
end
|
38
78
|
end
|
39
79
|
end
|
@@ -8,10 +8,10 @@ Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
|
8
8
|
it 'should be false if any of the given locators are on the page' do
|
9
9
|
expect do
|
10
10
|
expect(@session).to have_none_of_selectors(:xpath, '//p', '//a')
|
11
|
-
end.to raise_error
|
11
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
12
12
|
expect do
|
13
13
|
expect(@session).to have_none_of_selectors(:css, 'p a#foo')
|
14
|
-
end.to raise_error
|
14
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be true if none of the given locators are on the page' do
|
@@ -24,7 +24,7 @@ Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
|
24
24
|
expect(@session).to have_none_of_selectors('p a#doesnotexist', 'abbr')
|
25
25
|
expect do
|
26
26
|
expect(@session).to have_none_of_selectors('abbr', 'p a#foo')
|
27
|
-
end.to raise_error
|
27
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'should respect scopes' do
|
@@ -32,7 +32,7 @@ Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
|
32
32
|
@session.within "//p[@id='first']" do
|
33
33
|
expect do
|
34
34
|
expect(@session).to have_none_of_selectors(".//a[@id='foo']")
|
35
|
-
end.to raise_error
|
35
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
36
36
|
expect(@session).to have_none_of_selectors(".//a[@id='red']")
|
37
37
|
end
|
38
38
|
end
|
@@ -41,7 +41,7 @@ Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
|
41
41
|
el = @session.find "//p[@id='first']"
|
42
42
|
expect do
|
43
43
|
expect(el).to have_none_of_selectors(".//a[@id='foo']")
|
44
|
-
end.to raise_error
|
44
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
45
45
|
expect(el).to have_none_of_selectors(".//a[@id='red']")
|
46
46
|
end
|
47
47
|
end
|
@@ -50,14 +50,14 @@ Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
|
50
50
|
it 'should apply the options to all locators' do
|
51
51
|
expect do
|
52
52
|
expect(@session).to have_none_of_selectors('//p//a', text: 'Redirect')
|
53
|
-
end.to raise_error
|
53
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
54
54
|
expect(@session).to have_none_of_selectors('//p', text: 'Doesnotexist')
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should discard all matches where the given regexp is matched' do
|
58
58
|
expect do
|
59
59
|
expect(@session).to have_none_of_selectors('//p//a', text: /re[dab]i/i, count: 1)
|
60
|
-
end.to raise_error
|
60
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
61
61
|
expect(@session).to have_none_of_selectors('//p//a', text: /Red$/)
|
62
62
|
end
|
63
63
|
end
|
@@ -179,10 +179,16 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
it 'should raise an error if an invalid option is passed' do
|
183
|
+
expect do
|
184
|
+
expect(@session).to have_select('form_languages', invalid: true)
|
185
|
+
end.to raise_error(ArgumentError, 'Invalid option(s) :invalid, should be one of :above, :below, :left_of, :right_of, :near, :count, :minimum, :maximum, :between, :text, :id, :class, :style, :visible, :obscured, :exact, :exact_text, :normalize_ws, :match, :wait, :filter_set, :focused, :disabled, :name, :placeholder, :options, :enabled_options, :disabled_options, :selected, :with_selected, :multiple, :with_options')
|
186
|
+
end
|
187
|
+
|
182
188
|
it 'should support locator-less usage' do
|
183
|
-
expect(@session.has_select?(with_options: %w[Norway Sweden])).to
|
189
|
+
expect(@session.has_select?(with_options: %w[Norway Sweden])).to be true
|
184
190
|
expect(@session).to have_select(with_options: ['London'])
|
185
|
-
expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to
|
191
|
+
expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to be true
|
186
192
|
expect(@session).to have_select(with_selected: ['Briefs'])
|
187
193
|
end
|
188
194
|
end
|
@@ -302,9 +308,9 @@ Capybara::SpecHelper.spec '#has_no_select?' do
|
|
302
308
|
end
|
303
309
|
|
304
310
|
it 'should support locator-less usage' do
|
305
|
-
expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to
|
311
|
+
expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to be true
|
306
312
|
expect(@session).to have_no_select(with_options: ['New London'])
|
307
|
-
expect(@session.has_no_select?(id: 'form_underwear', with_selected: ['Boxers'])).to
|
313
|
+
expect(@session.has_no_select?(id: 'form_underwear', with_selected: ['Boxers'])).to be true
|
308
314
|
expect(@session).to have_no_select(id: 'form_underwear', with_selected: %w[Commando Boxers])
|
309
315
|
end
|
310
316
|
end
|
@@ -117,6 +117,21 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|
117
117
|
expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test One', exact_text: false)
|
118
118
|
expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test', exact_text: false)
|
119
119
|
end
|
120
|
+
|
121
|
+
it 'should warn if text option is a regexp that it is ignoring exact_text' do
|
122
|
+
allow(Capybara::Helpers).to receive(:warn)
|
123
|
+
expect(@session).to have_selector(:id, 'h2one', text: /Class Test/, exact_text: true)
|
124
|
+
expect(Capybara::Helpers).to have_received(:warn).with(/'exact_text' option is not supported/)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'regexp' do
|
129
|
+
it 'should only match when it fully matches' do
|
130
|
+
expect(@session).to have_selector(:id, 'h2one', exact_text: /Header Class Test One/)
|
131
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Header Class Test/)
|
132
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test One/)
|
133
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test/)
|
134
|
+
end
|
120
135
|
end
|
121
136
|
end
|
122
137
|
|
@@ -19,12 +19,17 @@ Capybara::SpecHelper.spec '#has_table?' do
|
|
19
19
|
])
|
20
20
|
end
|
21
21
|
|
22
|
-
it 'should accept rows with partial column header
|
22
|
+
it 'should accept rows with partial column header hashes' do
|
23
23
|
expect(@session).to have_table('Horizontal Headers', with_rows:
|
24
24
|
[
|
25
25
|
{ 'First Name' => 'Thomas' },
|
26
26
|
{ 'Last Name' => 'Sawayn', 'City' => 'West Trinidad' }
|
27
27
|
])
|
28
|
+
|
29
|
+
expect(@session).not_to have_table('Horizontal Headers', with_rows:
|
30
|
+
[
|
31
|
+
{ 'Unmatched Header' => 'Thomas' }
|
32
|
+
])
|
28
33
|
end
|
29
34
|
|
30
35
|
it 'should accept rows with array of cell values' do
|
@@ -103,6 +108,11 @@ Capybara::SpecHelper.spec '#has_table?' do
|
|
103
108
|
{ 'First Name' => 'Danilo', 'Last Name' => 'Walpole', 'City' => 'Johnsonville' },
|
104
109
|
{ 'Last Name' => 'Sawayn', 'City' => 'West Trinidad' }
|
105
110
|
])
|
111
|
+
|
112
|
+
expect(@session).not_to have_table('Vertical Headers', with_cols:
|
113
|
+
[
|
114
|
+
{ 'Unmatched Header' => 'Thomas' }
|
115
|
+
])
|
106
116
|
end
|
107
117
|
|
108
118
|
it 'should be false if the table is not on the page' do
|
@@ -113,10 +123,11 @@ Capybara::SpecHelper.spec '#has_table?' do
|
|
113
123
|
expect(@session.find(:table, 'Horizontal Headers')).to have_selector(:table_row, 'First Name' => 'Thomas', 'Last Name' => 'Walpole')
|
114
124
|
expect(@session.find(:table, 'Horizontal Headers')).to have_selector(:table_row, 'Last Name' => 'Walpole')
|
115
125
|
expect(@session.find(:table, 'Horizontal Headers')).not_to have_selector(:table_row, 'First Name' => 'Walpole')
|
126
|
+
expect(@session.find(:table, 'Horizontal Headers')).not_to have_selector(:table_row, 'Unmatched Header' => 'Thomas')
|
116
127
|
end
|
117
128
|
|
118
129
|
it 'should find row by cell values' do
|
119
|
-
expect(@session.find(:table, 'Horizontal Headers')).to have_selector(:table_row, %w[Thomas Walpole])
|
130
|
+
expect(@session.find(:table, 'Horizontal Headers')).to have_selector(:table_row, %w[Thomas Walpole Oceanside])
|
120
131
|
expect(@session.find(:table, 'Horizontal Headers')).not_to have_selector(:table_row, %w[Walpole Thomas])
|
121
132
|
expect(@session.find(:table, 'Horizontal Headers')).not_to have_selector(:table_row, %w[Other])
|
122
133
|
end
|
@@ -127,11 +127,7 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
127
127
|
def to_hash; { value: 'Other hash' } end
|
128
128
|
end.new
|
129
129
|
@session.visit('/with_html')
|
130
|
-
|
131
|
-
expect(@session).to have_text(:visible, with_to_hash, **{})
|
132
|
-
else
|
133
|
-
expect(@session).to have_text(:visible, with_to_hash, {})
|
134
|
-
end
|
130
|
+
expect(@session).to have_text(:visible, with_to_hash, **{})
|
135
131
|
end
|
136
132
|
end
|
137
133
|
|
@@ -157,16 +153,12 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
157
153
|
expect(@session).to have_text(42)
|
158
154
|
end
|
159
155
|
|
160
|
-
it 'should be true when passed nil' do
|
156
|
+
it 'should be true when passed nil, and warn about it' do
|
161
157
|
# nil is converted to '' when to_s is invoked
|
162
158
|
@session.visit('/with_html')
|
163
|
-
expect
|
164
|
-
|
165
|
-
|
166
|
-
it 'should warn when passed nil' do
|
167
|
-
@session.visit('/with_html')
|
168
|
-
expect_any_instance_of(Kernel).to receive(:warn).with(/Checking for expected text of nil is confusing/) # rubocop:disable RSpec/AnyInstance
|
169
|
-
expect(@session).to have_text(nil)
|
159
|
+
expect do
|
160
|
+
expect(@session).to have_text(nil)
|
161
|
+
end.to output(/Checking for expected text of nil is confusing/).to_stderr
|
170
162
|
end
|
171
163
|
|
172
164
|
it 'should wait for text to appear', requires: [:js] do
|
@@ -356,7 +348,7 @@ Capybara::SpecHelper.spec '#has_no_text?' do
|
|
356
348
|
expect(@session).to have_no_text(/xxxxyzzz/)
|
357
349
|
end
|
358
350
|
|
359
|
-
it 'should be false if the text in the page
|
351
|
+
it 'should be false if the text in the page matches given regexp' do
|
360
352
|
@session.visit('/with_html')
|
361
353
|
expect(@session).not_to have_no_text(/Lorem/)
|
362
354
|
end
|
@@ -23,6 +23,7 @@ Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do
|
|
23
23
|
expect(@session.find(:css, '#first').matches_style?(display: /^in/)).to be false
|
24
24
|
end
|
25
25
|
|
26
|
+
# rubocop:disable Capybara/MatchStyle
|
26
27
|
it 'deprecated has_style?' do
|
27
28
|
expect { have_style(display: /^bl/) }.to \
|
28
29
|
output(/have_style is deprecated/).to_stderr
|
@@ -32,4 +33,5 @@ Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do
|
|
32
33
|
el.has_style?('display' => /^bl/)
|
33
34
|
expect(Capybara::Helpers).to have_received(:warn)
|
34
35
|
end
|
36
|
+
# rubocop:enable Capybara/MatchStyle
|
35
37
|
end
|
@@ -157,6 +157,18 @@ Capybara::SpecHelper.spec 'node' do
|
|
157
157
|
expect(@session.find(:css, '#existing_content_editable_child_parent').text).to eq("Some content\nWYSIWYG")
|
158
158
|
end
|
159
159
|
end
|
160
|
+
|
161
|
+
it 'should submit single text input forms if ended with \n' do
|
162
|
+
@session.visit('/form')
|
163
|
+
@session.find(:css, '#single_input').set("my entry\n")
|
164
|
+
expect(extract_results(@session)['single_input']).to eq('my entry')
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should not submit single text input forms if ended with \n and has multiple values' do
|
168
|
+
@session.visit('/form')
|
169
|
+
@session.find(:css, '#two_input_1').set("my entry\n")
|
170
|
+
expect(@session.find(:css, '#two_input_1').value).to eq("my entry\n").or(eq 'my entry')
|
171
|
+
end
|
160
172
|
end
|
161
173
|
|
162
174
|
describe '#tag_name' do
|
@@ -651,6 +663,16 @@ Capybara::SpecHelper.spec 'node' do
|
|
651
663
|
expect(target).to have_text(%r{^HTML5 Dropped string: text/plain drag_html5-#{key}$}m, exact: true)
|
652
664
|
end
|
653
665
|
end
|
666
|
+
|
667
|
+
it 'should trigger a dragenter event, before the first dragover event' do
|
668
|
+
@session.visit('/with_js')
|
669
|
+
element = @session.find('//div[@id="drag_html5"]')
|
670
|
+
target = @session.find('//div[@id="drop_html5"]')
|
671
|
+
element.drag_to(target)
|
672
|
+
|
673
|
+
# Events are listed in reverse chronological order
|
674
|
+
expect(@session).to have_text(/DragOver.*DragEnter/m)
|
675
|
+
end
|
654
676
|
end
|
655
677
|
end
|
656
678
|
|
@@ -775,6 +797,7 @@ Capybara::SpecHelper.spec 'node' do
|
|
775
797
|
end
|
776
798
|
|
777
799
|
it 'should allow to adjust the click offset', requires: [:js] do
|
800
|
+
Capybara.w3c_click_offset = false
|
778
801
|
@session.visit('with_js')
|
779
802
|
@session.find(:css, '#click-test').click(x: 5, y: 5)
|
780
803
|
link = @session.find(:link, 'has-been-clicked')
|
@@ -901,6 +924,7 @@ Capybara::SpecHelper.spec 'node' do
|
|
901
924
|
end
|
902
925
|
|
903
926
|
it 'should allow to adjust the offset', requires: [:js] do
|
927
|
+
Capybara.w3c_click_offset = false
|
904
928
|
@session.visit('with_js')
|
905
929
|
@session.find(:css, '#click-test').double_click(x: 10, y: 5)
|
906
930
|
link = @session.find(:link, 'has-been-double-clicked')
|
@@ -987,6 +1011,7 @@ Capybara::SpecHelper.spec 'node' do
|
|
987
1011
|
end
|
988
1012
|
|
989
1013
|
it 'should allow to adjust the offset', requires: [:js] do
|
1014
|
+
Capybara.w3c_click_offset = false
|
990
1015
|
@session.visit('with_js')
|
991
1016
|
@session.find(:css, '#click-test').right_click(x: 10, y: 10)
|
992
1017
|
link = @session.find(:link, 'has-been-right-clicked')
|
@@ -1115,7 +1140,7 @@ Capybara::SpecHelper.spec 'node' do
|
|
1115
1140
|
end
|
1116
1141
|
|
1117
1142
|
describe '#evaluate_script', requires: %i[js es_args] do
|
1118
|
-
it 'should evaluate the given script in the context of the element and
|
1143
|
+
it 'should evaluate the given script in the context of the element and return whatever it produces' do
|
1119
1144
|
@session.visit('/with_js')
|
1120
1145
|
el = @session.find(:css, '#with_change_event')
|
1121
1146
|
expect(el.evaluate_script('this.value')).to eq('default value')
|
@@ -1176,6 +1201,68 @@ Capybara::SpecHelper.spec 'node' do
|
|
1176
1201
|
end
|
1177
1202
|
end
|
1178
1203
|
|
1204
|
+
describe '#shadow_root', requires: %i[js] do
|
1205
|
+
it 'should get the shadow root' do
|
1206
|
+
@session.visit('/with_shadow')
|
1207
|
+
expect do
|
1208
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1209
|
+
expect(shadow_root).to be_a(Capybara::Node::Element)
|
1210
|
+
end.not_to raise_error
|
1211
|
+
end
|
1212
|
+
|
1213
|
+
it 'should find elements inside the shadow dom using CSS' do
|
1214
|
+
@session.visit('/with_shadow')
|
1215
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1216
|
+
expect(shadow_root).to have_css('#shadow_content', text: 'some text')
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
it 'should find nested shadow roots' do
|
1220
|
+
@session.visit('/with_shadow')
|
1221
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1222
|
+
nested_shadow_root = shadow_root.find(:css, '#nested_shadow_host').shadow_root
|
1223
|
+
expect(nested_shadow_root).to have_css('#nested_shadow_content', text: 'nested text')
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
it 'should click on elements' do
|
1227
|
+
@session.visit('/with_shadow')
|
1228
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1229
|
+
checkbox = shadow_root.find(:css, 'input[type="checkbox"]')
|
1230
|
+
expect(checkbox).not_to be_checked
|
1231
|
+
checkbox.click
|
1232
|
+
expect(checkbox).to be_checked
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
it 'should use convenience methods once moved to a descendant of the shadow root' do
|
1236
|
+
@session.visit('/with_shadow')
|
1237
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1238
|
+
descendant = shadow_root.find(:css, '#controls_wrapper')
|
1239
|
+
expect do
|
1240
|
+
descendant.check('shadow_checkbox')
|
1241
|
+
end.not_to raise_error
|
1242
|
+
expect(descendant).to have_checked_field('shadow_checkbox')
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
it 'should produce error messages when failing' do
|
1246
|
+
@session.visit('/with_shadow')
|
1247
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1248
|
+
expect do
|
1249
|
+
expect(shadow_root).to have_css('#shadow_content', text: 'Not in the document')
|
1250
|
+
end.to raise_error(/tag="ShadowRoot"/)
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
it 'should get visible text' do
|
1254
|
+
@session.visit('/with_shadow')
|
1255
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1256
|
+
expect(shadow_root).to have_text('some text scroll.html')
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it 'should get all text' do
|
1260
|
+
@session.visit('/with_shadow')
|
1261
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1262
|
+
expect(shadow_root).to have_text(:all, 'some text scroll.html')
|
1263
|
+
end
|
1264
|
+
end
|
1265
|
+
|
1179
1266
|
describe '#reload', requires: [:js] do
|
1180
1267
|
it 'should reload elements found via ancestor with CSS' do
|
1181
1268
|
@session.visit('/with_js')
|
@@ -34,6 +34,6 @@ Capybara::SpecHelper.spec '#to_capybara_node' do
|
|
34
34
|
end.to raise_error(/^expected to find css "#second" within #<Capybara::Node::Element/)
|
35
35
|
expect do
|
36
36
|
expect(para).to have_link(href: %r{/without_simple_html})
|
37
|
-
end.to raise_error(%r{^expected to find link
|
37
|
+
end.to raise_error(%r{^expected to find link with href matching /\\/without_simple_html/ within #<Capybara::Node::Element})
|
38
38
|
end
|
39
39
|
end
|
@@ -95,6 +95,19 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
95
95
|
expect(@session.windows.size).to eq 1
|
96
96
|
end
|
97
97
|
|
98
|
+
it 'does not block opening a new window after a frame was switched to and not switched back', requires: [:windows] do
|
99
|
+
@session.visit('/with_iframe?id=test_iframe&url=/')
|
100
|
+
@session.switch_to_frame(@session.find(:frame, 'test_iframe'))
|
101
|
+
within_window_test = lambda do
|
102
|
+
@session.within_window(@session.open_new_window) do
|
103
|
+
@session.visit('/')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
expect(&within_window_test).to raise_error(Capybara::ScopeError)
|
107
|
+
@session.reset_session!
|
108
|
+
expect(&within_window_test).not_to raise_error
|
109
|
+
end
|
110
|
+
|
98
111
|
context 'When reuse_server == false' do
|
99
112
|
let!(:orig_reuse_server) { Capybara.reuse_server }
|
100
113
|
|
@@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
15
15
|
el = @session.find(:css, '#scroll')
|
16
16
|
@session.scroll_to(el, align: :bottom)
|
17
17
|
el_bottom = el.evaluate_script('this.getBoundingClientRect().bottom')
|
18
|
-
viewport_bottom = el.evaluate_script('document.
|
18
|
+
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
19
19
|
expect(el_bottom).to be_within(1).of(viewport_bottom)
|
20
20
|
end
|
21
21
|
|
@@ -23,7 +23,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
23
23
|
el = @session.find(:css, '#scroll')
|
24
24
|
@session.scroll_to(el, align: :center)
|
25
25
|
el_center = el.evaluate_script('(function(rect){return (rect.top + rect.bottom)/2})(this.getBoundingClientRect())')
|
26
|
-
viewport_bottom = el.evaluate_script('document.
|
26
|
+
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
27
27
|
expect(el_center).to be_within(2).of(viewport_bottom / 2)
|
28
28
|
end
|
29
29
|
|
@@ -35,13 +35,15 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
35
35
|
|
36
36
|
it 'can scroll the window to the vertical bottom' do
|
37
37
|
@session.scroll_to :bottom
|
38
|
-
max_scroll = @session.evaluate_script('document.
|
39
|
-
|
38
|
+
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
39
|
+
scrolled_location_x, scrolled_location_y = @session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')
|
40
|
+
expect(scrolled_location_x).to be_within(0.5).of(0)
|
41
|
+
expect(scrolled_location_y).to be_within(0.5).of(max_scroll)
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'can scroll the window to the vertical center' do
|
43
45
|
@session.scroll_to :center
|
44
|
-
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.
|
46
|
+
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
45
47
|
expect(@session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')).to eq [0, max_scroll / 2]
|
46
48
|
end
|
47
49
|
|