capybara 2.9.0 → 2.10.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 +23 -0
- data/README.md +37 -30
- data/lib/capybara/node/actions.rb +18 -15
- data/lib/capybara/node/base.rb +2 -2
- data/lib/capybara/node/element.rb +1 -1
- data/lib/capybara/node/finders.rb +37 -32
- data/lib/capybara/node/matchers.rb +187 -171
- data/lib/capybara/queries/match_query.rb +1 -3
- data/lib/capybara/queries/selector_query.rb +48 -19
- data/lib/capybara/rack_test/driver.rb +3 -3
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/rspec/features.rb +1 -1
- data/lib/capybara/rspec/matchers.rb +31 -22
- data/lib/capybara/selector/css.rb +30 -0
- data/lib/capybara/selector/selector.rb +24 -1
- data/lib/capybara/selector.rb +22 -23
- data/lib/capybara/session.rb +4 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +4 -4
- data/lib/capybara/spec/session/accept_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/accept_prompt_spec.rb +5 -5
- data/lib/capybara/spec/session/all_spec.rb +27 -27
- data/lib/capybara/spec/session/assert_current_path.rb +2 -2
- data/lib/capybara/spec/session/assert_selector.rb +28 -28
- data/lib/capybara/spec/session/assert_text.rb +20 -20
- data/lib/capybara/spec/session/assert_title.rb +2 -2
- data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
- data/lib/capybara/spec/session/check_spec.rb +19 -10
- data/lib/capybara/spec/session/choose_spec.rb +4 -4
- data/lib/capybara/spec/session/click_button_spec.rb +18 -5
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +6 -6
- data/lib/capybara/spec/session/click_link_spec.rb +13 -13
- data/lib/capybara/spec/session/current_url_spec.rb +2 -2
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +21 -8
- data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
- data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -30
- data/lib/capybara/spec/session/find_button_spec.rb +5 -5
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -2
- data/lib/capybara/spec/session/find_field_spec.rb +11 -7
- data/lib/capybara/spec/session/find_link_spec.rb +2 -2
- data/lib/capybara/spec/session/find_spec.rb +57 -48
- data/lib/capybara/spec/session/first_spec.rb +9 -9
- 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_button_spec.rb +12 -12
- data/lib/capybara/spec/session/has_css_spec.rb +73 -73
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +78 -68
- data/lib/capybara/spec/session/has_link_spec.rb +8 -8
- data/lib/capybara/spec/session/has_select_spec.rb +70 -61
- data/lib/capybara/spec/session/has_selector_spec.rb +28 -28
- data/lib/capybara/spec/session/has_text_spec.rb +6 -6
- data/lib/capybara/spec/session/has_title_spec.rb +2 -2
- data/lib/capybara/spec/session/has_xpath_spec.rb +26 -26
- data/lib/capybara/spec/session/headers.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +3 -3
- data/lib/capybara/spec/session/node_spec.rb +15 -15
- data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
- data/lib/capybara/spec/session/response_code.rb +1 -1
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/screenshot_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +30 -30
- data/lib/capybara/spec/session/selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +14 -14
- data/lib/capybara/spec/session/visit_spec.rb +2 -2
- data/lib/capybara/spec/session/within_frame_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +6 -6
- data/lib/capybara/spec/spec_helper.rb +1 -1
- data/lib/capybara/spec/test_app.rb +1 -1
- data/lib/capybara/spec/views/form.erb +6 -3
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +2 -2
- data/spec/basic_node_spec.rb +5 -5
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +1 -1
- data/spec/rack_test_spec.rb +7 -7
- data/spec/rspec/matchers_spec.rb +6 -6
- data/spec/rspec_spec.rb +1 -1
- data/spec/selector_spec.rb +94 -3
- data/spec/selenium_firefox_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +1 -1
- data/spec/shared_selenium_session.rb +10 -10
- metadata +3 -2
|
@@ -14,15 +14,15 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "should find the first element using the given locator and options" do
|
|
17
|
-
expect(@session.find('//a', :
|
|
18
|
-
expect(@session.find(:css, 'a', :
|
|
17
|
+
expect(@session.find('//a', text: 'Redirect')[:id]).to eq('red')
|
|
18
|
+
expect(@session.find(:css, 'a', text: 'A link came first')[:title]).to eq('twas a fine link')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should raise an error if there are multiple matches" do
|
|
22
22
|
expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
it "should wait for asynchronous load", :
|
|
25
|
+
it "should wait for asynchronous load", requires: [:js] do
|
|
26
26
|
@session.visit('/with_js')
|
|
27
27
|
@session.click_link('Click me')
|
|
28
28
|
expect(@session.find(:css, "a#has-been-clicked").text).to include('Has been clicked')
|
|
@@ -34,12 +34,12 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
context "with :wait option", :
|
|
37
|
+
context "with :wait option", requires: [:js] do
|
|
38
38
|
it "should not wait for asynchronous load when `false` given" do
|
|
39
39
|
@session.visit('/with_js')
|
|
40
40
|
@session.click_link('Click me')
|
|
41
41
|
expect do
|
|
42
|
-
@session.find(:css, "a#has-been-clicked", :
|
|
42
|
+
@session.find(:css, "a#has-been-clicked", wait: false)
|
|
43
43
|
end.to raise_error(Capybara::ElementNotFound)
|
|
44
44
|
end
|
|
45
45
|
|
|
@@ -47,18 +47,18 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
47
47
|
@session.visit('/with_js')
|
|
48
48
|
@session.click_link('Slowly')
|
|
49
49
|
expect do
|
|
50
|
-
@session.find(:css, "a#slow-clicked", :
|
|
50
|
+
@session.find(:css, "a#slow-clicked", wait: 0.2)
|
|
51
51
|
end.to raise_error(Capybara::ElementNotFound)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "should find element if it appears before given wait duration" do
|
|
55
55
|
@session.visit('/with_js')
|
|
56
56
|
@session.click_link('Click me')
|
|
57
|
-
expect(@session.find(:css, "a#has-been-clicked", :
|
|
57
|
+
expect(@session.find(:css, "a#has-been-clicked", wait: 0.9).text).to include('Has been clicked')
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
context "with frozen time", :
|
|
61
|
+
context "with frozen time", requires: [:js] do
|
|
62
62
|
if defined?(Process::CLOCK_MONOTONIC)
|
|
63
63
|
it "will time out even if time is frozen" do
|
|
64
64
|
@session.visit('/with_js')
|
|
@@ -126,8 +126,8 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it "should find elements that match the filter" do
|
|
129
|
-
expect(@session.find(:beatle, 'Paul', :
|
|
130
|
-
expect(@session.find(:beatle, 'Ringo', :
|
|
129
|
+
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
|
130
|
+
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
it "ignores filter when it is not given" do
|
|
@@ -136,8 +136,8 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
it "should not find elements that don't match the filter" do
|
|
139
|
-
expect { @session.find(:beatle, 'John', :
|
|
140
|
-
expect { @session.find(:beatle, 'George', :
|
|
139
|
+
expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
|
140
|
+
expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
143
|
|
|
@@ -145,13 +145,13 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
145
145
|
before do
|
|
146
146
|
Capybara.add_selector(:beatle) do
|
|
147
147
|
xpath { |name| ".//li[contains(@class, 'beatle')][contains(text(), '#{name}')]" }
|
|
148
|
-
filter(:type, :
|
|
148
|
+
filter(:type, default: "drummer") { |node, type| node[:class].split(/\s+/).include?(type) }
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
it "should find elements that match the filter" do
|
|
153
|
-
expect(@session.find(:beatle, 'Paul', :
|
|
154
|
-
expect(@session.find(:beatle, 'Ringo', :
|
|
153
|
+
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
|
154
|
+
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
it "should use default value when filter is not given" do
|
|
@@ -160,8 +160,8 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
it "should not find elements that don't match the filter" do
|
|
163
|
-
expect { @session.find(:beatle, 'John', :
|
|
164
|
-
expect { @session.find(:beatle, 'George', :
|
|
163
|
+
expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
|
164
|
+
expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
|
|
@@ -216,15 +216,15 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
216
216
|
|
|
217
217
|
context "with :exact option" do
|
|
218
218
|
it "matches exactly when true" do
|
|
219
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :
|
|
219
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
|
|
220
220
|
expect do
|
|
221
|
-
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :
|
|
221
|
+
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
|
|
222
222
|
end.to raise_error(Capybara::ElementNotFound)
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
it "matches loosely when false" do
|
|
226
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :
|
|
227
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :
|
|
226
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
|
|
227
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
it "defaults to `Capybara.exact`" do
|
|
@@ -247,31 +247,31 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
247
247
|
context "when set to `one`" do
|
|
248
248
|
it "raises an error when multiple matches exist" do
|
|
249
249
|
expect do
|
|
250
|
-
@session.find(:css, ".multiple", :
|
|
250
|
+
@session.find(:css, ".multiple", match: :one)
|
|
251
251
|
end.to raise_error(Capybara::Ambiguous)
|
|
252
252
|
end
|
|
253
253
|
it "raises an error even if there the match is exact and the others are inexact" do
|
|
254
254
|
expect do
|
|
255
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :
|
|
255
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
|
|
256
256
|
end.to raise_error(Capybara::Ambiguous)
|
|
257
257
|
end
|
|
258
258
|
it "returns the element if there is only one" do
|
|
259
|
-
expect(@session.find(:css, ".singular", :
|
|
259
|
+
expect(@session.find(:css, ".singular", match: :one).text).to eq("singular")
|
|
260
260
|
end
|
|
261
261
|
it "raises an error if there is no match" do
|
|
262
262
|
expect do
|
|
263
|
-
@session.find(:css, ".does-not-exist", :
|
|
263
|
+
@session.find(:css, ".does-not-exist", match: :one)
|
|
264
264
|
end.to raise_error(Capybara::ElementNotFound)
|
|
265
265
|
end
|
|
266
266
|
end
|
|
267
267
|
|
|
268
268
|
context "when set to `first`" do
|
|
269
269
|
it "returns the first matched element" do
|
|
270
|
-
expect(@session.find(:css, ".multiple", :
|
|
270
|
+
expect(@session.find(:css, ".multiple", match: :first).text).to eq("multiple one")
|
|
271
271
|
end
|
|
272
272
|
it "raises an error if there is no match" do
|
|
273
273
|
expect do
|
|
274
|
-
@session.find(:css, ".does-not-exist", :
|
|
274
|
+
@session.find(:css, ".does-not-exist", match: :first)
|
|
275
275
|
end.to raise_error(Capybara::ElementNotFound)
|
|
276
276
|
end
|
|
277
277
|
end
|
|
@@ -280,25 +280,25 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
280
280
|
context "and `exact` set to `false`" do
|
|
281
281
|
it "raises an error when there are multiple exact matches" do
|
|
282
282
|
expect do
|
|
283
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :
|
|
283
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
|
|
284
284
|
end.to raise_error(Capybara::Ambiguous)
|
|
285
285
|
end
|
|
286
286
|
it "finds a single exact match when there also are inexact matches" do
|
|
287
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :
|
|
287
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
|
|
288
288
|
expect(result.text).to eq("almost singular")
|
|
289
289
|
end
|
|
290
290
|
it "raises an error when there are multiple inexact matches" do
|
|
291
291
|
expect do
|
|
292
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :
|
|
292
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
|
|
293
293
|
end.to raise_error(Capybara::Ambiguous)
|
|
294
294
|
end
|
|
295
295
|
it "finds a single inexact match" do
|
|
296
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :
|
|
296
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
|
|
297
297
|
expect(result.text).to eq("almost singular but not quite")
|
|
298
298
|
end
|
|
299
299
|
it "raises an error if there is no match" do
|
|
300
300
|
expect do
|
|
301
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :
|
|
301
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
|
|
302
302
|
end.to raise_error(Capybara::ElementNotFound)
|
|
303
303
|
end
|
|
304
304
|
end
|
|
@@ -306,26 +306,26 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
306
306
|
context "with `exact` set to `true`" do
|
|
307
307
|
it "raises an error when there are multiple exact matches" do
|
|
308
308
|
expect do
|
|
309
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :
|
|
309
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
|
|
310
310
|
end.to raise_error(Capybara::Ambiguous)
|
|
311
311
|
end
|
|
312
312
|
it "finds a single exact match when there also are inexact matches" do
|
|
313
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :
|
|
313
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
|
|
314
314
|
expect(result.text).to eq("almost singular")
|
|
315
315
|
end
|
|
316
316
|
it "raises an error when there are multiple inexact matches" do
|
|
317
317
|
expect do
|
|
318
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :
|
|
318
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
|
|
319
319
|
end.to raise_error(Capybara::ElementNotFound)
|
|
320
320
|
end
|
|
321
321
|
it "raises an error when there is a single inexact matches" do
|
|
322
322
|
expect do
|
|
323
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :
|
|
323
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
|
|
324
324
|
end.to raise_error(Capybara::ElementNotFound)
|
|
325
325
|
end
|
|
326
326
|
it "raises an error if there is no match" do
|
|
327
327
|
expect do
|
|
328
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :
|
|
328
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
|
|
329
329
|
end.to raise_error(Capybara::ElementNotFound)
|
|
330
330
|
end
|
|
331
331
|
end
|
|
@@ -334,50 +334,50 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
334
334
|
context "when set to `prefer_exact`" do
|
|
335
335
|
context "and `exact` set to `false`" do
|
|
336
336
|
it "picks the first one when there are multiple exact matches" do
|
|
337
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :
|
|
337
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
|
|
338
338
|
expect(result.text).to eq("multiple one")
|
|
339
339
|
end
|
|
340
340
|
it "finds a single exact match when there also are inexact matches" do
|
|
341
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :
|
|
341
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
|
|
342
342
|
expect(result.text).to eq("almost singular")
|
|
343
343
|
end
|
|
344
344
|
it "picks the first one when there are multiple inexact matches" do
|
|
345
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :
|
|
345
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
|
|
346
346
|
expect(result.text).to eq("almost singular but not quite")
|
|
347
347
|
end
|
|
348
348
|
it "finds a single inexact match" do
|
|
349
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :
|
|
349
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
|
|
350
350
|
expect(result.text).to eq("almost singular but not quite")
|
|
351
351
|
end
|
|
352
352
|
it "raises an error if there is no match" do
|
|
353
353
|
expect do
|
|
354
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :
|
|
354
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
|
|
355
355
|
end.to raise_error(Capybara::ElementNotFound)
|
|
356
356
|
end
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
context "with `exact` set to `true`" do
|
|
360
360
|
it "picks the first one when there are multiple exact matches" do
|
|
361
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :
|
|
361
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
|
|
362
362
|
expect(result.text).to eq("multiple one")
|
|
363
363
|
end
|
|
364
364
|
it "finds a single exact match when there also are inexact matches" do
|
|
365
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :
|
|
365
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
|
|
366
366
|
expect(result.text).to eq("almost singular")
|
|
367
367
|
end
|
|
368
368
|
it "raises an error if there are multiple inexact matches" do
|
|
369
369
|
expect do
|
|
370
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :
|
|
370
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
|
|
371
371
|
end.to raise_error(Capybara::ElementNotFound)
|
|
372
372
|
end
|
|
373
373
|
it "raises an error if there is a single inexact match" do
|
|
374
374
|
expect do
|
|
375
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :
|
|
375
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
|
|
376
376
|
end.to raise_error(Capybara::ElementNotFound)
|
|
377
377
|
end
|
|
378
378
|
it "raises an error if there is no match" do
|
|
379
379
|
expect do
|
|
380
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :
|
|
380
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
|
|
381
381
|
end.to raise_error(Capybara::ElementNotFound)
|
|
382
382
|
end
|
|
383
383
|
end
|
|
@@ -394,11 +394,15 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
394
394
|
|
|
395
395
|
it "raises an error when unknown option given" do
|
|
396
396
|
expect do
|
|
397
|
-
@session.find(:css, ".singular", :
|
|
397
|
+
@session.find(:css, ".singular", match: :schmoo)
|
|
398
398
|
end.to raise_error(ArgumentError)
|
|
399
399
|
end
|
|
400
400
|
end
|
|
401
401
|
|
|
402
|
+
it "supports a custom filter block" do
|
|
403
|
+
expect(@session.find(:css, 'input'){|node| node.disabled? }[:name]).to eq('disabled_text')
|
|
404
|
+
end
|
|
405
|
+
|
|
402
406
|
context "within a scope" do
|
|
403
407
|
before do
|
|
404
408
|
@session.visit('/with_scope')
|
|
@@ -416,4 +420,9 @@ Capybara::SpecHelper.spec '#find' do
|
|
|
416
420
|
end
|
|
417
421
|
end
|
|
418
422
|
end
|
|
423
|
+
|
|
424
|
+
it "should warn if selector type is unknown" do
|
|
425
|
+
expect_any_instance_of(Kernel).to receive(:warn).with(/^Unknown selector type/)
|
|
426
|
+
@session.find(:unknown, '//h1')
|
|
427
|
+
end
|
|
419
428
|
end
|
|
@@ -43,27 +43,27 @@ Capybara::SpecHelper.spec '#first' do
|
|
|
43
43
|
|
|
44
44
|
context "with visible filter" do
|
|
45
45
|
it "should only find visible nodes when true" do
|
|
46
|
-
expect(@session.first(:css, "a#invisible", :
|
|
46
|
+
expect(@session.first(:css, "a#invisible", visible: true)).to be_nil
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "should find nodes regardless of whether they are invisible when false" do
|
|
50
|
-
expect(@session.first(:css, "a#invisible", :
|
|
51
|
-
expect(@session.first(:css, "a#visible", :
|
|
50
|
+
expect(@session.first(:css, "a#invisible", visible: false)).not_to be_nil
|
|
51
|
+
expect(@session.first(:css, "a#visible", visible: false)).not_to be_nil
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "should find nodes regardless of whether they are invisible when :all" do
|
|
55
|
-
expect(@session.first(:css, "a#invisible", :
|
|
56
|
-
expect(@session.first(:css, "a#visible", :
|
|
55
|
+
expect(@session.first(:css, "a#invisible", visible: :all)).not_to be_nil
|
|
56
|
+
expect(@session.first(:css, "a#visible", visible: :all)).not_to be_nil
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "should find only hidden nodes when :hidden" do
|
|
60
|
-
expect(@session.first(:css, "a#invisible", :
|
|
61
|
-
expect(@session.first(:css, "a#visible", :
|
|
60
|
+
expect(@session.first(:css, "a#invisible", visible: :hidden)).not_to be_nil
|
|
61
|
+
expect(@session.first(:css, "a#visible", visible: :hidden)).to be_nil
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "should find only visible nodes when :visible" do
|
|
65
|
-
expect(@session.first(:css, "a#invisible", :
|
|
66
|
-
expect(@session.first(:css, "a#visible", :
|
|
65
|
+
expect(@session.first(:css, "a#invisible", visible: :visible)).to be_nil
|
|
66
|
+
expect(@session.first(:css, "a#visible", visible: :visible)).not_to be_nil
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "should default to Capybara.ignore_hidden_elements" do
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
Capybara::SpecHelper.spec '#go_back', :
|
|
2
|
+
Capybara::SpecHelper.spec '#go_back', requires: [:js] do
|
|
3
3
|
it "should fetch a response from the driver from the previous page" do
|
|
4
4
|
@session.visit('/')
|
|
5
5
|
expect(@session).to have_content('Hello world!')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
Capybara::SpecHelper.spec '#go_forward', :
|
|
2
|
+
Capybara::SpecHelper.spec '#go_forward', requires: [:js] do
|
|
3
3
|
it "should fetch a response from the driver from the previous page" do
|
|
4
4
|
@session.visit('/')
|
|
5
5
|
expect(@session).to have_content('Hello world!')
|
|
@@ -10,8 +10,8 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
|
10
10
|
expect(@session).to have_button(:'crap321')
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
it "should be true for disabled buttons if :
|
|
14
|
-
expect(@session).to have_button('Disabled button', :
|
|
13
|
+
it "should be true for disabled buttons if disabled: true" do
|
|
14
|
+
expect(@session).to have_button('Disabled button', disabled: true)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should be false if the given button is not on the page" do
|
|
@@ -22,16 +22,16 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
|
22
22
|
expect(@session).not_to have_button('Disabled button')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
it "should be false for disabled buttons if :
|
|
26
|
-
expect(@session).not_to have_button('Disabled button', :
|
|
25
|
+
it "should be false for disabled buttons if disabled: false" do
|
|
26
|
+
expect(@session).not_to have_button('Disabled button', disabled: false)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
it "should be true for disabled buttons if :
|
|
30
|
-
expect(@session).to have_button('Disabled button', :
|
|
29
|
+
it "should be true for disabled buttons if disabled: :all" do
|
|
30
|
+
expect(@session).to have_button('Disabled button', disabled: :all)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
it "should be true for enabled buttons if :
|
|
34
|
-
expect(@session).to have_button('med', :
|
|
33
|
+
it "should be true for enabled buttons if disabled: :all" do
|
|
34
|
+
expect(@session).to have_button('med', disabled: :all)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -45,8 +45,8 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
|
45
45
|
expect(@session).not_to have_no_button('crap321')
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
it "should be true for disabled buttons if :
|
|
49
|
-
expect(@session).not_to have_no_button('Disabled button', :
|
|
48
|
+
it "should be true for disabled buttons if disabled: true" do
|
|
49
|
+
expect(@session).not_to have_no_button('Disabled button', disabled: true)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "should be false if the given button is not on the page" do
|
|
@@ -57,7 +57,7 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
|
57
57
|
expect(@session).to have_no_button('Disabled button')
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
it "should be false for disabled buttons if :
|
|
61
|
-
expect(@session).to have_no_button('Disabled button', :
|
|
60
|
+
it "should be false for disabled buttons if disabled: false" do
|
|
61
|
+
expect(@session).to have_no_button('Disabled button', disabled: false)
|
|
62
62
|
end
|
|
63
63
|
end
|