capybara 3.3.1 → 3.4.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 +16 -0
- data/README.md +5 -7
- data/lib/capybara.rb +7 -6
- data/lib/capybara/config.rb +1 -1
- data/lib/capybara/dsl.rb +2 -2
- data/lib/capybara/helpers.rb +3 -3
- data/lib/capybara/minitest/spec.rb +3 -3
- data/lib/capybara/node/actions.rb +18 -18
- data/lib/capybara/node/base.rb +1 -1
- data/lib/capybara/node/element.rb +2 -2
- data/lib/capybara/node/finders.rb +6 -6
- data/lib/capybara/node/matchers.rb +5 -5
- data/lib/capybara/node/simple.rb +2 -2
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/base_query.rb +12 -11
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +39 -15
- data/lib/capybara/queries/sibling_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +7 -7
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +7 -7
- data/lib/capybara/rack_test/node.rb +16 -16
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/result.rb +8 -4
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matchers.rb +6 -6
- data/lib/capybara/selector.rb +106 -90
- data/lib/capybara/selector/css.rb +4 -4
- data/lib/capybara/selector/filter_set.rb +52 -8
- data/lib/capybara/selector/selector.rb +39 -15
- data/lib/capybara/selenium/driver.rb +10 -10
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -0
- data/lib/capybara/selenium/node.rb +9 -10
- data/lib/capybara/selenium/nodes/chrome_node.rb +18 -0
- data/lib/capybara/selenium/nodes/marionette_node.rb +32 -7
- data/lib/capybara/server.rb +3 -3
- data/lib/capybara/server/animation_disabler.rb +1 -1
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/session.rb +23 -19
- data/lib/capybara/session/config.rb +18 -3
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/accept_alert_spec.rb +10 -10
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
- data/lib/capybara/spec/session/all_spec.rb +33 -32
- data/lib/capybara/spec/session/ancestor_spec.rb +19 -19
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +38 -38
- data/lib/capybara/spec/session/assert_current_path_spec.rb +16 -16
- data/lib/capybara/spec/session/assert_selector_spec.rb +53 -53
- data/lib/capybara/spec/session/assert_style_spec.rb +3 -3
- data/lib/capybara/spec/session/assert_text_spec.rb +31 -30
- data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +51 -52
- data/lib/capybara/spec/session/body_spec.rb +6 -6
- data/lib/capybara/spec/session/check_spec.rb +52 -47
- data/lib/capybara/spec/session/choose_spec.rb +32 -32
- data/lib/capybara/spec/session/click_button_spec.rb +103 -103
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +24 -23
- data/lib/capybara/spec/session/click_link_spec.rb +49 -48
- data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
- data/lib/capybara/spec/session/current_url_spec.rb +26 -27
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
- data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
- data/lib/capybara/spec/session/element/match_css_spec.rb +10 -10
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +51 -51
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
- data/lib/capybara/spec/session/evaluate_script_spec.rb +15 -8
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -7
- data/lib/capybara/spec/session/fill_in_spec.rb +43 -42
- data/lib/capybara/spec/session/find_button_spec.rb +23 -23
- data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
- data/lib/capybara/spec/session/find_field_spec.rb +32 -30
- data/lib/capybara/spec/session/find_link_spec.rb +21 -21
- data/lib/capybara/spec/session/find_spec.rb +153 -135
- data/lib/capybara/spec/session/first_spec.rb +41 -41
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +17 -17
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +31 -17
- data/lib/capybara/spec/session/go_back_spec.rb +1 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_button_spec.rb +13 -13
- data/lib/capybara/spec/session/has_css_spec.rb +133 -131
- data/lib/capybara/spec/session/has_current_path_spec.rb +29 -29
- data/lib/capybara/spec/session/has_field_spec.rb +58 -58
- data/lib/capybara/spec/session/has_link_spec.rb +4 -4
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +24 -24
- data/lib/capybara/spec/session/has_select_spec.rb +43 -43
- data/lib/capybara/spec/session/has_selector_spec.rb +71 -71
- data/lib/capybara/spec/session/has_style_spec.rb +3 -3
- data/lib/capybara/spec/session/has_table_spec.rb +4 -4
- data/lib/capybara/spec/session/has_text_spec.rb +53 -52
- data/lib/capybara/spec/session/has_title_spec.rb +14 -14
- data/lib/capybara/spec/session/has_xpath_spec.rb +39 -38
- data/lib/capybara/spec/session/headers_spec.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +6 -6
- data/lib/capybara/spec/session/node_spec.rb +129 -123
- data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
- data/lib/capybara/spec/session/refresh_spec.rb +4 -7
- data/lib/capybara/spec/session/reset_session_spec.rb +28 -28
- data/lib/capybara/spec/session/response_code_spec.rb +1 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +37 -37
- data/lib/capybara/spec/session/save_screenshot_spec.rb +6 -6
- data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/select_spec.rb +81 -81
- data/lib/capybara/spec/session/selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/sibling_spec.rb +9 -9
- data/lib/capybara/spec/session/text_spec.rb +23 -23
- data/lib/capybara/spec/session/title_spec.rb +5 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +24 -20
- data/lib/capybara/spec/session/unselect_spec.rb +37 -37
- data/lib/capybara/spec/session/visit_spec.rb +48 -49
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -16
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -2
- data/lib/capybara/spec/session/window/window_spec.rb +4 -4
- data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
- data/lib/capybara/spec/session/within_spec.rb +41 -41
- data/lib/capybara/spec/spec_helper.rb +11 -9
- data/lib/capybara/spec/test_app.rb +18 -17
- data/lib/capybara/spec/views/form.erb +29 -31
- data/lib/capybara/spec/views/with_html.erb +2 -2
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +23 -23
- data/spec/capybara_spec.rb +20 -20
- data/spec/css_splitter_spec.rb +7 -7
- data/spec/dsl_spec.rb +37 -32
- data/spec/filter_set_spec.rb +4 -4
- 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 +4 -4
- data/spec/minitest_spec_spec.rb +23 -23
- data/spec/per_session_config_spec.rb +5 -5
- data/spec/rack_test_spec.rb +44 -44
- data/spec/result_spec.rb +14 -14
- data/spec/rspec/features_spec.rb +13 -13
- data/spec/rspec/scenarios_spec.rb +4 -4
- data/spec/rspec/shared_spec_matchers.rb +282 -281
- data/spec/rspec/views_spec.rb +3 -3
- data/spec/rspec_matchers_spec.rb +10 -10
- data/spec/rspec_spec.rb +29 -29
- data/spec/selector_spec.rb +64 -64
- data/spec/selenium_spec_chrome.rb +14 -22
- data/spec/selenium_spec_chrome_remote.rb +28 -8
- data/spec/selenium_spec_edge.rb +9 -4
- data/spec/selenium_spec_firefox_remote.rb +87 -0
- data/spec/selenium_spec_ie.rb +9 -4
- data/spec/selenium_spec_marionette.rb +42 -18
- data/spec/server_spec.rb +29 -27
- data/spec/session_spec.rb +17 -17
- data/spec/shared_selenium_session.rb +70 -52
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
@@ -1,118 +1,118 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Capybara::SpecHelper.spec
|
3
|
+
Capybara::SpecHelper.spec '#select' do
|
4
4
|
before do
|
5
5
|
@session.visit('/form')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should return value of the first option' do
|
9
9
|
expect(@session.find_field('Title').value).to eq('Mrs')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
@session.select(
|
12
|
+
it 'should return value of the selected option' do
|
13
|
+
@session.select('Miss', from: 'Title')
|
14
14
|
expect(@session.find_field('Title').value).to eq('Miss')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
@session.select(
|
17
|
+
it 'should allow selecting exact options where there are inexact matches', :exact_false do
|
18
|
+
@session.select('Mr', from: 'Title')
|
19
19
|
expect(@session.find_field('Title').value).to eq('Mr')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
@session.select(
|
22
|
+
it 'should allow selecting options where they are the only inexact match', :exact_false do
|
23
|
+
@session.select('Mis', from: 'Title')
|
24
24
|
expect(@session.find_field('Title').value).to eq('Miss')
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'should not allow selecting options where they are the only inexact match if `exact: true` is specified' do
|
28
28
|
sel = @session.find(:select, 'Title')
|
29
29
|
expect do
|
30
|
-
sel.select(
|
30
|
+
sel.select('Mis', exact: true)
|
31
31
|
end.to raise_error(Capybara::ElementNotFound)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'should not allow selecting an option if the match is ambiguous', :exact_false do
|
35
35
|
expect do
|
36
|
-
@session.select(
|
36
|
+
@session.select('M', from: 'Title')
|
37
37
|
end.to raise_error(Capybara::Ambiguous)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'should return the value attribute rather than content if present' do
|
41
41
|
expect(@session.find_field('Locale').value).to eq('en')
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
@session.select(
|
44
|
+
it 'should select an option from a select box by id' do
|
45
|
+
@session.select('Finish', from: 'form_locale')
|
46
46
|
@session.click_button('awesome')
|
47
47
|
expect(extract_results(@session)['locale']).to eq('fi')
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
@session.select(
|
50
|
+
it 'should select an option from a select box by label' do
|
51
|
+
@session.select('Finish', from: 'Locale')
|
52
52
|
@session.click_button('awesome')
|
53
53
|
expect(extract_results(@session)['locale']).to eq('fi')
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
@session.select(
|
56
|
+
it 'should select an option without giving a select box' do
|
57
|
+
@session.select('Swedish')
|
58
58
|
@session.click_button('awesome')
|
59
59
|
expect(extract_results(@session)['locale']).to eq('sv')
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'should escape quotes' do
|
63
63
|
@session.select("John's made-up language", from: 'Locale')
|
64
64
|
@session.click_button('awesome')
|
65
65
|
expect(extract_results(@session)['locale']).to eq('jo')
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
@session.select(
|
68
|
+
it 'should obey from' do
|
69
|
+
@session.select('Miss', from: 'Other title')
|
70
70
|
@session.click_button('awesome')
|
71
71
|
results = extract_results(@session)
|
72
|
-
expect(results['other_title']).to eq(
|
73
|
-
expect(results['title']).not_to eq(
|
72
|
+
expect(results['other_title']).to eq('Miss')
|
73
|
+
expect(results['title']).not_to eq('Miss')
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
@session.select(
|
76
|
+
it 'show match labels with preceding or trailing whitespace' do
|
77
|
+
@session.select('Lojban', from: 'Locale')
|
78
78
|
@session.click_button('awesome')
|
79
79
|
expect(extract_results(@session)['locale']).to eq('jbo')
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'casts to string' do
|
83
83
|
@session.select(:Miss, from: :Title)
|
84
84
|
expect(@session.find_field('Title').value).to eq('Miss')
|
85
85
|
end
|
86
86
|
|
87
|
-
context
|
88
|
-
it
|
89
|
-
@session.select(
|
87
|
+
context 'input with datalist' do
|
88
|
+
it 'should select an option' do
|
89
|
+
@session.select('Audi', from: 'manufacturer')
|
90
90
|
@session.click_button('awesome')
|
91
91
|
expect(extract_results(@session)['manufacturer']).to eq('Audi')
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it 'should not find an input without a datalist' do
|
95
95
|
expect do
|
96
|
-
@session.select(
|
97
|
-
end.to raise_error(/Unable to find
|
96
|
+
@session.select('Thomas', from: 'form_first_name')
|
97
|
+
end.to raise_error(/Unable to find input box with datalist completion "form_first_name"/)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should not select an option that doesn't exist" do
|
101
101
|
expect do
|
102
|
-
@session.select(
|
102
|
+
@session.select('Tata', from: 'manufacturer')
|
103
103
|
end.to raise_error(/Unable to find datalist option "Tata"/)
|
104
104
|
end
|
105
105
|
|
106
|
-
it
|
106
|
+
it 'should not select a disabled option' do
|
107
107
|
expect do
|
108
|
-
@session.select(
|
108
|
+
@session.select('Mercedes', from: 'manufacturer')
|
109
109
|
end.to raise_error(/Unable to find datalist option "Mercedes"/)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
context "with a locator that doesn't exist" do
|
114
|
-
it
|
115
|
-
msg = /Unable to find
|
114
|
+
it 'should raise an error' do
|
115
|
+
msg = /Unable to find select box "does not exist"/
|
116
116
|
expect do
|
117
117
|
@session.select('foo', from: 'does not exist')
|
118
118
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -120,108 +120,108 @@ Capybara::SpecHelper.spec "#select" do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
context "with an option that doesn't exist" do
|
123
|
-
it
|
124
|
-
msg = /^Unable to find
|
123
|
+
it 'should raise an error' do
|
124
|
+
msg = /^Unable to find option "Does not Exist" within/
|
125
125
|
expect do
|
126
126
|
@session.select('Does not Exist', from: 'form_locale')
|
127
127
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
context
|
132
|
-
it
|
131
|
+
context 'on a disabled select' do
|
132
|
+
it 'should raise an error' do
|
133
133
|
expect do
|
134
134
|
@session.select('Should not see me', from: 'Disabled Select')
|
135
135
|
end.to raise_error(Capybara::ElementNotFound)
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
context
|
140
|
-
it
|
139
|
+
context 'on a disabled option' do
|
140
|
+
it 'should not select' do
|
141
141
|
@session.select('Other', from: 'form_title')
|
142
142
|
expect(@session.find_field('form_title').value).not_to eq 'Other'
|
143
143
|
end
|
144
144
|
|
145
|
-
it
|
145
|
+
it 'should warn' do
|
146
146
|
expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once
|
147
147
|
@session.select('Other', from: 'form_title')
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
context
|
152
|
-
it
|
151
|
+
context 'with multiple select' do
|
152
|
+
it 'should return an empty value' do
|
153
153
|
expect(@session.find_field('Languages').value).to eq([])
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
157
|
-
@session.select(
|
158
|
-
@session.select(
|
156
|
+
it 'should return value of the selected options' do
|
157
|
+
@session.select('Ruby', from: 'Languages')
|
158
|
+
@session.select('Javascript', from: 'Languages')
|
159
159
|
expect(@session.find_field('Languages').value).to include('Ruby', 'Javascript')
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
163
|
-
@session.select(
|
162
|
+
it 'should select one option' do
|
163
|
+
@session.select('Ruby', from: 'Languages')
|
164
164
|
@session.click_button('awesome')
|
165
165
|
expect(extract_results(@session)['languages']).to eq(['Ruby'])
|
166
166
|
end
|
167
167
|
|
168
|
-
it
|
169
|
-
@session.select(
|
170
|
-
@session.select(
|
168
|
+
it 'should select multiple options' do
|
169
|
+
@session.select('Ruby', from: 'Languages')
|
170
|
+
@session.select('Javascript', from: 'Languages')
|
171
171
|
@session.click_button('awesome')
|
172
172
|
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
173
173
|
end
|
174
174
|
|
175
|
-
it
|
176
|
-
@session.select(
|
177
|
-
@session.select(
|
178
|
-
@session.select(
|
175
|
+
it 'should remain selected if already selected' do
|
176
|
+
@session.select('Ruby', from: 'Languages')
|
177
|
+
@session.select('Javascript', from: 'Languages')
|
178
|
+
@session.select('Ruby', from: 'Languages')
|
179
179
|
@session.click_button('awesome')
|
180
180
|
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
181
181
|
end
|
182
182
|
|
183
|
-
it
|
183
|
+
it 'should return value attribute rather than content if present' do
|
184
184
|
expect(@session.find_field('Underwear').value).to include('thermal')
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
context
|
189
|
-
context
|
190
|
-
it
|
191
|
-
@session.select(
|
192
|
-
@session.click_button(
|
193
|
-
expect(extract_results(@session)[
|
188
|
+
context 'with :exact option' do
|
189
|
+
context 'when `false`' do
|
190
|
+
it 'can match select box approximately' do
|
191
|
+
@session.select('Finish', from: 'Loc', exact: false)
|
192
|
+
@session.click_button('awesome')
|
193
|
+
expect(extract_results(@session)['locale']).to eq('fi')
|
194
194
|
end
|
195
195
|
|
196
|
-
it
|
197
|
-
@session.select(
|
198
|
-
@session.click_button(
|
199
|
-
expect(extract_results(@session)[
|
196
|
+
it 'can match option approximately' do
|
197
|
+
@session.select('Fin', from: 'Locale', exact: false)
|
198
|
+
@session.click_button('awesome')
|
199
|
+
expect(extract_results(@session)['locale']).to eq('fi')
|
200
200
|
end
|
201
201
|
|
202
|
-
it
|
203
|
-
@session.select(
|
204
|
-
@session.click_button(
|
205
|
-
expect(extract_results(@session)[
|
202
|
+
it 'can match option approximately when :from not given' do
|
203
|
+
@session.select('made-up language', exact: false)
|
204
|
+
@session.click_button('awesome')
|
205
|
+
expect(extract_results(@session)['locale']).to eq('jo')
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
-
context
|
210
|
-
it
|
209
|
+
context 'when `true`' do
|
210
|
+
it 'can match select box approximately' do
|
211
211
|
expect do
|
212
|
-
@session.select(
|
212
|
+
@session.select('Finish', from: 'Loc', exact: true)
|
213
213
|
end.to raise_error(Capybara::ElementNotFound)
|
214
214
|
end
|
215
215
|
|
216
|
-
it
|
216
|
+
it 'can match option approximately' do
|
217
217
|
expect do
|
218
|
-
@session.select(
|
218
|
+
@session.select('Fin', from: 'Locale', exact: true)
|
219
219
|
end.to raise_error(Capybara::ElementNotFound)
|
220
220
|
end
|
221
221
|
|
222
|
-
it
|
222
|
+
it 'can match option approximately when :from not given' do
|
223
223
|
expect do
|
224
|
-
@session.select(
|
224
|
+
@session.select('made-up language', exact: true)
|
225
225
|
end.to raise_error(Capybara::ElementNotFound)
|
226
226
|
end
|
227
227
|
end
|
@@ -5,31 +5,31 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
5
5
|
@session.visit('/form')
|
6
6
|
end
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe ':label selector' do
|
9
|
+
it 'finds a label by text' do
|
10
10
|
expect(@session.find(:label, 'Customer Name').text).to eq 'Customer Name'
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'finds a label by for attribute string' do
|
14
14
|
expect(@session.find(:label, for: 'form_other_title')['for']).to eq 'form_other_title'
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'finds a label from nested input using :for filter with id string' do
|
18
18
|
expect(@session.find(:label, for: 'nested_label').text).to eq 'Nested Label'
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'finds a label from nested input using :for filter with element' do
|
22
22
|
input = @session.find(:id, 'nested_label')
|
23
23
|
expect(@session.find(:label, for: input).text).to eq 'Nested Label'
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'finds the label for an non-nested element when using :for filter' do
|
27
27
|
select = @session.find(:id, 'form_other_title')
|
28
28
|
expect(@session.find(:label, for: select)['for']).to eq 'form_other_title'
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
32
|
-
it
|
31
|
+
context 'with exact option' do
|
32
|
+
it 'matches substrings' do
|
33
33
|
expect(@session.find(:label, 'Customer Na', exact: false).text).to eq 'Customer Name'
|
34
34
|
end
|
35
35
|
|
@@ -39,26 +39,26 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
44
|
-
expect(@session.find(:field, id: 'customer_email').value).to eq
|
42
|
+
describe 'field selectors' do
|
43
|
+
it 'can find specifically by id' do
|
44
|
+
expect(@session.find(:field, id: 'customer_email').value).to eq 'ben@ben.com'
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq
|
47
|
+
it 'can find specifically by name' do
|
48
|
+
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq 'form_other_title'
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq
|
51
|
+
it 'can find specifically by placeholder' do
|
52
|
+
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq 'form_first_name'
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'can find by type' do
|
56
56
|
expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
|
57
57
|
expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
|
58
58
|
expect(@session.find(:field, 'Confusion', type: 'textarea')['id']).to eq 'confusion_textarea'
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'can find by class' do
|
62
62
|
expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
|
63
63
|
expect(@session).to have_selector(:field, class: 'confusion', count: 3)
|
64
64
|
expect(@session.find(:field, class: ['confusion', 'confusion-textarea'])['id']).to eq 'confusion_textarea'
|
@@ -9,31 +9,31 @@ Capybara::SpecHelper.spec '#sibling' do
|
|
9
9
|
Capybara::Selector.remove(:monkey)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should find a prior sibling element using the given locator' do
|
13
13
|
el = @session.find(:css, '#mid_sibling')
|
14
14
|
expect(el.sibling('//div[@data-pre]')[:id]).to eq('pre_sibling')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should find a following sibling element using the given locator' do
|
18
18
|
el = @session.find(:css, '#mid_sibling')
|
19
19
|
expect(el.sibling('//div[@data-post]')[:id]).to eq('post_sibling')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should raise an error if there are multiple matches' do
|
23
23
|
el = @session.find(:css, '#mid_sibling')
|
24
24
|
expect { el.sibling('//div') }.to raise_error(Capybara::Ambiguous)
|
25
25
|
end
|
26
26
|
|
27
|
-
context
|
28
|
-
it
|
27
|
+
context 'with css selectors' do
|
28
|
+
it 'should find the first element using the given locator' do
|
29
29
|
el = @session.find(:css, '#mid_sibling')
|
30
30
|
expect(el.sibling(:css, '#pre_sibling')).to have_text('Pre Sibling')
|
31
31
|
expect(el.sibling(:css, '#post_sibling')).to have_text('Post Sibling')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
36
|
-
it
|
35
|
+
context 'with custom selector' do
|
36
|
+
it 'should use the custom selector' do
|
37
37
|
Capybara.add_selector(:data_attribute) do
|
38
38
|
xpath { |attr| ".//*[@data-#{attr}]" }
|
39
39
|
end
|
@@ -43,10 +43,10 @@ Capybara::SpecHelper.spec '#sibling' do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'should raise ElementNotFound with a useful default message if nothing was found' do
|
47
47
|
el = @session.find(:css, '#child')
|
48
48
|
expect do
|
49
49
|
el.sibling(:xpath, '//div[@id="nosuchthing"]')
|
50
|
-
end.to raise_error(Capybara::ElementNotFound,
|
50
|
+
end.to raise_error(Capybara::ElementNotFound, 'Unable to find xpath "//div[@id=\\"nosuchthing\\"]" that is a sibling of visible css "#child"')
|
51
51
|
end
|
52
52
|
end
|
@@ -1,73 +1,73 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#text' do
|
4
|
-
it
|
4
|
+
it 'should print the text of the page' do
|
5
5
|
@session.visit('/with_simple_html')
|
6
6
|
expect(@session.text).to eq('Bar')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'ignores invisible text by default' do
|
10
10
|
@session.visit('/with_html')
|
11
|
-
expect(@session.find(:id,
|
11
|
+
expect(@session.find(:id, 'hidden-text').text).to eq('Some of this text is')
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'shows invisible text if `:all` given' do
|
15
15
|
@session.visit('/with_html')
|
16
|
-
expect(@session.find(:id,
|
16
|
+
expect(@session.find(:id, 'hidden-text').text(:all)).to eq('Some of this text is hidden!')
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'ignores invisible text if `:visible` given' do
|
20
20
|
Capybara.ignore_hidden_elements = false
|
21
21
|
@session.visit('/with_html')
|
22
|
-
expect(@session.find(:id,
|
22
|
+
expect(@session.find(:id, 'hidden-text').text(:visible)).to eq('Some of this text is')
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'ignores invisible text if `Capybara.ignore_hidden_elements = true`' do
|
26
26
|
@session.visit('/with_html')
|
27
|
-
expect(@session.find(:id,
|
27
|
+
expect(@session.find(:id, 'hidden-text').text).to eq('Some of this text is')
|
28
28
|
Capybara.ignore_hidden_elements = false
|
29
|
-
expect(@session.find(:id,
|
29
|
+
expect(@session.find(:id, 'hidden-text').text).to eq('Some of this text is hidden!')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'ignores invisible text if `Capybara.visible_text_only = true`' do
|
33
33
|
@session.visit('/with_html')
|
34
34
|
Capybara.visible_text_only = true
|
35
|
-
expect(@session.find(:id,
|
35
|
+
expect(@session.find(:id, 'hidden-text').text).to eq('Some of this text is')
|
36
36
|
Capybara.ignore_hidden_elements = false
|
37
|
-
expect(@session.find(:id,
|
37
|
+
expect(@session.find(:id, 'hidden-text').text).to eq('Some of this text is')
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'ignores invisible text if ancestor is invisible' do
|
41
41
|
@session.visit('/with_html')
|
42
|
-
expect(@session.find(:id,
|
42
|
+
expect(@session.find(:id, 'hidden_via_ancestor', visible: false).text).to eq('')
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
45
|
+
context 'with css as default selector' do
|
46
46
|
before { Capybara.default_selector = :css }
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'should print the text of the page' do
|
49
49
|
@session.visit('/with_simple_html')
|
50
50
|
expect(@session.text).to eq('Bar')
|
51
51
|
end
|
52
52
|
after { Capybara.default_selector = :xpath }
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'should be correctly normalized when visible' do
|
56
56
|
@session.visit('/with_html')
|
57
57
|
el = @session.find(:css, '#normalized')
|
58
58
|
expect(el.text).to eq "Some text\nMore text\nAnd more text\nEven more text on multiple lines"
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'should be a textContent with irrelevant whitespace collapsed when non-visible' do
|
62
62
|
@session.visit('/with_html')
|
63
63
|
el = @session.find(:css, '#non_visible_normalized', visible: false)
|
64
|
-
expect(el.text(:all)).to eq
|
64
|
+
expect(el.text(:all)).to eq 'Some textMore text And more text Even more text on multiple lines'
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'should strip correctly' do
|
68
68
|
@session.visit('/with_html')
|
69
69
|
el = @session.find(:css, '#ws')
|
70
|
-
expect(el.text).to eq
|
71
|
-
expect(el.text(:all)).to eq
|
70
|
+
expect(el.text).to eq ' '
|
71
|
+
expect(el.text(:all)).to eq ' '
|
72
72
|
end
|
73
73
|
end
|