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
@@ -11,13 +11,13 @@ Capybara::SpecHelper.spec '#assert_title' do
|
|
11
11
|
end.not_to raise_error
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'should not raise when given an empty string' do
|
15
15
|
expect do
|
16
16
|
@session.assert_title('')
|
17
17
|
end.not_to raise_error
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'should allow regexp matches' do
|
21
21
|
expect do
|
22
22
|
@session.assert_title(/w[a-z]{3}_js/)
|
23
23
|
end.not_to raise_error
|
@@ -27,10 +27,10 @@ Capybara::SpecHelper.spec '#assert_title' do
|
|
27
27
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to match /w[a-z]{10}_js/')
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
@session.click_link(
|
30
|
+
it 'should wait for title', requires: [:js] do
|
31
|
+
@session.click_link('Change title')
|
32
32
|
expect do
|
33
|
-
@session.assert_title(
|
33
|
+
@session.assert_title('changed title', wait: 3)
|
34
34
|
end.not_to raise_error
|
35
35
|
end
|
36
36
|
|
@@ -40,12 +40,12 @@ Capybara::SpecHelper.spec '#assert_title' do
|
|
40
40
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "monkey"')
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'should not normalize given title' do
|
44
44
|
@session.visit('/with_js')
|
45
45
|
expect { @session.assert_title(' with_js ') }.to raise_error(Capybara::ExpectationNotMet)
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'should match correctly normalized title' do
|
49
49
|
uri = Addressable::URI.parse('/with_title')
|
50
50
|
uri.query_values = { title: ' with space title ' }
|
51
51
|
@session.visit(uri.to_s)
|
@@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#assert_title' do
|
|
53
53
|
expect { @session.assert_title('with space title') }.to raise_error(Capybara::ExpectationNotMet)
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'should not normalize given title in error message' do
|
57
57
|
expect do
|
58
58
|
@session.assert_title(2)
|
59
59
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "2"')
|
@@ -65,21 +65,21 @@ Capybara::SpecHelper.spec '#assert_no_title' do
|
|
65
65
|
@session.visit('/with_js')
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'should raise error if the title contains the given string' do
|
69
69
|
expect do
|
70
70
|
@session.assert_no_title('with_j')
|
71
71
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to include "with_j"')
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it 'should allow regexp matches' do
|
75
75
|
expect do
|
76
76
|
@session.assert_no_title(/w[a-z]{3}_js/)
|
77
77
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to match /w[a-z]{3}_js/')
|
78
78
|
@session.assert_no_title(/monkey/)
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
82
|
-
@session.click_link(
|
81
|
+
it 'should wait for title to disappear', requires: [:js] do
|
82
|
+
@session.click_link('Change title')
|
83
83
|
expect do
|
84
84
|
@session.assert_no_title('with_js', wait: 3)
|
85
85
|
end.not_to raise_error
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Capybara::SpecHelper.spec
|
3
|
+
Capybara::SpecHelper.spec '#attach_file' do
|
4
4
|
before do
|
5
5
|
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
|
6
6
|
@another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
|
@@ -9,97 +9,96 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|
9
9
|
@session.visit('/form')
|
10
10
|
end
|
11
11
|
|
12
|
-
context
|
13
|
-
it
|
14
|
-
@session.attach_file
|
12
|
+
context 'with normal form' do
|
13
|
+
it 'should set a file path by id' do
|
14
|
+
@session.attach_file 'form_image', with_os_path_separators(__FILE__)
|
15
15
|
@session.click_button('awesome')
|
16
16
|
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
@session.attach_file
|
19
|
+
it 'should set a file path by label' do
|
20
|
+
@session.attach_file 'Image', with_os_path_separators(__FILE__)
|
21
21
|
@session.click_button('awesome')
|
22
22
|
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'casts to string' do
|
26
26
|
@session.attach_file :form_image, with_os_path_separators(__FILE__)
|
27
27
|
@session.click_button('awesome')
|
28
28
|
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
context
|
33
|
-
it
|
34
|
-
@session.attach_file
|
32
|
+
context 'with multipart form' do
|
33
|
+
it 'should set a file path by id' do
|
34
|
+
@session.attach_file 'form_document', with_os_path_separators(@test_file_path)
|
35
35
|
@session.click_button('Upload Single')
|
36
36
|
expect(@session).to have_content(File.read(@test_file_path))
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
@session.attach_file
|
39
|
+
it 'should set a file path by label' do
|
40
|
+
@session.attach_file 'Single Document', with_os_path_separators(@test_file_path)
|
41
41
|
@session.click_button('Upload Single')
|
42
42
|
expect(@session).to have_content(File.read(@test_file_path))
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'should not break if no file is submitted' do
|
46
46
|
@session.click_button('Upload Single')
|
47
47
|
expect(@session).to have_content('No file uploaded')
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
@session.attach_file
|
50
|
+
it 'should send content type text/plain when uploading a text file' do
|
51
|
+
@session.attach_file 'Single Document', with_os_path_separators(@test_file_path)
|
52
52
|
@session.click_button 'Upload Single'
|
53
53
|
expect(@session).to have_content('text/plain')
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
@session.attach_file
|
56
|
+
it 'should send content type image/jpeg when uploading an image' do
|
57
|
+
@session.attach_file 'Single Document', with_os_path_separators(@test_jpg_file_path)
|
58
58
|
@session.click_button 'Upload Single'
|
59
59
|
expect(@session).to have_content('image/jpeg')
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
@session.attach_file
|
62
|
+
it 'should not break when uploading a file without extension' do
|
63
|
+
@session.attach_file 'Single Document', with_os_path_separators(@no_extension_file_path)
|
64
64
|
@session.click_button 'Upload Single'
|
65
65
|
expect(@session).to have_content(File.read(@no_extension_file_path))
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
@session.attach_file
|
68
|
+
it 'should not break when using HTML5 multiple file input' do
|
69
|
+
@session.attach_file 'Multiple Documents', with_os_path_separators(@test_file_path)
|
70
70
|
@session.click_button('Upload Multiple')
|
71
71
|
expect(@session).to have_content(File.read(@test_file_path))
|
72
|
-
expect(@session.body).to include(
|
72
|
+
expect(@session.body).to include('1 | ') # number of files
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
76
|
-
@session.attach_file(
|
75
|
+
it 'should not break when using HTML5 multiple file input uploading multiple files' do
|
76
|
+
@session.attach_file('Multiple Documents',
|
77
77
|
[@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
|
78
78
|
@session.click_button('Upload Multiple')
|
79
|
-
expect(@session.body).to include(
|
79
|
+
expect(@session.body).to include('2 | ') # number of files
|
80
80
|
expect(@session.body).to include(File.read(@test_file_path))
|
81
81
|
expect(@session.body).to include(File.read(@another_test_file_path))
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'should not send anything when attaching no files to a multiple upload field' do
|
85
85
|
@session.click_button('Upload Empty Multiple')
|
86
|
-
expect(@session).to have_content(
|
86
|
+
expect(@session).to have_content('Successfully ignored empty file field')
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
@session.attach_file
|
91
|
-
@session.attach_file
|
92
|
-
[@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
|
89
|
+
it 'should not append files to already attached' do
|
90
|
+
@session.attach_file 'Multiple Documents', with_os_path_separators(@test_file_path)
|
91
|
+
@session.attach_file 'Multiple Documents', with_os_path_separators(@another_test_file_path)
|
93
92
|
@session.click_button('Upload Multiple')
|
94
|
-
expect(@session.body).to include(
|
95
|
-
expect(@session.body).to include(File.read(@test_file_path))
|
93
|
+
expect(@session.body).to include('1 | ') # number of files
|
96
94
|
expect(@session.body).to include(File.read(@another_test_file_path))
|
95
|
+
expect(@session.body).not_to include(File.read(@test_file_path))
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
99
|
context "with a locator that doesn't exist" do
|
101
|
-
it
|
102
|
-
msg =
|
100
|
+
it 'should raise an error' do
|
101
|
+
msg = 'Unable to find file field "does not exist"'
|
103
102
|
expect do
|
104
103
|
@session.attach_file('does not exist', with_os_path_separators(@test_file_path))
|
105
104
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -107,56 +106,56 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|
107
106
|
end
|
108
107
|
|
109
108
|
context "with a path that doesn't exist" do
|
110
|
-
it
|
109
|
+
it 'should raise an error' do
|
111
110
|
expect { @session.attach_file('Image', '/no_such_file.png') }.to raise_error(Capybara::FileNotFound)
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
115
|
-
context
|
116
|
-
it
|
117
|
-
@session.attach_file
|
114
|
+
context 'with :exact option' do
|
115
|
+
it 'should set a file path by partial label when false' do
|
116
|
+
@session.attach_file 'Imag', with_os_path_separators(__FILE__), exact: false
|
118
117
|
@session.click_button('awesome')
|
119
118
|
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
|
120
119
|
end
|
121
120
|
|
122
|
-
it
|
121
|
+
it 'should not allow partial matches when true' do
|
123
122
|
expect do
|
124
|
-
@session.attach_file
|
123
|
+
@session.attach_file 'Imag', with_os_path_separators(__FILE__), exact: true
|
125
124
|
end.to raise_error(Capybara::ElementNotFound)
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
129
|
-
context
|
130
|
-
it
|
128
|
+
context 'with :make_visible option', requires: %i[js es_args] do
|
129
|
+
it 'applies a default style change when true' do
|
131
130
|
@session.visit('/with_js')
|
132
131
|
expect do
|
133
|
-
@session.attach_file(
|
132
|
+
@session.attach_file('hidden_file', with_os_path_separators(__FILE__))
|
134
133
|
end.to raise_error Capybara::ElementNotFound
|
135
134
|
expect do
|
136
|
-
@session.attach_file(
|
135
|
+
@session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: true)
|
137
136
|
end.not_to raise_error
|
138
137
|
end
|
139
138
|
|
140
|
-
it
|
139
|
+
it 'accepts a hash of styles to be applied' do
|
141
140
|
@session.visit('/with_js')
|
142
141
|
expect do
|
143
|
-
@session.attach_file(
|
142
|
+
@session.attach_file('hidden_file',
|
144
143
|
with_os_path_separators(__FILE__),
|
145
144
|
make_visible: { opacity: 1, display: 'block' })
|
146
145
|
end.not_to raise_error
|
147
146
|
end
|
148
147
|
|
149
|
-
it
|
148
|
+
it 'raises an error when the file input is not made visible' do
|
150
149
|
@session.visit('/with_js')
|
151
150
|
expect do
|
152
|
-
@session.attach_file(
|
151
|
+
@session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: { color: 'red' })
|
153
152
|
end.to raise_error(Capybara::ExpectationNotMet)
|
154
153
|
end
|
155
154
|
|
156
|
-
it
|
155
|
+
it 'resets the style when done' do
|
157
156
|
@session.visit('/with_js')
|
158
|
-
@session.attach_file(
|
159
|
-
expect(@session.evaluate_script(
|
157
|
+
@session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: true)
|
158
|
+
expect(@session.evaluate_script('arguments[0].style.display', @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#body' do
|
4
|
-
it
|
4
|
+
it 'should return the unmodified page body' do
|
5
5
|
@session.visit('/')
|
6
6
|
expect(@session).to have_content('Hello world!') # wait for content to appear if visit is async
|
7
7
|
expect(@session.body).to include('Hello world!')
|
8
8
|
end
|
9
9
|
|
10
|
-
context
|
11
|
-
it
|
10
|
+
context 'encoding of response between ascii and utf8' do
|
11
|
+
it 'should be valid with html entities' do
|
12
12
|
@session.visit('/with_html_entities')
|
13
13
|
expect(@session).to have_content('Encoding') # wait for content to appear if visit is async
|
14
|
-
expect { @session.body.encode!(
|
14
|
+
expect { @session.body.encode!('UTF-8') }.not_to raise_error
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should be valid without html entities' do
|
18
18
|
@session.visit('/with_html')
|
19
19
|
expect(@session).to have_content('This is a test') # wait for content to appear if visit is async
|
20
|
-
expect { @session.body.encode!(
|
20
|
+
expect { @session.body.encode!('UTF-8') }.not_to raise_error
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,182 +1,187 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Capybara::SpecHelper.spec
|
3
|
+
Capybara::SpecHelper.spec '#check' do
|
4
4
|
before do
|
5
5
|
@session.visit('/form')
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "'checked' attribute" do
|
9
|
-
it
|
10
|
-
@session.check(
|
9
|
+
it 'should be true if checked' do
|
10
|
+
@session.check('Terms of Use')
|
11
11
|
expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_truthy
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'should be false if unchecked' do
|
15
15
|
expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_falsey
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'should trigger associated events', requires: [:js] do
|
20
20
|
@session.visit('/with_js')
|
21
21
|
@session.check('checkbox_with_event')
|
22
22
|
expect(@session).to have_css('#checkbox_event_triggered')
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
25
|
+
describe 'checking' do
|
26
|
+
it 'should not change an already checked checkbox' do
|
27
27
|
expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
|
28
28
|
@session.check('form_pets_dog')
|
29
29
|
expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'should check an unchecked checkbox' do
|
33
33
|
expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
|
34
34
|
@session.check('form_pets_cat')
|
35
35
|
expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).to be_checked
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe
|
40
|
-
it
|
39
|
+
describe 'unchecking' do
|
40
|
+
it 'should not change an already unchecked checkbox' do
|
41
41
|
expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
|
42
42
|
@session.uncheck('form_pets_cat')
|
43
43
|
expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'should uncheck a checked checkbox' do
|
47
47
|
expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
|
48
48
|
@session.uncheck('form_pets_dog')
|
49
49
|
expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).not_to be_checked
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
@session.check(
|
53
|
+
it 'should check a checkbox by id' do
|
54
|
+
@session.check('form_pets_cat')
|
55
55
|
@session.click_button('awesome')
|
56
56
|
expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
@session.check(
|
59
|
+
it 'should check a checkbox by label' do
|
60
|
+
@session.check('Cat')
|
61
61
|
@session.click_button('awesome')
|
62
62
|
expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
@session.check(id:
|
65
|
+
it 'should work without a locator string' do
|
66
|
+
@session.check(id: 'form_pets_cat')
|
67
67
|
@session.click_button('awesome')
|
68
68
|
expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
71
|
+
it 'casts to string' do
|
72
72
|
@session.check(:form_pets_cat)
|
73
73
|
@session.click_button('awesome')
|
74
74
|
expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
|
75
75
|
end
|
76
76
|
|
77
77
|
context "with a locator that doesn't exist" do
|
78
|
-
it
|
79
|
-
msg =
|
78
|
+
it 'should raise an error' do
|
79
|
+
msg = 'Unable to find checkbox "does not exist"'
|
80
80
|
expect do
|
81
81
|
@session.check('does not exist')
|
82
82
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
context
|
87
|
-
it
|
86
|
+
context 'with a disabled checkbox' do
|
87
|
+
it 'should raise an error' do
|
88
|
+
msg = 'Unable to find visible checkbox "Disabled Checkbox" that is not disabled'
|
88
89
|
expect do
|
89
90
|
@session.check('Disabled Checkbox')
|
90
|
-
end.to raise_error(Capybara::ElementNotFound)
|
91
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
context
|
95
|
-
it
|
95
|
+
context 'with :exact option' do
|
96
|
+
it 'should accept partial matches when false' do
|
96
97
|
@session.check('Ham', exact: false)
|
97
98
|
@session.click_button('awesome')
|
98
99
|
expect(extract_results(@session)['pets']).to include('hamster')
|
99
100
|
end
|
100
101
|
|
101
|
-
it
|
102
|
+
it 'should not accept partial matches when true' do
|
102
103
|
expect do
|
103
104
|
@session.check('Ham', exact: true)
|
104
105
|
end.to raise_error(Capybara::ElementNotFound)
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
108
|
-
context
|
109
|
-
it
|
110
|
-
@session.check('form[pets][]', option:
|
109
|
+
context 'with `option` option' do
|
110
|
+
it 'can check boxes by their value' do
|
111
|
+
@session.check('form[pets][]', option: 'cat')
|
111
112
|
@session.click_button('awesome')
|
112
113
|
expect(extract_results(@session)['pets']).to include('cat')
|
113
114
|
end
|
114
115
|
|
115
|
-
it
|
116
|
+
it 'should raise an error if option not found' do
|
116
117
|
expect do
|
117
|
-
@session.check('form[pets][]', option:
|
118
|
+
@session.check('form[pets][]', option: 'elephant')
|
118
119
|
end.to raise_error(Capybara::ElementNotFound)
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
|
-
context
|
123
|
-
context
|
123
|
+
context 'when checkbox hidden' do
|
124
|
+
context 'with Capybara.automatic_label_click == true' do
|
124
125
|
around do |spec|
|
125
126
|
old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
|
126
127
|
spec.run
|
127
128
|
Capybara.automatic_label_click = old_click_label
|
128
129
|
end
|
129
130
|
|
130
|
-
it
|
131
|
+
it 'should check via clicking the label with :for attribute if possible' do
|
131
132
|
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
|
132
133
|
@session.check('form_cars_tesla')
|
133
134
|
@session.click_button('awesome')
|
134
135
|
expect(extract_results(@session)['cars']).to include('tesla')
|
135
136
|
end
|
136
137
|
|
137
|
-
it
|
138
|
+
it 'should check via clicking the wrapping label if possible' do
|
138
139
|
expect(@session.find(:checkbox, 'form_cars_mclaren', unchecked: true, visible: :hidden)).to be_truthy
|
139
140
|
@session.check('form_cars_mclaren')
|
140
141
|
@session.click_button('awesome')
|
141
142
|
expect(extract_results(@session)['cars']).to include('mclaren')
|
142
143
|
end
|
143
144
|
|
144
|
-
it
|
145
|
+
it 'should not click the label if unneeded' do
|
145
146
|
expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to be_truthy
|
146
147
|
@session.check('form_cars_jaguar')
|
147
148
|
@session.click_button('awesome')
|
148
149
|
expect(extract_results(@session)['cars']).to include('jaguar')
|
149
150
|
end
|
150
151
|
|
151
|
-
it
|
152
|
-
expect { @session.check('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_ariel"
|
152
|
+
it 'should raise original error when no label available' do
|
153
|
+
expect { @session.check('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_ariel"')
|
153
154
|
end
|
154
155
|
|
155
|
-
it
|
156
|
-
expect { @session.check('form_cars_mclaren', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"
|
156
|
+
it 'should raise error if not allowed to click label' do
|
157
|
+
expect { @session.check('form_cars_mclaren', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"')
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
160
|
-
context
|
161
|
+
context 'with Capybara.automatic_label_click == false' do
|
161
162
|
around do |spec|
|
162
163
|
old_label_click, Capybara.automatic_label_click = Capybara.automatic_label_click, false
|
163
164
|
spec.run
|
164
165
|
Capybara.automatic_label_click = old_label_click
|
165
166
|
end
|
166
167
|
|
167
|
-
it
|
168
|
-
expect { @session.check('form_cars_mclaren') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"
|
168
|
+
it 'should raise error if checkbox not visible' do
|
169
|
+
expect { @session.check('form_cars_mclaren') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should include node filter in error if verified' do
|
173
|
+
expect { @session.check('form_cars_maserati') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_maserati" that is not disabled')
|
169
174
|
end
|
170
175
|
|
171
|
-
context
|
172
|
-
it
|
176
|
+
context 'with allow_label_click == true' do
|
177
|
+
it 'should check via the label if input is hidden' do
|
173
178
|
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
|
174
179
|
@session.check('form_cars_tesla', allow_label_click: true)
|
175
180
|
@session.click_button('awesome')
|
176
181
|
expect(extract_results(@session)['cars']).to include('tesla')
|
177
182
|
end
|
178
183
|
|
179
|
-
it
|
184
|
+
it 'should not wait the full time if label can be clicked' do
|
180
185
|
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
|
181
186
|
start_time = Time.now
|
182
187
|
@session.check('form_cars_tesla', allow_label_click: true, wait: 10)
|
@@ -184,7 +189,7 @@ Capybara::SpecHelper.spec "#check" do
|
|
184
189
|
expect(end_time - start_time).to be < 10
|
185
190
|
end
|
186
191
|
|
187
|
-
it
|
192
|
+
it 'should check via the label if input is moved off the left edge of the page' do
|
188
193
|
expect(@session.find(:checkbox, 'form_cars_pagani', unchecked: true, visible: :all)).to be_truthy
|
189
194
|
@session.check('form_cars_pagani', allow_label_click: true)
|
190
195
|
@session.click_button('awesome')
|