capybara 3.16.1 → 3.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +321 -0
- data/README.md +51 -60
- data/lib/capybara.rb +71 -114
- data/lib/capybara/config.rb +8 -5
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/node.rb +15 -3
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +5 -3
- data/lib/capybara/minitest.rb +242 -141
- data/lib/capybara/minitest/spec.rb +159 -90
- data/lib/capybara/node/actions.rb +85 -74
- data/lib/capybara/node/base.rb +4 -4
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +216 -117
- data/lib/capybara/node/finders.rb +65 -65
- data/lib/capybara/node/matchers.rb +228 -126
- data/lib/capybara/node/simple.rb +9 -4
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +296 -30
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +2 -2
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/queries/title_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +7 -2
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +1 -1
- data/lib/capybara/rack_test/node.rb +43 -7
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +36 -8
- data/lib/capybara/rspec/matcher_proxies.rb +6 -4
- data/lib/capybara/rspec/matchers.rb +100 -63
- data/lib/capybara/rspec/matchers/base.rb +23 -10
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +4 -4
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +2 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/selector.rb +219 -588
- data/lib/capybara/selector/builders/css_builder.rb +10 -6
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +4 -2
- data/lib/capybara/selector/definition.rb +277 -0
- data/lib/capybara/selector/definition/button.rb +52 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +27 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +54 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/filter_set.rb +13 -9
- data/lib/capybara/selector/filters/base.rb +11 -2
- data/lib/capybara/selector/filters/locator_filter.rb +13 -3
- data/lib/capybara/selector/regexp_disassembler.rb +9 -2
- data/lib/capybara/selector/selector.rb +43 -448
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +125 -56
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +73 -17
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +41 -2
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +14 -5
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +67 -45
- data/lib/capybara/selenium/extensions/html5_drag.rb +152 -36
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +227 -56
- data/lib/capybara/selenium/nodes/chrome_node.rb +93 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +37 -59
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +27 -54
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/server.rb +19 -3
- data/lib/capybara/server/animation_disabler.rb +2 -2
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/session.rb +124 -106
- data/lib/capybara/session/config.rb +12 -10
- data/lib/capybara/session/matchers.rb +6 -6
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +94 -5
- data/lib/capybara/spec/session/all_spec.rb +84 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -6
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +44 -1
- data/lib/capybara/spec/session/click_link_spec.rb +11 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +37 -2
- data/lib/capybara/spec/session/find_spec.rb +60 -6
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +35 -6
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +34 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +47 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +574 -16
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +5 -10
- data/lib/capybara/spec/session/selectors_spec.rb +24 -3
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +10 -9
- data/lib/capybara/spec/spec_helper.rb +7 -2
- data/lib/capybara/spec/test_app.rb +26 -21
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +25 -4
- data/lib/capybara/spec/views/frame_child.erb +2 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +9 -9
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_html.erb +28 -2
- data/lib/capybara/spec/views/with_js.erb +2 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +10 -10
- data/spec/basic_node_spec.rb +6 -6
- data/spec/capybara_spec.rb +28 -28
- data/spec/dsl_spec.rb +16 -3
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +12 -2
- data/spec/minitest_spec_spec.rb +56 -45
- data/spec/rack_test_spec.rb +25 -12
- data/spec/regexp_dissassembler_spec.rb +53 -39
- data/spec/result_spec.rb +50 -54
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/shared_spec_matchers.rb +78 -62
- data/spec/rspec_spec.rb +5 -5
- data/spec/sauce_spec_chrome.rb +1 -0
- data/spec/selector_spec.rb +26 -16
- data/spec/selenium_spec_chrome.rb +84 -5
- data/spec/selenium_spec_chrome_remote.rb +23 -8
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +16 -21
- data/spec/selenium_spec_firefox_remote.rb +4 -13
- data/spec/selenium_spec_ie.rb +23 -15
- data/spec/selenium_spec_safari.rb +17 -17
- data/spec/server_spec.rb +87 -42
- data/spec/session_spec.rb +11 -4
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +62 -72
- data/spec/spec_helper.rb +43 -5
- metadata +114 -16
@@ -24,7 +24,7 @@ Capybara::SpecHelper.spec '#first' do
|
|
24
24
|
|
25
25
|
it 'should accept an XPath instance' do
|
26
26
|
@session.visit('/form')
|
27
|
-
@xpath = Capybara::Selector
|
27
|
+
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
|
28
28
|
expect(@xpath).to be_a(::XPath::Union)
|
29
29
|
expect(@session.first(@xpath).value).to eq('John')
|
30
30
|
end
|
@@ -53,7 +53,20 @@ Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
|
|
53
53
|
@session.switch_to_frame frame
|
54
54
|
frame = @session.find(:frame, 'childFrame')
|
55
55
|
@session.switch_to_frame frame
|
56
|
-
@session.click_link 'Close Window'
|
56
|
+
@session.click_link 'Close Window Now'
|
57
|
+
@session.switch_to_frame :parent # Go back to parentFrame
|
58
|
+
expect(@session).to have_selector(:css, 'body#parentBody')
|
59
|
+
expect(@session).not_to have_selector(:css, '#childFrame')
|
60
|
+
@session.switch_to_frame :parent # Go back to top
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'works if the frame is closed with a slight delay', requires: %i[frames js] do
|
64
|
+
frame = @session.find(:frame, 'parentFrame')
|
65
|
+
@session.switch_to_frame frame
|
66
|
+
frame = @session.find(:frame, 'childFrame')
|
67
|
+
@session.switch_to_frame frame
|
68
|
+
@session.click_link 'Close Window Soon'
|
69
|
+
sleep 1
|
57
70
|
@session.switch_to_frame :parent # Go back to parentFrame
|
58
71
|
expect(@session).to have_selector(:css, 'body#parentBody')
|
59
72
|
expect(@session).not_to have_selector(:css, '#childFrame')
|
@@ -92,7 +92,18 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
|
92
92
|
it 'works if the frame is closed', requires: %i[frames js] do
|
93
93
|
@session.within_frame 'parentFrame' do
|
94
94
|
@session.within_frame 'childFrame' do
|
95
|
-
@session.click_link 'Close Window'
|
95
|
+
@session.click_link 'Close Window Now'
|
96
|
+
end
|
97
|
+
expect(@session).to have_selector(:css, 'body#parentBody')
|
98
|
+
expect(@session).not_to have_selector(:css, '#childFrame')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'works if the frame is closed with a slight delay', requires: %i[frames js] do
|
103
|
+
@session.within_frame 'parentFrame' do
|
104
|
+
@session.within_frame 'childFrame' do
|
105
|
+
@session.click_link 'Close Window Soon'
|
106
|
+
sleep 1
|
96
107
|
end
|
97
108
|
expect(@session).to have_selector(:css, 'body#parentBody')
|
98
109
|
expect(@session).not_to have_selector(:css, '#childFrame')
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#have_ancestor' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should assert an ancestor using the given locator' do
|
9
|
+
el = @session.find(:css, '#ancestor1')
|
10
|
+
expect(el).to have_ancestor(:css, '#ancestor2')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should assert an ancestor even if not parent' do
|
14
|
+
el = @session.find(:css, '#child')
|
15
|
+
expect(el).to have_ancestor(:css, '#ancestor3')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not raise an error if there are multiple matches' do
|
19
|
+
el = @session.find(:css, '#child')
|
20
|
+
expect(el).to have_ancestor(:css, 'div')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow counts to be specified' do
|
24
|
+
el = @session.find(:css, '#child')
|
25
|
+
|
26
|
+
expect do
|
27
|
+
expect(el).to have_ancestor(:css, 'div').once
|
28
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
29
|
+
|
30
|
+
expect(el).to have_ancestor(:css, 'div').exactly(3).times
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Capybara::SpecHelper.spec '#have_no_ancestor' do
|
35
|
+
before do
|
36
|
+
@session.visit('/with_html')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should assert no matching ancestor' do
|
40
|
+
el = @session.find(:css, '#ancestor1')
|
41
|
+
expect(el).to have_no_ancestor(:css, '#child')
|
42
|
+
expect(el).to have_no_ancestor(:css, '#ancestor1_sibiling')
|
43
|
+
expect(el).not_to have_ancestor(:css, '#child')
|
44
|
+
expect(el).not_to have_ancestor(:css, '#ancestor1_sibiling')
|
45
|
+
end
|
46
|
+
end
|
@@ -39,6 +39,14 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
39
39
|
expect(@session).to have_button('awe123', type: 'submit')
|
40
40
|
expect(@session).not_to have_button('awe123', type: 'reset')
|
41
41
|
end
|
42
|
+
|
43
|
+
it 'should be true for role=button when enable_aria_role: true' do
|
44
|
+
expect(@session).to have_button('ARIA button', enable_aria_role: true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should be false for role=button when enable_aria_role: false' do
|
48
|
+
expect(@session).not_to have_button('ARIA button', enable_aria_role: false)
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
Capybara::SpecHelper.spec '#has_no_button?' do
|
@@ -66,4 +74,12 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
66
74
|
it 'should be false for disabled buttons if disabled: false' do
|
67
75
|
expect(@session).to have_no_button('Disabled button', disabled: false)
|
68
76
|
end
|
77
|
+
|
78
|
+
it 'should be true for role=button when enable_aria_role: false' do
|
79
|
+
expect(@session).to have_no_button('ARIA button', enable_aria_role: false)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should be false for role=button when enable_aria_role: true' do
|
83
|
+
expect(@session).not_to have_no_button('ARIA button', enable_aria_role: true)
|
84
|
+
end
|
69
85
|
end
|
@@ -10,10 +10,11 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
10
10
|
expect(@session).to have_css('p a#foo')
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'should
|
13
|
+
it 'should warn when passed a symbol' do
|
14
14
|
# This was never a specifically accepted format but it has worked for a
|
15
|
-
# lot of versions.
|
16
|
-
# TODO:
|
15
|
+
# lot of versions.
|
16
|
+
# TODO: Remove in 4.0
|
17
|
+
expect_any_instance_of(Kernel).to receive(:warn) # rubocop:disable RSpec/AnyInstance
|
17
18
|
expect(@session).to have_css(:p)
|
18
19
|
end
|
19
20
|
|
@@ -146,7 +147,9 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
146
147
|
context 'with count' do
|
147
148
|
it 'should be true if the content occurs the given number of times' do
|
148
149
|
expect(@session).to have_css('p', count: 3)
|
150
|
+
expect(@session).to have_css('p').exactly(3).times
|
149
151
|
expect(@session).to have_css('p a#foo', count: 1)
|
152
|
+
expect(@session).to have_css('p a#foo').once
|
150
153
|
expect(@session).to have_css('p a.doesnotexist', count: 0)
|
151
154
|
expect(@session).to have_css('li', class: /guitar|drummer/, count: 4)
|
152
155
|
expect(@session).to have_css('li', id: /john|paul/, class: /guitar|drummer/, count: 2)
|
@@ -161,6 +164,7 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
161
164
|
|
162
165
|
it 'should be false if the content occurs a different number of times than the given' do
|
163
166
|
expect(@session).not_to have_css('p', count: 6)
|
167
|
+
expect(@session).not_to have_css('p').exactly(5).times
|
164
168
|
expect(@session).not_to have_css('p a#foo', count: 2)
|
165
169
|
expect(@session).not_to have_css('p a.doesnotexist', count: 1)
|
166
170
|
end
|
@@ -175,14 +179,16 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
175
179
|
it 'should be true when content occurs same or fewer times than given' do
|
176
180
|
expect(@session).to have_css('h2.head', maximum: 5) # edge case
|
177
181
|
expect(@session).to have_css('h2', maximum: 10)
|
182
|
+
expect(@session).to have_css('h2').at_most(10).times
|
178
183
|
expect(@session).to have_css('p a.doesnotexist', maximum: 1)
|
179
184
|
expect(@session).to have_css('p a.doesnotexist', maximum: 0)
|
180
185
|
end
|
181
186
|
|
182
187
|
it 'should be false when content occurs more times than given' do
|
183
|
-
expect(@session).not_to have_css('h2.head', maximum: 4) # edge case
|
184
|
-
expect(@session).not_to have_css('h2', maximum: 3)
|
185
|
-
expect(@session).not_to have_css('
|
188
|
+
# expect(@session).not_to have_css('h2.head', maximum: 4) # edge case
|
189
|
+
# expect(@session).not_to have_css('h2', maximum: 3)
|
190
|
+
expect(@session).not_to have_css('h2').at_most(3).times
|
191
|
+
# expect(@session).not_to have_css('p', maximum: 1)
|
186
192
|
end
|
187
193
|
|
188
194
|
it 'should coerce maximum to an integer' do
|
@@ -195,12 +201,14 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
195
201
|
it 'should be true when content occurs same or more times than given' do
|
196
202
|
expect(@session).to have_css('h2.head', minimum: 5) # edge case
|
197
203
|
expect(@session).to have_css('h2', minimum: 3)
|
204
|
+
expect(@session).to have_css('h2').at_least(2).times
|
198
205
|
expect(@session).to have_css('p a.doesnotexist', minimum: 0)
|
199
206
|
end
|
200
207
|
|
201
208
|
it 'should be false when content occurs fewer times than given' do
|
202
209
|
expect(@session).not_to have_css('h2.head', minimum: 6) # edge case
|
203
210
|
expect(@session).not_to have_css('h2', minimum: 8)
|
211
|
+
expect(@session).not_to have_css('h2').at_least(8).times
|
204
212
|
expect(@session).not_to have_css('p', minimum: 10)
|
205
213
|
expect(@session).not_to have_css('p a.doesnotexist', minimum: 1)
|
206
214
|
end
|
@@ -223,6 +231,27 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
223
231
|
end
|
224
232
|
end
|
225
233
|
|
234
|
+
context 'with spatial requirements', requires: [:spatial] do
|
235
|
+
before do
|
236
|
+
@session.visit('/spatial')
|
237
|
+
end
|
238
|
+
|
239
|
+
let :center do
|
240
|
+
@session.find(:css, '.center')
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'accepts spatial options' do
|
244
|
+
expect(@session).to have_css('div', above: center).thrice
|
245
|
+
expect(@session).to have_css('div', above: center, right_of: center).once
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'supports spatial sugar' do
|
249
|
+
expect(@session).to have_css('div').left_of(center).thrice
|
250
|
+
expect(@session).to have_css('div').below(center).right_of(center).once
|
251
|
+
expect(@session).to have_css('div').near(center).exactly(8).times
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
226
255
|
it 'should allow escapes in the CSS selector' do
|
227
256
|
expect(@session).to have_css('p[data-random="abc\\\\def"]')
|
228
257
|
expect(@session).to have_css("p[data-random='#{Capybara::Selector::CSS.escape('abc\def')}']")
|
@@ -81,7 +81,8 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should not raise an exception if the current_url is nil' do
|
84
|
-
|
84
|
+
allow(@session).to receive(:current_url).and_return(nil)
|
85
|
+
allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
|
85
86
|
|
86
87
|
# Without ignore_query option
|
87
88
|
expect do
|
@@ -121,16 +122,17 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|
121
122
|
end
|
122
123
|
|
123
124
|
it 'should not raise an exception if the current_url is nil' do
|
124
|
-
|
125
|
+
allow(@session).to receive(:current_url).and_return(nil)
|
126
|
+
allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
|
125
127
|
|
126
128
|
# Without ignore_query option
|
127
129
|
expect do
|
128
130
|
expect(@session).not_to have_current_path('/with_js')
|
129
|
-
end.
|
131
|
+
end.not_to raise_exception
|
130
132
|
|
131
133
|
# With ignore_query option
|
132
134
|
expect do
|
133
135
|
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
134
|
-
end.
|
136
|
+
end.not_to raise_exception
|
135
137
|
end
|
136
138
|
end
|
@@ -60,6 +60,22 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
context 'with validation message', requires: [:html_validation] do
|
64
|
+
it 'should accept a regexp' do
|
65
|
+
@session.fill_in('form_zipcode', with: '1234')
|
66
|
+
expect(@session).to have_field('form_zipcode', validation_message: /match the requested format/)
|
67
|
+
expect(@session).not_to have_field('form_zipcode', validation_message: /random/)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should accept a string' do
|
71
|
+
@session.fill_in('form_zipcode', with: '1234')
|
72
|
+
expect(@session).to have_field('form_zipcode', validation_message: 'Please match the requested format.')
|
73
|
+
expect(@session).not_to have_field('form_zipcode', validation_message: 'match the requested format.')
|
74
|
+
@session.fill_in('form_zipcode', with: '12345')
|
75
|
+
expect(@session).to have_field('form_zipcode', validation_message: '')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
63
79
|
context 'with type' do
|
64
80
|
it 'should be true if a field with the given type is on the page' do
|
65
81
|
expect(@session).to have_field('First Name', type: 'text')
|
@@ -93,6 +109,24 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
93
109
|
expect(@session).not_to have_field('Html5 Multiple Email', multiple: false)
|
94
110
|
end
|
95
111
|
end
|
112
|
+
|
113
|
+
context 'with valid', requires: [:js] do
|
114
|
+
it 'should be true if field is valid' do
|
115
|
+
@session.fill_in 'required', with: 'something'
|
116
|
+
@session.fill_in 'length', with: 'abcd'
|
117
|
+
|
118
|
+
expect(@session).to have_field('required', valid: true)
|
119
|
+
expect(@session).to have_field('length', valid: true)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should be false if field is invalid' do
|
123
|
+
expect(@session).not_to have_field('required', valid: true)
|
124
|
+
expect(@session).to have_field('required', valid: false)
|
125
|
+
|
126
|
+
@session.fill_in 'length', with: 'abc'
|
127
|
+
expect(@session).not_to have_field('length', valid: true)
|
128
|
+
end
|
129
|
+
end
|
96
130
|
end
|
97
131
|
|
98
132
|
Capybara::SpecHelper.spec '#has_no_field' do
|
@@ -63,7 +63,7 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should be true even when the selected option invisible, regardless of the select's visibility" do
|
66
|
-
expect(@session).to have_select('Icecream', visible:
|
66
|
+
expect(@session).to have_select('Icecream', visible: :hidden, selected: 'Chocolate')
|
67
67
|
expect(@session).to have_select('Sorbet', selected: 'Vanilla')
|
68
68
|
end
|
69
69
|
end
|
@@ -88,7 +88,7 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should be true even when the selected values are invisible, regardless of the select's visibility" do
|
91
|
-
expect(@session).to have_select('Dessert', visible:
|
91
|
+
expect(@session).to have_select('Dessert', visible: :hidden, with_options: %w[Pudding Tiramisu])
|
92
92
|
expect(@session).to have_select('Cake', with_selected: ['Chocolate Cake', 'Sponge Cake'])
|
93
93
|
end
|
94
94
|
|
@@ -113,7 +113,35 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should be true even when the options are invisible, if the select itself is invisible' do
|
116
|
-
expect(@session).to have_select('Icecream', visible:
|
116
|
+
expect(@session).to have_select('Icecream', visible: :hidden, options: %w[Chocolate Vanilla Strawberry])
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'with enabled options' do
|
121
|
+
it 'should be true if the listed options exist and are enabled' do
|
122
|
+
expect(@session).to have_select('form_title', enabled_options: %w[Mr Mrs Miss])
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should be false if the listed options do not exist' do
|
126
|
+
expect(@session).not_to have_select('form_title', enabled_options: ['Not there'])
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should be false if the listed option exists but is not enabled' do
|
130
|
+
expect(@session).not_to have_select('form_title', enabled_options: %w[Mr Mrs Miss Other])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'with disabled options' do
|
135
|
+
it 'should be true if the listed options exist and are disabled' do
|
136
|
+
expect(@session).to have_select('form_title', disabled_options: ['Other'])
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should be false if the listed options do not exist' do
|
140
|
+
expect(@session).not_to have_select('form_title', disabled_options: ['Not there'])
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should be false if the listed option exists but is not disabled' do
|
144
|
+
expect(@session).not_to have_select('form_title', disabled_options: %w[Other Mrs])
|
117
145
|
end
|
118
146
|
end
|
119
147
|
|
@@ -130,7 +158,7 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
130
158
|
end
|
131
159
|
|
132
160
|
it 'should be true even when the options are invisible, if the select itself is invisible' do
|
133
|
-
expect(@session).to have_select('Icecream', visible:
|
161
|
+
expect(@session).to have_select('Icecream', visible: :hidden, with_options: %w[Vanilla Strawberry])
|
134
162
|
end
|
135
163
|
end
|
136
164
|
|
@@ -61,12 +61,12 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should respect visibility setting' do
|
64
|
-
expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible:
|
65
|
-
expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible:
|
64
|
+
expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :all)
|
65
|
+
expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :visible)
|
66
66
|
Capybara.ignore_hidden_elements = false
|
67
|
-
expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible:
|
67
|
+
expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :all)
|
68
68
|
Capybara.visible_text_only = true
|
69
|
-
expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible:
|
69
|
+
expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :visible)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should discard all matches where the given regexp is not matched' do
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#have_sibling' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should assert a prior sibling element using the given locator' do
|
9
|
+
el = @session.find(:css, '#mid_sibling')
|
10
|
+
expect(el).to have_sibling(:css, '#pre_sibling')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should assert a following sibling element using the given locator' do
|
14
|
+
el = @session.find(:css, '#mid_sibling')
|
15
|
+
expect(el).to have_sibling(:css, '#post_sibling')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not raise an error if there are multiple matches' do
|
19
|
+
el = @session.find(:css, '#mid_sibling')
|
20
|
+
expect(el).to have_sibling(:css, 'div')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow counts to be specified' do
|
24
|
+
el = @session.find(:css, '#mid_sibling')
|
25
|
+
|
26
|
+
expect(el).to have_sibling(:css, 'div').exactly(2).times
|
27
|
+
expect do
|
28
|
+
expect(el).to have_sibling(:css, 'div').once
|
29
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Capybara::SpecHelper.spec '#have_no_sibling' do
|
34
|
+
before do
|
35
|
+
@session.visit('/with_html')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should assert no matching sibling' do
|
39
|
+
el = @session.find(:css, '#mid_sibling')
|
40
|
+
expect(el).to have_no_sibling(:css, '#not_a_sibling')
|
41
|
+
expect(el).not_to have_sibling(:css, '#not_a_sibling')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should raise if there are matching siblings' do
|
45
|
+
el = @session.find(:css, '#mid_sibling')
|
46
|
+
expect do
|
47
|
+
expect(el).to have_no_sibling(:css, '#pre_sibling')
|
48
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
49
|
+
end
|
50
|
+
end
|
@@ -143,10 +143,56 @@ Capybara::SpecHelper.spec '#has_no_table?' do
|
|
143
143
|
])
|
144
144
|
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
context 'using :with_cols' do
|
147
|
+
it 'should consider a single column' do
|
148
|
+
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
149
|
+
[
|
150
|
+
{ 'First Name' => 'Joe' }
|
151
|
+
])
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should be true even if the last column does exist' do
|
155
|
+
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
156
|
+
[
|
157
|
+
{
|
158
|
+
'First Name' => 'What?',
|
159
|
+
'What?' => 'Walpole',
|
160
|
+
'City' => 'Oceanside' # This line makes the example fail
|
161
|
+
}
|
162
|
+
])
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should be true if none of the columns exist' do
|
166
|
+
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
167
|
+
[
|
168
|
+
{
|
169
|
+
'First Name' => 'What?',
|
170
|
+
'What?' => 'Walpole',
|
171
|
+
'City' => 'What?'
|
172
|
+
}
|
173
|
+
])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should be true if the first column does match' do
|
177
|
+
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
178
|
+
[
|
179
|
+
{
|
180
|
+
'First Name' => 'Thomas',
|
181
|
+
'Last Name' => 'What',
|
182
|
+
'City' => 'What'
|
183
|
+
}
|
184
|
+
])
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should be true if none of the columns match' do
|
188
|
+
expect(@session).to have_no_table('Vertical Headers', with_cols:
|
189
|
+
[
|
190
|
+
{
|
191
|
+
'First Name' => 'What',
|
192
|
+
'Last Name' => 'What',
|
193
|
+
'City' => 'What'
|
194
|
+
}
|
195
|
+
])
|
196
|
+
end
|
151
197
|
end
|
152
198
|
end
|