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
@@ -5,25 +5,25 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
5
5
|
@session.visit('/form')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
expect(@session.find_button('med')[:id]).to eq(
|
10
|
-
expect(@session.find_button('crap321').value).to eq(
|
8
|
+
it 'should find any button' do
|
9
|
+
expect(@session.find_button('med')[:id]).to eq('mediocre')
|
10
|
+
expect(@session.find_button('crap321').value).to eq('crappy')
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
it
|
13
|
+
context 'aria_label attribute with Capybara.enable_aria_label' do
|
14
|
+
it 'should find when true' do
|
15
15
|
Capybara.enable_aria_label = true
|
16
|
-
expect(@session.find_button('Mediocre Button')[:id]).to eq(
|
16
|
+
expect(@session.find_button('Mediocre Button')[:id]).to eq('mediocre')
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'should not find when false' do
|
20
20
|
Capybara.enable_aria_label = false
|
21
21
|
expect { @session.find_button('Mediocre Button') }.to raise_error(Capybara::ElementNotFound)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(@session.find_button(:med)[:id]).to eq(
|
25
|
+
it 'casts to string' do
|
26
|
+
expect(@session.find_button(:med)[:id]).to eq('mediocre')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise error if the button doesn't exist" do
|
@@ -32,43 +32,43 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
32
32
|
end.to raise_error(Capybara::ElementNotFound)
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
36
|
-
it
|
37
|
-
expect(@session.find_button('What an Awesome', exact: false).value).to eq(
|
35
|
+
context 'with :exact option' do
|
36
|
+
it 'should accept partial matches when false' do
|
37
|
+
expect(@session.find_button('What an Awesome', exact: false).value).to eq('awesome')
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'should not accept partial matches when true' do
|
41
41
|
expect do
|
42
42
|
@session.find_button('What an Awesome', exact: true)
|
43
43
|
end.to raise_error(Capybara::ElementNotFound)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
context
|
48
|
-
it
|
49
|
-
expect(@session.find_button('Disabled button', disabled: true).value).to eq(
|
47
|
+
context 'with :disabled option' do
|
48
|
+
it 'should find disabled buttons when true' do
|
49
|
+
expect(@session.find_button('Disabled button', disabled: true).value).to eq('Disabled button')
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'should not find disabled buttons when false' do
|
53
53
|
expect do
|
54
54
|
@session.find_button('Disabled button', disabled: false)
|
55
55
|
end.to raise_error(Capybara::ElementNotFound)
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it 'should default to not finding disabled buttons' do
|
59
59
|
expect do
|
60
60
|
@session.find_button('Disabled button')
|
61
61
|
end.to raise_error(Capybara::ElementNotFound)
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
65
|
-
expect(@session.find_button('Disabled button', disabled: :all).value).to eq(
|
64
|
+
it 'should find disabled buttons when :all' do
|
65
|
+
expect(@session.find_button('Disabled button', disabled: :all).value).to eq('Disabled button')
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context
|
70
|
-
it
|
71
|
-
expect(@session.find_button(disabled: true).value).to eq(
|
69
|
+
context 'without locator' do
|
70
|
+
it 'should use options' do
|
71
|
+
expect(@session.find_button(disabled: true).value).to eq('Disabled button')
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -5,28 +5,28 @@ Capybara::SpecHelper.spec '#find_by_id' do
|
|
5
5
|
@session.visit('/with_html')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should find any element by id' do
|
9
9
|
expect(@session.find_by_id('red').tag_name).to eq('a')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'casts to string' do
|
13
13
|
expect(@session.find_by_id(:red).tag_name).to eq('a')
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'should raise error if no element with id is found' do
|
17
17
|
expect do
|
18
18
|
@session.find_by_id('nothing_with_this_id')
|
19
19
|
end.to raise_error(Capybara::ElementNotFound)
|
20
20
|
end
|
21
21
|
|
22
|
-
context
|
23
|
-
it
|
24
|
-
expect(@session.find_by_id(
|
22
|
+
context 'with :visible option' do
|
23
|
+
it 'finds invisible elements when `false`' do
|
24
|
+
expect(@session.find_by_id('hidden_via_ancestor', visible: false).text(:all)).to match(/with hidden ancestor/)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "doesn't find invisible elements when `true`" do
|
28
28
|
expect do
|
29
|
-
@session.find_by_id(
|
29
|
+
@session.find_by_id('hidden_via_ancestor', visible: true)
|
30
30
|
end.to raise_error(Capybara::ElementNotFound)
|
31
31
|
end
|
32
32
|
end
|
@@ -5,28 +5,30 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
5
5
|
@session.visit('/form')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should find any field' do
|
9
|
+
Capybara.test_id = 'data-test-id'
|
9
10
|
expect(@session.find_field('Dog').value).to eq('dog')
|
10
11
|
expect(@session.find_field('form_description').value).to eq('Descriptive text goes here')
|
11
12
|
expect(@session.find_field('Region')[:name]).to eq('form[region]')
|
12
13
|
expect(@session.find_field('With Asterisk*')).to be_truthy
|
14
|
+
expect(@session.find_field('my_test_id')).to be_truthy
|
13
15
|
end
|
14
16
|
|
15
|
-
context
|
16
|
-
it
|
17
|
+
context 'aria_label attribute with Capybara.enable_aria_label' do
|
18
|
+
it 'should find when true' do
|
17
19
|
Capybara.enable_aria_label = true
|
18
20
|
expect(@session.find_field('Unlabelled Input')[:name]).to eq('form[which_form]')
|
19
21
|
# expect(@session.find_field('Emergency Number')[:id]).to eq('html5_tel')
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
24
|
+
it 'should not find when false' do
|
23
25
|
Capybara.enable_aria_label = false
|
24
26
|
expect { @session.find_field('Unlabelled Input') }.to raise_error(Capybara::ElementNotFound)
|
25
27
|
# expect { @session.find_field('Emergency Number') }.to raise_error(Capybara::ElementNotFound)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
it
|
31
|
+
it 'casts to string' do
|
30
32
|
expect(@session.find_field(:Dog).value).to eq('dog')
|
31
33
|
end
|
32
34
|
|
@@ -36,62 +38,62 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
36
38
|
end.to raise_error(Capybara::ElementNotFound)
|
37
39
|
end
|
38
40
|
|
39
|
-
it
|
41
|
+
it 'should raise error if filter option is invalid' do
|
40
42
|
expect do
|
41
43
|
@session.find_field('Dog', disabled: nil)
|
42
|
-
end.to raise_error ArgumentError,
|
44
|
+
end.to raise_error ArgumentError, 'Invalid value nil passed to NodeFilter disabled'
|
43
45
|
end
|
44
46
|
|
45
|
-
context
|
46
|
-
it
|
47
|
-
expect(@session.find_field(
|
47
|
+
context 'with :exact option' do
|
48
|
+
it 'should accept partial matches when false' do
|
49
|
+
expect(@session.find_field('Explanation', exact: false)[:name]).to eq('form[name_explanation]')
|
48
50
|
end
|
49
51
|
|
50
|
-
it
|
52
|
+
it 'should not accept partial matches when true' do
|
51
53
|
expect do
|
52
|
-
@session.find_field(
|
54
|
+
@session.find_field('Explanation', exact: true)
|
53
55
|
end.to raise_error(Capybara::ElementNotFound)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
context
|
58
|
-
it
|
59
|
-
expect(@session.find_field(
|
60
|
-
expect(@session.find_field(
|
61
|
-
expect(@session.find_field(
|
59
|
+
context 'with :disabled option' do
|
60
|
+
it 'should find disabled fields when true' do
|
61
|
+
expect(@session.find_field('Disabled Checkbox', disabled: true)[:name]).to eq('form[disabled_checkbox]')
|
62
|
+
expect(@session.find_field('form_disabled_fieldset_child', disabled: true)[:name]).to eq('form[disabled_fieldset_child]')
|
63
|
+
expect(@session.find_field('form_disabled_fieldset_descendant', disabled: true)[:name]).to eq('form[disabled_fieldset_descendant]')
|
62
64
|
end
|
63
65
|
|
64
|
-
it
|
66
|
+
it 'should not find disabled fields when false' do
|
65
67
|
expect do
|
66
|
-
@session.find_field(
|
68
|
+
@session.find_field('Disabled Checkbox', disabled: false)
|
67
69
|
end.to raise_error(Capybara::ElementNotFound)
|
68
70
|
end
|
69
71
|
|
70
|
-
it
|
72
|
+
it 'should not find disabled fields by default' do
|
71
73
|
expect do
|
72
|
-
@session.find_field(
|
74
|
+
@session.find_field('Disabled Checkbox')
|
73
75
|
end.to raise_error(Capybara::ElementNotFound)
|
74
76
|
end
|
75
77
|
|
76
|
-
it
|
77
|
-
expect(@session.find_field(
|
78
|
+
it 'should find disabled fields when :all' do
|
79
|
+
expect(@session.find_field('Disabled Checkbox', disabled: :all)[:name]).to eq('form[disabled_checkbox]')
|
78
80
|
end
|
79
81
|
|
80
|
-
it
|
82
|
+
it 'should find enabled fields when :all' do
|
81
83
|
expect(@session.find_field('Dog', disabled: :all).value).to eq('dog')
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
87
|
context 'with :readonly option' do
|
86
|
-
it
|
88
|
+
it 'should find readonly fields when true' do
|
87
89
|
expect(@session.find_field('form[readonly_test]', readonly: true)[:id]).to eq 'readonly'
|
88
90
|
end
|
89
91
|
|
90
|
-
it
|
92
|
+
it 'should not find readonly fields when false' do
|
91
93
|
expect(@session.find_field('form[readonly_test]', readonly: false)[:id]).to eq 'not_readonly'
|
92
94
|
end
|
93
95
|
|
94
|
-
it
|
96
|
+
it 'should ignore readonly by default' do
|
95
97
|
expect do
|
96
98
|
@session.find_field('form[readonly_test]')
|
97
99
|
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
|
@@ -100,12 +102,12 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
100
102
|
|
101
103
|
context 'with no locator' do
|
102
104
|
it 'should use options to find the field' do
|
103
|
-
expect(@session.find_field(with: 'dog')['id']).to eq
|
105
|
+
expect(@session.find_field(with: 'dog')['id']).to eq 'form_pets_dog'
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
it
|
109
|
+
it 'should accept an optional filter block' do
|
108
110
|
# this would be better done with the :with option but this is just a test
|
109
|
-
expect(@session.find_field('form[pets][]') { |node| node.value == 'dog' }[:id]).to eq
|
111
|
+
expect(@session.find_field('form[pets][]') { |node| node.value == 'dog' }[:id]).to eq 'form_pets_dog'
|
110
112
|
end
|
111
113
|
end
|
@@ -5,25 +5,25 @@ Capybara::SpecHelper.spec '#find_link' do
|
|
5
5
|
@session.visit('/with_html')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
expect(@session.find_link('foo').text).to eq(
|
8
|
+
it 'should find any link' do
|
9
|
+
expect(@session.find_link('foo').text).to eq('ullamco')
|
10
10
|
expect(@session.find_link('labore')[:href]).to match %r{/with_simple_html$}
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
it
|
13
|
+
context 'aria_label attribute with Capybara.enable_aria_label' do
|
14
|
+
it 'should find when true' do
|
15
15
|
Capybara.enable_aria_label = true
|
16
16
|
expect(@session.find_link('Go to simple')[:href]).to match %r{/with_simple_html$}
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'should not find when false' do
|
20
20
|
Capybara.enable_aria_label = false
|
21
21
|
expect { @session.find_link('Go to simple') }.to raise_error(Capybara::ElementNotFound)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(@session.find_link(:foo).text).to eq(
|
25
|
+
it 'casts to string' do
|
26
|
+
expect(@session.find_link(:foo).text).to eq('ullamco')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise error if the field doesn't exist" do
|
@@ -32,38 +32,38 @@ Capybara::SpecHelper.spec '#find_link' do
|
|
32
32
|
end.to raise_error(Capybara::ElementNotFound)
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
36
|
-
it
|
37
|
-
expect(@session.find_link('abo', exact: false).text).to eq(
|
35
|
+
context 'with :exact option' do
|
36
|
+
it 'should accept partial matches when false' do
|
37
|
+
expect(@session.find_link('abo', exact: false).text).to eq('labore')
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'should not accept partial matches when true' do
|
41
41
|
expect do
|
42
42
|
@session.find_link('abo', exact: true)
|
43
43
|
end.to raise_error(Capybara::ElementNotFound)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
context
|
48
|
-
it
|
49
|
-
expect(@session.find_link(href: '#anchor').text).to eq
|
47
|
+
context 'without locator' do
|
48
|
+
it 'should use options' do
|
49
|
+
expect(@session.find_link(href: '#anchor').text).to eq 'Normal Anchor'
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context
|
54
|
-
it
|
55
|
-
expect(@session.find_link(
|
53
|
+
context 'download filter' do
|
54
|
+
it 'finds a download link' do
|
55
|
+
expect(@session.find_link('Download Me', download: true).text).to eq 'Download Me'
|
56
56
|
end
|
57
57
|
|
58
58
|
it "doesn't find a download link if download is false" do
|
59
|
-
expect { @session.find_link(
|
59
|
+
expect { @session.find_link('Download Me', download: false) }.to raise_error Capybara::ElementNotFound
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
expect(@session.find_link(download:
|
62
|
+
it 'finds a renaming download link' do
|
63
|
+
expect(@session.find_link(download: 'other.csv').text).to eq 'Download Other'
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'raises if passed an invalid value' do
|
67
67
|
expect { @session.find_link(download: 37) }.to raise_error ArgumentError
|
68
68
|
end
|
69
69
|
end
|
@@ -9,66 +9,67 @@ Capybara::SpecHelper.spec '#find' do
|
|
9
9
|
Capybara::Selector.remove(:monkey)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should find the first element using the given locator' do
|
13
13
|
expect(@session.find('//h1').text).to eq('This is a test')
|
14
14
|
expect(@session.find("//input[@id='test_field']").value).to eq('monkey')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should find the first element using the given locator and options' do
|
18
18
|
expect(@session.find('//a', text: 'Redirect')[:id]).to eq('red')
|
19
19
|
expect(@session.find(:css, 'a', text: 'A link came first')[:title]).to eq('twas a fine link')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should raise an error if there are multiple matches' do
|
23
23
|
expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should wait for asynchronous load', requires: [:js] do
|
27
|
+
Capybara.default_max_wait_time = 2
|
27
28
|
@session.visit('/with_js')
|
28
29
|
@session.click_link('Click me')
|
29
|
-
expect(@session.find(:css,
|
30
|
+
expect(@session.find(:css, 'a#has-been-clicked').text).to include('Has been clicked')
|
30
31
|
end
|
31
32
|
|
32
|
-
context
|
33
|
+
context 'with :text option' do
|
33
34
|
it "casts text's argument to string" do
|
34
|
-
expect(@session.find(:css, '.number', text: 42)).to have_content(
|
35
|
+
expect(@session.find(:css, '.number', text: 42)).to have_content('42')
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
context
|
39
|
-
it
|
39
|
+
context 'with :wait option', requires: [:js] do
|
40
|
+
it 'should not wait for asynchronous load when `false` given' do
|
40
41
|
@session.visit('/with_js')
|
41
42
|
@session.click_link('Click me')
|
42
43
|
expect do
|
43
|
-
@session.find(:css,
|
44
|
+
@session.find(:css, 'a#has-been-clicked', wait: false)
|
44
45
|
end.to raise_error(Capybara::ElementNotFound)
|
45
46
|
end
|
46
47
|
|
47
|
-
it
|
48
|
+
it 'should not find element if it appears after given wait duration' do
|
48
49
|
@session.visit('/with_js')
|
49
50
|
@session.click_link('Slowly')
|
50
51
|
expect do
|
51
|
-
@session.find(:css,
|
52
|
+
@session.find(:css, 'a#slow-clicked', wait: 0.2)
|
52
53
|
end.to raise_error(Capybara::ElementNotFound)
|
53
54
|
end
|
54
55
|
|
55
|
-
it
|
56
|
+
it 'should find element if it appears before given wait duration' do
|
56
57
|
@session.visit('/with_js')
|
57
58
|
@session.click_link('Click me')
|
58
|
-
expect(@session.find(:css,
|
59
|
+
expect(@session.find(:css, 'a#has-been-clicked', wait: 3.0).text).to include('Has been clicked')
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
context
|
63
|
+
context 'with frozen time', requires: [:js] do
|
63
64
|
if defined?(Process::CLOCK_MONOTONIC)
|
64
|
-
it
|
65
|
+
it 'will time out even if time is frozen' do
|
65
66
|
@session.visit('/with_js')
|
66
67
|
now = Time.now
|
67
68
|
allow(Time).to receive(:now).and_return(now)
|
68
69
|
expect { @session.find('//isnotthere') }.to raise_error(Capybara::ElementNotFound)
|
69
70
|
end
|
70
71
|
else
|
71
|
-
it
|
72
|
+
it 'raises an error suggesting that Capybara is stuck in time' do
|
72
73
|
@session.visit('/with_js')
|
73
74
|
now = Time.now
|
74
75
|
allow(Time).to receive(:now).and_return(now)
|
@@ -77,31 +78,31 @@ Capybara::SpecHelper.spec '#find' do
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
context
|
81
|
-
it
|
81
|
+
context 'with css selectors' do
|
82
|
+
it 'should find the first element using the given locator' do
|
82
83
|
expect(@session.find(:css, 'h1').text).to eq('This is a test')
|
83
84
|
expect(@session.find(:css, "input[id='test_field']").value).to eq('monkey')
|
84
85
|
end
|
85
86
|
|
86
|
-
it
|
87
|
+
it 'should support pseudo selectors' do
|
87
88
|
expect(@session.find(:css, 'input:disabled').value).to eq('This is disabled')
|
88
89
|
end
|
89
90
|
|
90
|
-
it
|
91
|
+
it 'should support escaping characters' do
|
91
92
|
expect(@session.find(:css, '#\31 escape\.me').text).to eq('needs escaping')
|
92
93
|
expect(@session.find(:css, '.\32 escape').text).to eq('needs escaping')
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
context
|
97
|
-
it
|
97
|
+
context 'with xpath selectors' do
|
98
|
+
it 'should find the first element using the given locator' do
|
98
99
|
expect(@session.find(:xpath, '//h1').text).to eq('This is a test')
|
99
100
|
expect(@session.find(:xpath, "//input[@id='test_field']").value).to eq('monkey')
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
context
|
104
|
-
it
|
104
|
+
context 'with custom selector' do
|
105
|
+
it 'should use the custom selector' do
|
105
106
|
Capybara.add_selector(:beatle) do
|
106
107
|
xpath { |name| ".//*[@id='#{name}']" }
|
107
108
|
end
|
@@ -110,8 +111,8 @@ Capybara::SpecHelper.spec '#find' do
|
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
113
|
-
context
|
114
|
-
it
|
114
|
+
context 'with custom selector with custom `match` block' do
|
115
|
+
it 'should use the custom selector when locator matches the block' do
|
115
116
|
Capybara.add_selector(:beatle) do
|
116
117
|
xpath { |num| ".//*[contains(@class, 'beatle')][#{num}]" }
|
117
118
|
match { |value| value.is_a?(Integer) }
|
@@ -123,7 +124,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
126
|
-
context
|
127
|
+
context 'with custom selector with custom filter' do
|
127
128
|
before do
|
128
129
|
Capybara.add_selector(:beatle) do
|
129
130
|
xpath { |name| ".//li[contains(@class, 'beatle')][contains(text(), '#{name}')]" }
|
@@ -132,12 +133,12 @@ Capybara::SpecHelper.spec '#find' do
|
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
|
-
it
|
136
|
+
it 'should find elements that match the filter' do
|
136
137
|
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
137
138
|
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
138
139
|
end
|
139
140
|
|
140
|
-
it
|
141
|
+
it 'ignores filter when it is not given' do
|
141
142
|
expect(@session.find(:beatle, 'Paul').text).to eq('Paul')
|
142
143
|
expect(@session.find(:beatle, 'John').text).to eq('John')
|
143
144
|
end
|
@@ -147,25 +148,25 @@ Capybara::SpecHelper.spec '#find' do
|
|
147
148
|
expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
148
149
|
end
|
149
150
|
|
150
|
-
it
|
151
|
+
it 'should not raise an ElementNotFound error from in a filter' do
|
151
152
|
expect { @session.find(:beatle, 'John', fail: 'something') }.to raise_error(Capybara::ElementNotFound, /beatle "John"/)
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
|
-
context
|
156
|
+
context 'with custom selector with custom filter and default' do
|
156
157
|
before do
|
157
158
|
Capybara.add_selector(:beatle) do
|
158
159
|
xpath { |name| ".//li[contains(@class, 'beatle')][contains(text(), '#{name}')]" }
|
159
|
-
node_filter(:type, default:
|
160
|
+
node_filter(:type, default: 'drummer') { |node, type| node[:class].split(/\s+/).include?(type) }
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
163
|
-
it
|
164
|
+
it 'should find elements that match the filter' do
|
164
165
|
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
165
166
|
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
166
167
|
end
|
167
168
|
|
168
|
-
it
|
169
|
+
it 'should use default value when filter is not given' do
|
169
170
|
expect(@session.find(:beatle, 'Paul').text).to eq('Paul')
|
170
171
|
expect { @session.find(:beatle, 'John') }.to raise_error(Capybara::ElementNotFound)
|
171
172
|
end
|
@@ -176,7 +177,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
|
-
context
|
180
|
+
context 'with alternate filter set' do
|
180
181
|
before do
|
181
182
|
Capybara::Selector::FilterSet.add(:value) do
|
182
183
|
node_filter(:with) { |node, with| node.value == with.to_s }
|
@@ -188,255 +189,272 @@ Capybara::SpecHelper.spec '#find' do
|
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
|
-
it
|
192
|
+
it 'should allow use of filters from custom filter set' do
|
192
193
|
expect(@session.find(:id, 'test_field', filter_set: :value, with: 'monkey').value).to eq('monkey')
|
193
194
|
expect { @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
194
195
|
end
|
195
196
|
|
196
|
-
it
|
197
|
+
it 'should allow use of filter set from a different selector' do
|
197
198
|
expect(@session.find(:id, 'test_field', filter_set: :field, with: 'monkey').value).to eq('monkey')
|
198
199
|
expect { @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
199
200
|
end
|
200
201
|
|
201
|
-
it
|
202
|
+
it 'should allow importing of filter set into selector' do
|
202
203
|
expect(@session.find(:id_with_field_filters, 'test_field', with: 'monkey').value).to eq('monkey')
|
203
204
|
expect { @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
204
205
|
end
|
205
206
|
end
|
206
207
|
|
207
|
-
context
|
208
|
+
context 'with css as default selector' do
|
208
209
|
before { Capybara.default_selector = :css }
|
209
210
|
|
210
|
-
it
|
211
|
+
it 'should find the first element using the given locator' do
|
211
212
|
expect(@session.find('h1').text).to eq('This is a test')
|
212
213
|
expect(@session.find("input[id='test_field']").value).to eq('monkey')
|
213
214
|
end
|
214
215
|
after { Capybara.default_selector = :xpath }
|
215
216
|
end
|
216
217
|
|
217
|
-
it
|
218
|
+
it 'should raise ElementNotFound with a useful default message if nothing was found' do
|
218
219
|
expect do
|
219
220
|
@session.find(:xpath, '//div[@id="nosuchthing"]').to be_nil
|
220
|
-
end.to raise_error(Capybara::ElementNotFound,
|
221
|
+
end.to raise_error(Capybara::ElementNotFound, 'Unable to find xpath "//div[@id=\\"nosuchthing\\"]"')
|
221
222
|
end
|
222
223
|
|
223
|
-
it
|
224
|
+
it 'should accept an XPath instance' do
|
224
225
|
@session.visit('/form')
|
225
226
|
@xpath = Capybara::Selector.all[:fillable_field].call('First Name')
|
226
227
|
expect(@xpath).to be_a(::XPath::Union)
|
227
228
|
expect(@session.find(@xpath).value).to eq('John')
|
228
229
|
end
|
229
230
|
|
230
|
-
context
|
231
|
-
it
|
232
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
231
|
+
context 'with :exact option' do
|
232
|
+
it 'matches exactly when true' do
|
233
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('test_field')], exact: true).value).to eq('monkey')
|
233
234
|
expect do
|
234
|
-
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
235
|
+
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('est_fiel')], exact: true)
|
235
236
|
end.to raise_error(Capybara::ElementNotFound)
|
236
237
|
end
|
237
238
|
|
238
|
-
it
|
239
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
240
|
-
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
239
|
+
it 'matches loosely when false' do
|
240
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('test_field')], exact: false).value).to eq('monkey')
|
241
|
+
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('est_fiel')], exact: false).value).to eq('monkey')
|
241
242
|
end
|
242
243
|
|
243
|
-
it
|
244
|
+
it 'defaults to `Capybara.exact`' do
|
244
245
|
Capybara.exact = true
|
245
246
|
expect do
|
246
|
-
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
247
|
+
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('est_fiel')])
|
247
248
|
end.to raise_error(Capybara::ElementNotFound)
|
248
249
|
Capybara.exact = false
|
249
|
-
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is(
|
250
|
+
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is('est_fiel')])
|
250
251
|
end
|
251
252
|
|
252
|
-
it
|
253
|
+
it 'warns when the option has no effect' do
|
253
254
|
expect_any_instance_of(Kernel).to receive(:warn)
|
254
255
|
.with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
|
255
256
|
@session.find(:css, '#test_field', exact: true)
|
256
257
|
end
|
257
258
|
end
|
258
259
|
|
259
|
-
context
|
260
|
-
context
|
261
|
-
it
|
260
|
+
context 'with :match option' do
|
261
|
+
context 'when set to `one`' do
|
262
|
+
it 'raises an error when multiple matches exist' do
|
262
263
|
expect do
|
263
|
-
@session.find(:css,
|
264
|
+
@session.find(:css, '.multiple', match: :one)
|
264
265
|
end.to raise_error(Capybara::Ambiguous)
|
265
266
|
end
|
266
|
-
it
|
267
|
+
it 'raises an error even if there the match is exact and the others are inexact' do
|
267
268
|
expect do
|
268
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
269
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], exact: false, match: :one)
|
269
270
|
end.to raise_error(Capybara::Ambiguous)
|
270
271
|
end
|
271
|
-
it
|
272
|
-
expect(@session.find(:css,
|
272
|
+
it 'returns the element if there is only one' do
|
273
|
+
expect(@session.find(:css, '.singular', match: :one).text).to eq('singular')
|
273
274
|
end
|
274
|
-
it
|
275
|
+
it 'raises an error if there is no match' do
|
275
276
|
expect do
|
276
|
-
@session.find(:css,
|
277
|
+
@session.find(:css, '.does-not-exist', match: :one)
|
277
278
|
end.to raise_error(Capybara::ElementNotFound)
|
278
279
|
end
|
279
280
|
end
|
280
281
|
|
281
|
-
context
|
282
|
-
it
|
283
|
-
expect(@session.find(:css,
|
282
|
+
context 'when set to `first`' do
|
283
|
+
it 'returns the first matched element' do
|
284
|
+
expect(@session.find(:css, '.multiple', match: :first).text).to eq('multiple one')
|
284
285
|
end
|
285
|
-
it
|
286
|
+
it 'raises an error if there is no match' do
|
286
287
|
expect do
|
287
|
-
@session.find(:css,
|
288
|
+
@session.find(:css, '.does-not-exist', match: :first)
|
288
289
|
end.to raise_error(Capybara::ElementNotFound)
|
289
290
|
end
|
290
291
|
end
|
291
292
|
|
292
|
-
context
|
293
|
-
context
|
294
|
-
it
|
293
|
+
context 'when set to `smart`' do
|
294
|
+
context 'and `exact` set to `false`' do
|
295
|
+
it 'raises an error when there are multiple exact matches' do
|
295
296
|
expect do
|
296
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
297
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :smart, exact: false)
|
297
298
|
end.to raise_error(Capybara::Ambiguous)
|
298
299
|
end
|
299
|
-
it
|
300
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
301
|
-
expect(result.text).to eq(
|
300
|
+
it 'finds a single exact match when there also are inexact matches' do
|
301
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :smart, exact: false)
|
302
|
+
expect(result.text).to eq('almost singular')
|
302
303
|
end
|
303
|
-
it
|
304
|
+
it 'raises an error when there are multiple inexact matches' do
|
304
305
|
expect do
|
305
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
306
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :smart, exact: false)
|
306
307
|
end.to raise_error(Capybara::Ambiguous)
|
307
308
|
end
|
308
|
-
it
|
309
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
310
|
-
expect(result.text).to eq(
|
309
|
+
it 'finds a single inexact match' do
|
310
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :smart, exact: false)
|
311
|
+
expect(result.text).to eq('almost singular but not quite')
|
311
312
|
end
|
312
|
-
it
|
313
|
+
it 'raises an error if there is no match' do
|
313
314
|
expect do
|
314
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
315
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :smart, exact: false)
|
315
316
|
end.to raise_error(Capybara::ElementNotFound)
|
316
317
|
end
|
317
318
|
end
|
318
319
|
|
319
|
-
context
|
320
|
-
it
|
320
|
+
context 'with `exact` set to `true`' do
|
321
|
+
it 'raises an error when there are multiple exact matches' do
|
321
322
|
expect do
|
322
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
323
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :smart, exact: true)
|
323
324
|
end.to raise_error(Capybara::Ambiguous)
|
324
325
|
end
|
325
|
-
it
|
326
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
327
|
-
expect(result.text).to eq(
|
326
|
+
it 'finds a single exact match when there also are inexact matches' do
|
327
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :smart, exact: true)
|
328
|
+
expect(result.text).to eq('almost singular')
|
328
329
|
end
|
329
|
-
it
|
330
|
+
it 'raises an error when there are multiple inexact matches' do
|
330
331
|
expect do
|
331
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
332
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :smart, exact: true)
|
332
333
|
end.to raise_error(Capybara::ElementNotFound)
|
333
334
|
end
|
334
|
-
it
|
335
|
+
it 'raises an error when there is a single inexact matches' do
|
335
336
|
expect do
|
336
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
337
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :smart, exact: true)
|
337
338
|
end.to raise_error(Capybara::ElementNotFound)
|
338
339
|
end
|
339
|
-
it
|
340
|
+
it 'raises an error if there is no match' do
|
340
341
|
expect do
|
341
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
342
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :smart, exact: true)
|
342
343
|
end.to raise_error(Capybara::ElementNotFound)
|
343
344
|
end
|
344
345
|
end
|
345
346
|
end
|
346
347
|
|
347
|
-
context
|
348
|
-
context
|
349
|
-
it
|
350
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
351
|
-
expect(result.text).to eq(
|
348
|
+
context 'when set to `prefer_exact`' do
|
349
|
+
context 'and `exact` set to `false`' do
|
350
|
+
it 'picks the first one when there are multiple exact matches' do
|
351
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :prefer_exact, exact: false)
|
352
|
+
expect(result.text).to eq('multiple one')
|
352
353
|
end
|
353
|
-
it
|
354
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
355
|
-
expect(result.text).to eq(
|
354
|
+
it 'finds a single exact match when there also are inexact matches' do
|
355
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :prefer_exact, exact: false)
|
356
|
+
expect(result.text).to eq('almost singular')
|
356
357
|
end
|
357
|
-
it
|
358
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
359
|
-
expect(result.text).to eq(
|
358
|
+
it 'picks the first one when there are multiple inexact matches' do
|
359
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :prefer_exact, exact: false)
|
360
|
+
expect(result.text).to eq('almost singular but not quite')
|
360
361
|
end
|
361
|
-
it
|
362
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
363
|
-
expect(result.text).to eq(
|
362
|
+
it 'finds a single inexact match' do
|
363
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :prefer_exact, exact: false)
|
364
|
+
expect(result.text).to eq('almost singular but not quite')
|
364
365
|
end
|
365
|
-
it
|
366
|
+
it 'raises an error if there is no match' do
|
366
367
|
expect do
|
367
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
368
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :prefer_exact, exact: false)
|
368
369
|
end.to raise_error(Capybara::ElementNotFound)
|
369
370
|
end
|
370
371
|
end
|
371
372
|
|
372
|
-
context
|
373
|
-
it
|
374
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
375
|
-
expect(result.text).to eq(
|
373
|
+
context 'with `exact` set to `true`' do
|
374
|
+
it 'picks the first one when there are multiple exact matches' do
|
375
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :prefer_exact, exact: true)
|
376
|
+
expect(result.text).to eq('multiple one')
|
376
377
|
end
|
377
|
-
it
|
378
|
-
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
379
|
-
expect(result.text).to eq(
|
378
|
+
it 'finds a single exact match when there also are inexact matches' do
|
379
|
+
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :prefer_exact, exact: true)
|
380
|
+
expect(result.text).to eq('almost singular')
|
380
381
|
end
|
381
|
-
it
|
382
|
+
it 'raises an error if there are multiple inexact matches' do
|
382
383
|
expect do
|
383
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
384
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :prefer_exact, exact: true)
|
384
385
|
end.to raise_error(Capybara::ElementNotFound)
|
385
386
|
end
|
386
|
-
it
|
387
|
+
it 'raises an error if there is a single inexact match' do
|
387
388
|
expect do
|
388
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
389
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :prefer_exact, exact: true)
|
389
390
|
end.to raise_error(Capybara::ElementNotFound)
|
390
391
|
end
|
391
|
-
it
|
392
|
+
it 'raises an error if there is no match' do
|
392
393
|
expect do
|
393
|
-
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is(
|
394
|
+
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :prefer_exact, exact: true)
|
394
395
|
end.to raise_error(Capybara::ElementNotFound)
|
395
396
|
end
|
396
397
|
end
|
397
398
|
end
|
398
399
|
|
399
|
-
it
|
400
|
+
it 'defaults to `Capybara.match`' do
|
400
401
|
Capybara.match = :one
|
401
402
|
expect do
|
402
|
-
@session.find(:css,
|
403
|
+
@session.find(:css, '.multiple')
|
403
404
|
end.to raise_error(Capybara::Ambiguous)
|
404
405
|
Capybara.match = :first
|
405
|
-
expect(@session.find(:css,
|
406
|
+
expect(@session.find(:css, '.multiple').text).to eq('multiple one')
|
406
407
|
end
|
407
408
|
|
408
|
-
it
|
409
|
+
it 'raises an error when unknown option given' do
|
409
410
|
expect do
|
410
|
-
@session.find(:css,
|
411
|
+
@session.find(:css, '.singular', match: :schmoo)
|
411
412
|
end.to raise_error(ArgumentError)
|
412
413
|
end
|
413
414
|
end
|
414
415
|
|
415
|
-
it
|
416
|
+
it 'supports a custom filter block' do
|
416
417
|
expect(@session.find(:css, 'input', &:disabled?)[:name]).to eq('disabled_text')
|
417
418
|
end
|
418
419
|
|
419
|
-
context
|
420
|
+
context 'within a scope' do
|
420
421
|
before do
|
421
422
|
@session.visit('/with_scope')
|
422
423
|
end
|
423
424
|
|
424
|
-
it
|
425
|
+
it 'should find the an element using the given locator' do
|
425
426
|
@session.within(:xpath, "//div[@id='for_bar']") do
|
426
427
|
expect(@session.find('.//li[1]').text).to match(/With Simple HTML/)
|
427
428
|
end
|
428
429
|
end
|
429
430
|
|
430
|
-
it
|
431
|
+
it 'should support pseudo selectors' do
|
431
432
|
@session.within(:xpath, "//div[@id='for_bar']") do
|
432
433
|
expect(@session.find(:css, 'input:disabled').value).to eq('James')
|
433
434
|
end
|
434
435
|
end
|
435
436
|
end
|
436
437
|
|
437
|
-
it
|
438
|
+
it 'should raise if selector type is unknown' do
|
438
439
|
expect do
|
439
440
|
@session.find(:unknown, '//h1')
|
440
441
|
end.to raise_error(ArgumentError)
|
441
442
|
end
|
443
|
+
|
444
|
+
context 'with Capybara.test_id' do
|
445
|
+
it 'should not match on it when nil' do
|
446
|
+
Capybara.test_id = nil
|
447
|
+
expect(@session).not_to have_field('test_id')
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'should work with the attribute set to `data-test-id` attribute' do
|
451
|
+
Capybara.test_id = 'data-test-id'
|
452
|
+
expect(@session.find(:field, 'test_id')[:id]).to eq 'test_field'
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'should use a different attribute if set' do
|
456
|
+
Capybara.test_id = 'data-other-test-id'
|
457
|
+
expect(@session.find(:field, 'test_id')[:id]).to eq 'normal'
|
458
|
+
end
|
459
|
+
end
|
442
460
|
end
|