capybara 3.3.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +16 -0
- data/README.md +5 -7
- data/lib/capybara.rb +7 -6
- data/lib/capybara/config.rb +1 -1
- data/lib/capybara/dsl.rb +2 -2
- data/lib/capybara/helpers.rb +3 -3
- data/lib/capybara/minitest/spec.rb +3 -3
- data/lib/capybara/node/actions.rb +18 -18
- data/lib/capybara/node/base.rb +1 -1
- data/lib/capybara/node/element.rb +2 -2
- data/lib/capybara/node/finders.rb +6 -6
- data/lib/capybara/node/matchers.rb +5 -5
- data/lib/capybara/node/simple.rb +2 -2
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/base_query.rb +12 -11
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +39 -15
- data/lib/capybara/queries/sibling_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +7 -7
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +7 -7
- data/lib/capybara/rack_test/node.rb +16 -16
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/result.rb +8 -4
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matchers.rb +6 -6
- data/lib/capybara/selector.rb +106 -90
- data/lib/capybara/selector/css.rb +4 -4
- data/lib/capybara/selector/filter_set.rb +52 -8
- data/lib/capybara/selector/selector.rb +39 -15
- data/lib/capybara/selenium/driver.rb +10 -10
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -0
- data/lib/capybara/selenium/node.rb +9 -10
- data/lib/capybara/selenium/nodes/chrome_node.rb +18 -0
- data/lib/capybara/selenium/nodes/marionette_node.rb +32 -7
- data/lib/capybara/server.rb +3 -3
- data/lib/capybara/server/animation_disabler.rb +1 -1
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/session.rb +23 -19
- data/lib/capybara/session/config.rb +18 -3
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/accept_alert_spec.rb +10 -10
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
- data/lib/capybara/spec/session/all_spec.rb +33 -32
- data/lib/capybara/spec/session/ancestor_spec.rb +19 -19
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +38 -38
- data/lib/capybara/spec/session/assert_current_path_spec.rb +16 -16
- data/lib/capybara/spec/session/assert_selector_spec.rb +53 -53
- data/lib/capybara/spec/session/assert_style_spec.rb +3 -3
- data/lib/capybara/spec/session/assert_text_spec.rb +31 -30
- data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +51 -52
- data/lib/capybara/spec/session/body_spec.rb +6 -6
- data/lib/capybara/spec/session/check_spec.rb +52 -47
- data/lib/capybara/spec/session/choose_spec.rb +32 -32
- data/lib/capybara/spec/session/click_button_spec.rb +103 -103
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +24 -23
- data/lib/capybara/spec/session/click_link_spec.rb +49 -48
- data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
- data/lib/capybara/spec/session/current_url_spec.rb +26 -27
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
- data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
- data/lib/capybara/spec/session/element/match_css_spec.rb +10 -10
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +51 -51
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
- data/lib/capybara/spec/session/evaluate_script_spec.rb +15 -8
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -7
- data/lib/capybara/spec/session/fill_in_spec.rb +43 -42
- data/lib/capybara/spec/session/find_button_spec.rb +23 -23
- data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
- data/lib/capybara/spec/session/find_field_spec.rb +32 -30
- data/lib/capybara/spec/session/find_link_spec.rb +21 -21
- data/lib/capybara/spec/session/find_spec.rb +153 -135
- data/lib/capybara/spec/session/first_spec.rb +41 -41
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +17 -17
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +31 -17
- data/lib/capybara/spec/session/go_back_spec.rb +1 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_button_spec.rb +13 -13
- data/lib/capybara/spec/session/has_css_spec.rb +133 -131
- data/lib/capybara/spec/session/has_current_path_spec.rb +29 -29
- data/lib/capybara/spec/session/has_field_spec.rb +58 -58
- data/lib/capybara/spec/session/has_link_spec.rb +4 -4
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +24 -24
- data/lib/capybara/spec/session/has_select_spec.rb +43 -43
- data/lib/capybara/spec/session/has_selector_spec.rb +71 -71
- data/lib/capybara/spec/session/has_style_spec.rb +3 -3
- data/lib/capybara/spec/session/has_table_spec.rb +4 -4
- data/lib/capybara/spec/session/has_text_spec.rb +53 -52
- data/lib/capybara/spec/session/has_title_spec.rb +14 -14
- data/lib/capybara/spec/session/has_xpath_spec.rb +39 -38
- data/lib/capybara/spec/session/headers_spec.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +6 -6
- data/lib/capybara/spec/session/node_spec.rb +129 -123
- data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
- data/lib/capybara/spec/session/refresh_spec.rb +4 -7
- data/lib/capybara/spec/session/reset_session_spec.rb +28 -28
- data/lib/capybara/spec/session/response_code_spec.rb +1 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +37 -37
- data/lib/capybara/spec/session/save_screenshot_spec.rb +6 -6
- data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/select_spec.rb +81 -81
- data/lib/capybara/spec/session/selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/sibling_spec.rb +9 -9
- data/lib/capybara/spec/session/text_spec.rb +23 -23
- data/lib/capybara/spec/session/title_spec.rb +5 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +24 -20
- data/lib/capybara/spec/session/unselect_spec.rb +37 -37
- data/lib/capybara/spec/session/visit_spec.rb +48 -49
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -16
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -2
- data/lib/capybara/spec/session/window/window_spec.rb +4 -4
- data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
- data/lib/capybara/spec/session/within_spec.rb +41 -41
- data/lib/capybara/spec/spec_helper.rb +11 -9
- data/lib/capybara/spec/test_app.rb +18 -17
- data/lib/capybara/spec/views/form.erb +29 -31
- data/lib/capybara/spec/views/with_html.erb +2 -2
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +23 -23
- data/spec/capybara_spec.rb +20 -20
- data/spec/css_splitter_spec.rb +7 -7
- data/spec/dsl_spec.rb +37 -32
- data/spec/filter_set_spec.rb +4 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +4 -4
- data/spec/minitest_spec_spec.rb +23 -23
- data/spec/per_session_config_spec.rb +5 -5
- data/spec/rack_test_spec.rb +44 -44
- data/spec/result_spec.rb +14 -14
- data/spec/rspec/features_spec.rb +13 -13
- data/spec/rspec/scenarios_spec.rb +4 -4
- data/spec/rspec/shared_spec_matchers.rb +282 -281
- data/spec/rspec/views_spec.rb +3 -3
- data/spec/rspec_matchers_spec.rb +10 -10
- data/spec/rspec_spec.rb +29 -29
- data/spec/selector_spec.rb +64 -64
- data/spec/selenium_spec_chrome.rb +14 -22
- data/spec/selenium_spec_chrome_remote.rb +28 -8
- data/spec/selenium_spec_edge.rb +9 -4
- data/spec/selenium_spec_firefox_remote.rb +87 -0
- data/spec/selenium_spec_ie.rb +9 -4
- data/spec/selenium_spec_marionette.rb +42 -18
- data/spec/server_spec.rb +29 -27
- data/spec/session_spec.rb +17 -17
- data/spec/shared_selenium_session.rb +70 -52
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#response_headers' do
|
4
|
-
it
|
4
|
+
it 'should return response headers', requires: [:response_headers] do
|
5
5
|
@session.visit('/with_simple_html')
|
6
6
|
expect(@session.response_headers['Content-Type']).to match %r{text/html}
|
7
7
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#html' do
|
4
|
-
it
|
4
|
+
it 'should return the unmodified page body' do
|
5
5
|
@session.visit('/')
|
6
6
|
expect(@session.html).to include('Hello world!')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'should return the current state of the page', requires: [:js] do
|
10
10
|
@session.visit('/with_js')
|
11
11
|
expect(@session.html).to include('I changed it')
|
12
12
|
expect(@session.html).not_to include('This is text')
|
@@ -14,12 +14,12 @@ Capybara::SpecHelper.spec '#html' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Capybara::SpecHelper.spec '#source' do
|
17
|
-
it
|
17
|
+
it 'should return the unmodified page source' do
|
18
18
|
@session.visit('/')
|
19
19
|
expect(@session.source).to include('Hello world!')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should return the current state of the page', requires: [:js] do
|
23
23
|
@session.visit('/with_js')
|
24
24
|
expect(@session.source).to include('I changed it')
|
25
25
|
expect(@session.source).not_to include('This is text')
|
@@ -27,12 +27,12 @@ Capybara::SpecHelper.spec '#source' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
Capybara::SpecHelper.spec '#body' do
|
30
|
-
it
|
30
|
+
it 'should return the unmodified page source' do
|
31
31
|
@session.visit('/')
|
32
32
|
expect(@session.body).to include('Hello world!')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'should return the current state of the page', requires: [:js] do
|
36
36
|
@session.visit('/with_js')
|
37
37
|
expect(@session.body).to include('I changed it')
|
38
38
|
expect(@session.body).not_to include('This is text')
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Capybara::SpecHelper.spec
|
3
|
+
Capybara::SpecHelper.spec 'node' do
|
4
4
|
before do
|
5
5
|
@session.visit('/with_html')
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should act like a session object' do
|
9
9
|
@session.visit('/form')
|
10
10
|
@form = @session.find(:css, '#get-form')
|
11
11
|
expect(@form).to have_field('Middle Name')
|
@@ -15,70 +15,70 @@ Capybara::SpecHelper.spec "node" do
|
|
15
15
|
expect(extract_results(@session)['middle_name']).to eq('Monkey')
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'should scope CSS selectors' do
|
19
19
|
expect(@session.find(:css, '#second')).to have_no_css('h1')
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
it
|
22
|
+
describe '#query_scope' do
|
23
|
+
it 'should have a reference to the element the query was evaluated on if there is one' do
|
24
24
|
@node = @session.find(:css, '#first')
|
25
25
|
expect(@node.query_scope).to eq(@node.session.document)
|
26
26
|
expect(@node.find(:css, '#foo').query_scope).to eq(@node)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
it
|
30
|
+
describe '#text' do
|
31
|
+
it 'should extract node texts' do
|
32
32
|
expect(@session.all('//a')[0].text).to eq('labore')
|
33
33
|
expect(@session.all('//a')[1].text).to eq('ullamco')
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'should return document text on /html selector' do
|
37
37
|
@session.visit('/with_simple_html')
|
38
38
|
expect(@session.all('/html')[0].text).to eq('Bar')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
42
|
+
describe '#[]' do
|
43
|
+
it 'should extract node attributes' do
|
44
44
|
expect(@session.all('//a')[0][:class]).to eq('simple')
|
45
45
|
expect(@session.all('//a')[1][:id]).to eq('foo')
|
46
46
|
expect(@session.all('//input')[0][:type]).to eq('text')
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'should extract boolean node attributes' do
|
50
50
|
expect(@session.find('//input[@id="checked_field"]')[:checked]).to be_truthy
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
it
|
54
|
+
describe '#style', requires: [:css] do
|
55
|
+
it 'should return the computed style value' do
|
56
56
|
expect(@session.find(:css, '#first').style('display')).to eq('display' => 'block')
|
57
57
|
expect(@session.find(:css, '#second').style(:display)).to eq('display' => 'inline')
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
60
|
+
it 'should return multiple style values' do
|
61
61
|
expect(@session.find(:css, '#first').style('display', :'line-height')).to eq('display' => 'block', 'line-height' => '25px')
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
66
|
-
it
|
65
|
+
describe '#value' do
|
66
|
+
it 'should allow retrieval of the value' do
|
67
67
|
expect(@session.find('//textarea[@id="normal"]').value).to eq('banana')
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'should not swallow extra newlines in textarea' do
|
71
71
|
expect(@session.find('//textarea[@id="additional_newline"]').value).to eq("\nbanana")
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it 'should not swallow leading newlines for set content in textarea' do
|
75
75
|
@session.find('//textarea[@id="normal"]').set("\nbanana")
|
76
76
|
expect(@session.find('//textarea[@id="normal"]').value).to eq("\nbanana")
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
@session.find('//textarea[1]').set(
|
81
|
-
expect(@session.find('//textarea[1]').value).to eq(
|
79
|
+
it 'return any HTML content in textarea' do
|
80
|
+
@session.find('//textarea[1]').set('some <em>html</em> here')
|
81
|
+
expect(@session.find('//textarea[1]').value).to eq('some <em>html</em> here')
|
82
82
|
end
|
83
83
|
|
84
84
|
it "defaults to 'on' for checkbox" do
|
@@ -92,24 +92,24 @@ Capybara::SpecHelper.spec "node" do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
describe
|
96
|
-
it
|
95
|
+
describe '#set' do
|
96
|
+
it 'should allow assignment of field value' do
|
97
97
|
expect(@session.first('//input').value).to eq('monkey')
|
98
98
|
@session.first('//input').set('gorilla')
|
99
99
|
expect(@session.first('//input').value).to eq('gorilla')
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
102
|
+
it 'should fill the field even if the caret was not at the end', requires: [:js] do
|
103
103
|
@session.execute_script("var el = document.getElementById('test_field'); el.focus(); el.setSelectionRange(0, 0);")
|
104
104
|
@session.first('//input').set('')
|
105
105
|
expect(@session.first('//input').value).to eq('')
|
106
106
|
end
|
107
107
|
|
108
|
-
it
|
108
|
+
it 'should raise if the text field is readonly' do
|
109
109
|
expect { @session.first('//input[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError)
|
110
110
|
end
|
111
111
|
|
112
|
-
it
|
112
|
+
it 'should raise if the textarea is readonly' do
|
113
113
|
expect { @session.first('//textarea[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError)
|
114
114
|
end
|
115
115
|
|
@@ -121,7 +121,7 @@ Capybara::SpecHelper.spec "node" do
|
|
121
121
|
expect(element.base).to have_received(:set).with('gorilla', clear: :backspace)
|
122
122
|
end
|
123
123
|
|
124
|
-
context
|
124
|
+
context 'with a contenteditable element', requires: [:js] do
|
125
125
|
it 'should allow me to change the contents' do
|
126
126
|
@session.visit('/with_js')
|
127
127
|
@session.find(:css, '#existing_content_editable').set('WYSIWYG')
|
@@ -143,75 +143,81 @@ Capybara::SpecHelper.spec "node" do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
describe
|
147
|
-
it
|
146
|
+
describe '#tag_name' do
|
147
|
+
it 'should extract node tag name' do
|
148
148
|
expect(@session.all('//a')[0].tag_name).to eq('a')
|
149
149
|
expect(@session.all('//a')[1].tag_name).to eq('a')
|
150
150
|
expect(@session.all('//p')[1].tag_name).to eq('p')
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
describe
|
155
|
-
it
|
154
|
+
describe '#disabled?' do
|
155
|
+
it 'should extract disabled node' do
|
156
156
|
@session.visit('/form')
|
157
157
|
expect(@session.find('//input[@id="customer_name"]')).to be_disabled
|
158
158
|
expect(@session.find('//input[@id="customer_email"]')).not_to be_disabled
|
159
159
|
end
|
160
160
|
|
161
|
-
it
|
161
|
+
it 'should see disabled options as disabled' do
|
162
162
|
@session.visit('/form')
|
163
163
|
expect(@session.find('//select[@id="form_title"]/option[1]')).not_to be_disabled
|
164
164
|
expect(@session.find('//select[@id="form_title"]/option[@disabled]')).to be_disabled
|
165
165
|
end
|
166
166
|
|
167
|
-
it
|
167
|
+
it 'should see enabled options in disabled select as disabled' do
|
168
168
|
@session.visit('/form')
|
169
169
|
expect(@session.find('//select[@id="form_disabled_select"]/option')).to be_disabled
|
170
170
|
expect(@session.find('//select[@id="form_disabled_select"]/optgroup/option')).to be_disabled
|
171
171
|
expect(@session.find('//select[@id="form_title"]/option[1]')).not_to be_disabled
|
172
172
|
end
|
173
173
|
|
174
|
-
it
|
174
|
+
it 'should see enabled options in disabled optgroup as disabled' do
|
175
175
|
@session.visit('/form')
|
176
|
-
expect(@session.find('//option', text:
|
177
|
-
expect(@session.find('//option', text:
|
176
|
+
expect(@session.find('//option', text: 'A.B.1')).to be_disabled
|
177
|
+
expect(@session.find('//option', text: 'A.2')).not_to be_disabled
|
178
178
|
end
|
179
179
|
|
180
|
-
it
|
180
|
+
it 'should see a disabled fieldset as disabled' do
|
181
181
|
@session.visit('/form')
|
182
182
|
expect(@session.find(:css, '#form_disabled_fieldset')).to be_disabled
|
183
183
|
end
|
184
184
|
|
185
|
-
context
|
185
|
+
context 'in a disabled fieldset' do
|
186
186
|
# https://html.spec.whatwg.org/#the-fieldset-element
|
187
|
-
it
|
187
|
+
it 'should see elements not in first legend as disabled' do
|
188
188
|
@session.visit('/form')
|
189
189
|
expect(@session.find('//input[@id="form_disabled_fieldset_child"]')).to be_disabled
|
190
190
|
expect(@session.find('//input[@id="form_disabled_fieldset_second_legend_child"]')).to be_disabled
|
191
191
|
expect(@session.find('//input[@id="form_enabled_fieldset_child"]')).not_to be_disabled
|
192
192
|
end
|
193
193
|
|
194
|
-
it
|
194
|
+
it 'should see elements in first legend as enabled' do
|
195
195
|
@session.visit('/form')
|
196
196
|
expect(@session.find('//input[@id="form_disabled_fieldset_legend_child"]')).not_to be_disabled
|
197
197
|
end
|
198
198
|
|
199
|
-
it
|
199
|
+
it 'should sees options not in first legend as disabled' do
|
200
200
|
@session.visit('/form')
|
201
201
|
expect(@session.find('//option', text: 'Disabled Child Option')).to be_disabled
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
it
|
205
|
+
it 'should be boolean' do
|
206
206
|
@session.visit('/form')
|
207
207
|
expect(@session.find('//select[@id="form_disabled_select"]/option').disabled?).to be true
|
208
208
|
expect(@session.find('//select[@id="form_disabled_select2"]/option').disabled?).to be true
|
209
209
|
expect(@session.find('//select[@id="form_title"]/option[1]').disabled?).to be false
|
210
210
|
end
|
211
|
+
|
212
|
+
it 'should be disabled for all elements that are CSS :disabled' do
|
213
|
+
@session.visit('/form')
|
214
|
+
# sanity check
|
215
|
+
expect(@session.all(:css, ':disabled')).to all(be_disabled)
|
216
|
+
end
|
211
217
|
end
|
212
218
|
|
213
|
-
describe
|
214
|
-
it
|
219
|
+
describe '#visible?' do
|
220
|
+
it 'should extract node visibility' do
|
215
221
|
Capybara.ignore_hidden_elements = false
|
216
222
|
expect(@session.first('//a')).to be_visible
|
217
223
|
|
@@ -222,22 +228,22 @@ Capybara::SpecHelper.spec "node" do
|
|
222
228
|
expect(@session.find('//input[@id="hidden_input"]')).not_to be_visible
|
223
229
|
end
|
224
230
|
|
225
|
-
it
|
231
|
+
it 'should be boolean' do
|
226
232
|
Capybara.ignore_hidden_elements = false
|
227
233
|
expect(@session.first('//a').visible?).to be true
|
228
234
|
expect(@session.find('//div[@id="hidden"]').visible?).to be false
|
229
235
|
end
|
230
236
|
end
|
231
237
|
|
232
|
-
describe
|
233
|
-
it
|
238
|
+
describe '#checked?' do
|
239
|
+
it 'should extract node checked state' do
|
234
240
|
@session.visit('/form')
|
235
241
|
expect(@session.find('//input[@id="gender_female"]')).to be_checked
|
236
242
|
expect(@session.find('//input[@id="gender_male"]')).not_to be_checked
|
237
243
|
expect(@session.first('//h1')).not_to be_checked
|
238
244
|
end
|
239
245
|
|
240
|
-
it
|
246
|
+
it 'should be boolean' do
|
241
247
|
@session.visit('/form')
|
242
248
|
expect(@session.find('//input[@id="gender_female"]').checked?).to be true
|
243
249
|
expect(@session.find('//input[@id="gender_male"]').checked?).to be false
|
@@ -245,15 +251,15 @@ Capybara::SpecHelper.spec "node" do
|
|
245
251
|
end
|
246
252
|
end
|
247
253
|
|
248
|
-
describe
|
249
|
-
it
|
254
|
+
describe '#selected?' do
|
255
|
+
it 'should extract node selected state' do
|
250
256
|
@session.visit('/form')
|
251
257
|
expect(@session.find('//option[@value="en"]')).to be_selected
|
252
258
|
expect(@session.find('//option[@value="sv"]')).not_to be_selected
|
253
259
|
expect(@session.first('//h1')).not_to be_selected
|
254
260
|
end
|
255
261
|
|
256
|
-
it
|
262
|
+
it 'should be boolean' do
|
257
263
|
@session.visit('/form')
|
258
264
|
expect(@session.find('//option[@value="en"]').selected?).to be true
|
259
265
|
expect(@session.find('//option[@value="sv"]').selected?).to be false
|
@@ -261,33 +267,33 @@ Capybara::SpecHelper.spec "node" do
|
|
261
267
|
end
|
262
268
|
end
|
263
269
|
|
264
|
-
describe
|
265
|
-
it
|
270
|
+
describe '#==' do
|
271
|
+
it 'preserve object identity' do
|
266
272
|
expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/UselessComparison
|
267
273
|
expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/UselessComparison
|
268
274
|
expect(@session.find('//h1').eql?(@session.find('//h1'))).to be false
|
269
275
|
end
|
270
276
|
|
271
|
-
it
|
272
|
-
expect(@session.find('//h1') ==
|
277
|
+
it 'returns false for unrelated object' do
|
278
|
+
expect(@session.find('//h1') == 'Not Capybara::Node::Base').to be false
|
273
279
|
end
|
274
280
|
end
|
275
281
|
|
276
|
-
describe
|
282
|
+
describe '#path' do
|
277
283
|
# Testing for specific XPaths here doesn't make sense since there
|
278
284
|
# are many that can refer to the same element
|
279
285
|
before do
|
280
286
|
@session.visit('/path')
|
281
287
|
end
|
282
288
|
|
283
|
-
it
|
289
|
+
it 'returns xpath which points to itself' do
|
284
290
|
element = @session.find(:link, 'Second Link')
|
285
291
|
expect(@session.find(:xpath, element.path)).to eq(element)
|
286
292
|
end
|
287
293
|
end
|
288
294
|
|
289
|
-
describe
|
290
|
-
it
|
295
|
+
describe '#trigger', requires: %i[js trigger] do
|
296
|
+
it 'should allow triggering of custom JS events' do
|
291
297
|
@session.visit('/with_js')
|
292
298
|
@session.find(:css, '#with_focus_event').trigger(:focus)
|
293
299
|
expect(@session).to have_css('#focus_event_triggered')
|
@@ -295,7 +301,7 @@ Capybara::SpecHelper.spec "node" do
|
|
295
301
|
end
|
296
302
|
|
297
303
|
describe '#drag_to', requires: %i[js drag] do
|
298
|
-
it
|
304
|
+
it 'should drag and drop an object' do
|
299
305
|
@session.visit('/with_js')
|
300
306
|
element = @session.find('//div[@id="drag"]')
|
301
307
|
target = @session.find('//div[@id="drop"]')
|
@@ -303,7 +309,7 @@ Capybara::SpecHelper.spec "node" do
|
|
303
309
|
expect(@session.find('//div[contains(., "Dropped!")]')).not_to be_nil
|
304
310
|
end
|
305
311
|
|
306
|
-
it
|
312
|
+
it 'should drag and drop if scrolling is needed' do
|
307
313
|
@session.visit('/with_js')
|
308
314
|
element = @session.find('//div[@id="drag_scroll"]')
|
309
315
|
target = @session.find('//div[@id="drop_scroll"]')
|
@@ -313,14 +319,14 @@ Capybara::SpecHelper.spec "node" do
|
|
313
319
|
end
|
314
320
|
|
315
321
|
describe '#hover', requires: [:hover] do
|
316
|
-
it
|
322
|
+
it 'should allow hovering on an element' do
|
317
323
|
@session.visit('/with_hover')
|
318
324
|
expect(@session.find(:css, '.wrapper:not(.scroll_needed) .hidden_until_hover', visible: false)).not_to be_visible
|
319
325
|
@session.find(:css, '.wrapper:not(.scroll_needed)').hover
|
320
326
|
expect(@session.find(:css, '.wrapper:not(.scroll_needed) .hidden_until_hover', visible: false)).to be_visible
|
321
327
|
end
|
322
328
|
|
323
|
-
it
|
329
|
+
it 'should allow hovering on an element that needs to be scrolled into view' do
|
324
330
|
@session.visit('/with_hover')
|
325
331
|
expect(@session.find(:css, '.wrapper.scroll_needed .hidden_until_hover', visible: false)).not_to be_visible
|
326
332
|
@session.find(:css, '.wrapper.scroll_needed').hover
|
@@ -329,18 +335,18 @@ Capybara::SpecHelper.spec "node" do
|
|
329
335
|
end
|
330
336
|
|
331
337
|
describe '#click' do
|
332
|
-
it
|
338
|
+
it 'should not follow a link if no href' do
|
333
339
|
@session.find(:css, '#link_placeholder').click
|
334
340
|
expect(@session.current_url).to match(%r{/with_html$})
|
335
341
|
end
|
336
342
|
|
337
|
-
it
|
343
|
+
it 'should go to the same page if href is blank' do
|
338
344
|
@session.find(:css, '#link_blank_href').click
|
339
345
|
sleep 1
|
340
346
|
expect(@session).to have_current_path('/with_html')
|
341
347
|
end
|
342
348
|
|
343
|
-
it
|
349
|
+
it 'should be able to check a checkbox' do
|
344
350
|
@session.visit('form')
|
345
351
|
cbox = @session.find(:checkbox, 'form_terms_of_use')
|
346
352
|
expect(cbox).not_to be_checked
|
@@ -348,7 +354,7 @@ Capybara::SpecHelper.spec "node" do
|
|
348
354
|
expect(cbox).to be_checked
|
349
355
|
end
|
350
356
|
|
351
|
-
it
|
357
|
+
it 'should be able to uncheck a checkbox' do
|
352
358
|
@session.visit('/form')
|
353
359
|
cbox = @session.find(:checkbox, 'form_pets_dog')
|
354
360
|
expect(cbox).to be_checked
|
@@ -356,7 +362,7 @@ Capybara::SpecHelper.spec "node" do
|
|
356
362
|
expect(cbox).not_to be_checked
|
357
363
|
end
|
358
364
|
|
359
|
-
it
|
365
|
+
it 'should be able to select a radio button' do
|
360
366
|
@session.visit('/form')
|
361
367
|
radio = @session.find(:radio_button, 'gender_male')
|
362
368
|
expect(radio).not_to be_checked
|
@@ -364,20 +370,20 @@ Capybara::SpecHelper.spec "node" do
|
|
364
370
|
expect(radio).to be_checked
|
365
371
|
end
|
366
372
|
|
367
|
-
it
|
373
|
+
it 'should allow modifiers', requires: [:js] do
|
368
374
|
@session.visit('/with_js')
|
369
375
|
@session.find(:css, '#click-test').click(:shift)
|
370
376
|
expect(@session).to have_link('Has been shift clicked')
|
371
377
|
end
|
372
378
|
|
373
|
-
it
|
379
|
+
it 'should allow multiple modifiers', requires: [:js] do
|
374
380
|
@session.visit('with_js')
|
375
381
|
@session.find(:css, '#click-test').click(:control, :alt, :meta, :shift)
|
376
382
|
# Selenium with Chrome on OSX ctrl-click generates a right click so just verify all keys but not click type
|
377
|
-
expect(@session).to have_link(
|
383
|
+
expect(@session).to have_link('alt control meta shift')
|
378
384
|
end
|
379
385
|
|
380
|
-
it
|
386
|
+
it 'should allow to adjust the click offset', requires: [:js] do
|
381
387
|
@session.visit('with_js')
|
382
388
|
@session.find(:css, '#click-test').click(x: 5, y: 5)
|
383
389
|
link = @session.find(:link, 'has-been-clicked')
|
@@ -388,7 +394,7 @@ Capybara::SpecHelper.spec "node" do
|
|
388
394
|
expect(locations[:y].to_f).to be_within(1).of(5)
|
389
395
|
end
|
390
396
|
|
391
|
-
it
|
397
|
+
it 'should be able to click a table row', requires: [:js] do
|
392
398
|
@session.visit('/tables')
|
393
399
|
tr = @session.find(:css, '#agent_table tr:first-child').click
|
394
400
|
expect(tr).to have_css('label', text: 'Clicked')
|
@@ -396,23 +402,19 @@ Capybara::SpecHelper.spec "node" do
|
|
396
402
|
end
|
397
403
|
|
398
404
|
describe '#double_click', requires: [:js] do
|
399
|
-
|
400
|
-
pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should double click an element" do
|
405
|
+
it 'should double click an element' do
|
404
406
|
@session.visit('/with_js')
|
405
407
|
@session.find(:css, '#click-test').double_click
|
406
408
|
expect(@session.find(:css, '#has-been-double-clicked')).to be_truthy
|
407
409
|
end
|
408
410
|
|
409
|
-
it
|
411
|
+
it 'should allow modifiers', requires: [:js] do
|
410
412
|
@session.visit('/with_js')
|
411
413
|
@session.find(:css, '#click-test').double_click(:alt)
|
412
414
|
expect(@session).to have_link('Has been alt double clicked')
|
413
415
|
end
|
414
416
|
|
415
|
-
it
|
417
|
+
it 'should allow to adjust the offset', requires: [:js] do
|
416
418
|
@session.visit('with_js')
|
417
419
|
@session.find(:css, '#click-test').double_click(x: 10, y: 5)
|
418
420
|
link = @session.find(:link, 'has-been-double-clicked')
|
@@ -425,19 +427,19 @@ Capybara::SpecHelper.spec "node" do
|
|
425
427
|
end
|
426
428
|
|
427
429
|
describe '#right_click', requires: [:js] do
|
428
|
-
it
|
430
|
+
it 'should right click an element' do
|
429
431
|
@session.visit('/with_js')
|
430
432
|
@session.find(:css, '#click-test').right_click
|
431
433
|
expect(@session.find(:css, '#has-been-right-clicked')).to be_truthy
|
432
434
|
end
|
433
435
|
|
434
|
-
it
|
436
|
+
it 'should allow modifiers', requires: [:js] do
|
435
437
|
@session.visit('/with_js')
|
436
438
|
@session.find(:css, '#click-test').right_click(:meta)
|
437
439
|
expect(@session).to have_link('Has been meta right clicked')
|
438
440
|
end
|
439
441
|
|
440
|
-
it
|
442
|
+
it 'should allow to adjust the offset', requires: [:js] do
|
441
443
|
@session.visit('with_js')
|
442
444
|
@session.find(:css, '#click-test').right_click(x: 10, y: 10)
|
443
445
|
link = @session.find(:link, 'has-been-right-clicked')
|
@@ -450,96 +452,100 @@ Capybara::SpecHelper.spec "node" do
|
|
450
452
|
end
|
451
453
|
|
452
454
|
describe '#send_keys', requires: [:send_keys] do
|
453
|
-
it
|
455
|
+
it 'should send a string of keys to an element' do
|
454
456
|
@session.visit('/form')
|
455
457
|
@session.find(:css, '#address1_city').send_keys('Oceanside')
|
456
458
|
expect(@session.find(:css, '#address1_city').value).to eq 'Oceanside'
|
457
459
|
end
|
458
460
|
|
459
|
-
it
|
460
|
-
pending "selenium-webdriver/geckodriver doesn't support complex sets of characters" if marionette?(@session)
|
461
|
+
it 'should send special characters' do
|
461
462
|
@session.visit('/form')
|
462
463
|
@session.find(:css, '#address1_city').send_keys('Ocean', :space, 'sie', :left, 'd')
|
463
464
|
expect(@session.find(:css, '#address1_city').value).to eq 'Ocean side'
|
464
465
|
end
|
465
466
|
|
466
|
-
it
|
467
|
-
pending "selenium-webdriver/geckodriver doesn't support complex sets of characters" if marionette?(@session)
|
467
|
+
it 'should allow for multiple simultaneous keys' do
|
468
468
|
@session.visit('/form')
|
469
469
|
@session.find(:css, '#address1_city').send_keys([:shift, 'o'], 'ceanside')
|
470
470
|
expect(@session.find(:css, '#address1_city').value).to eq 'Oceanside'
|
471
471
|
end
|
472
472
|
|
473
|
-
it
|
474
|
-
pending "selenium-webdriver/geckodriver doesn't support complex sets of characters" if marionette?(@session)
|
473
|
+
it 'should generate key events', requires: %i[send_keys js] do
|
475
474
|
@session.visit('/with_js')
|
476
475
|
@session.find(:css, '#with-key-events').send_keys([:shift, 't'], [:shift, 'w'])
|
477
476
|
expect(@session.find(:css, '#key-events-output')).to have_text('keydown:16 keydown:84 keydown:16 keydown:87')
|
478
477
|
end
|
479
478
|
end
|
480
479
|
|
481
|
-
describe
|
482
|
-
it
|
480
|
+
describe '#execute_script', requires: %i[js es_args] do
|
481
|
+
it 'should execute the given script in the context of the element and return nothing' do
|
483
482
|
@session.visit('/with_js')
|
484
483
|
expect(@session.find(:css, '#change').execute_script("this.textContent = 'Funky Doodle'")).to be_nil
|
485
484
|
expect(@session).to have_css('#change', text: 'Funky Doodle')
|
486
485
|
end
|
487
486
|
|
488
|
-
it
|
487
|
+
it 'should pass arguments to the script' do
|
489
488
|
@session.visit('/with_js')
|
490
|
-
@session.find(:css, '#change').execute_script(
|
489
|
+
@session.find(:css, '#change').execute_script('this.textContent = arguments[0]', 'Doodle Funk')
|
491
490
|
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
492
491
|
end
|
493
492
|
end
|
494
493
|
|
495
|
-
describe
|
496
|
-
it
|
494
|
+
describe '#evaluate_script', requires: %i[js es_args] do
|
495
|
+
it 'should evaluate the given script in the context of the element and return whatever it produces' do
|
497
496
|
@session.visit('/with_js')
|
498
497
|
el = @session.find(:css, '#with_change_event')
|
499
|
-
expect(el.evaluate_script(
|
498
|
+
expect(el.evaluate_script('this.value')).to eq('default value')
|
499
|
+
end
|
500
|
+
|
501
|
+
it 'should ignore leading whitespace' do
|
502
|
+
@session.visit('/with_js')
|
503
|
+
expect(@session.find(:css, '#change').evaluate_script('
|
504
|
+
2 + 3
|
505
|
+
')).to eq 5
|
500
506
|
end
|
501
507
|
|
502
|
-
it
|
508
|
+
it 'should pass arguments to the script' do
|
503
509
|
@session.visit('/with_js')
|
504
|
-
@session.find(:css, '#change').evaluate_script(
|
510
|
+
@session.find(:css, '#change').evaluate_script('this.textContent = arguments[0]', 'Doodle Funk')
|
505
511
|
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
506
512
|
end
|
507
513
|
|
508
|
-
it
|
514
|
+
it 'should pass multiple arguments' do
|
509
515
|
@session.visit('/with_js')
|
510
516
|
change = @session.find(:css, '#change')
|
511
|
-
expect(change.evaluate_script(
|
517
|
+
expect(change.evaluate_script('arguments[0] + arguments[1]', 2, 3)).to eq 5
|
512
518
|
end
|
513
519
|
|
514
|
-
it
|
520
|
+
it 'should support returning elements' do
|
515
521
|
@session.visit('/with_js')
|
516
522
|
change = @session.find(:css, '#change') # ensure page has loaded and element is available
|
517
|
-
el = change.evaluate_script(
|
523
|
+
el = change.evaluate_script('this')
|
518
524
|
expect(el).to be_instance_of(Capybara::Node::Element)
|
519
525
|
expect(el).to eq(change)
|
520
526
|
end
|
521
527
|
end
|
522
528
|
|
523
|
-
describe
|
524
|
-
it
|
529
|
+
describe '#evaluate_async_script', requires: %i[js es_args] do
|
530
|
+
it 'should evaluate the given script in the context of the element' do
|
525
531
|
@session.visit('/with_js')
|
526
532
|
el = @session.find(:css, '#with_change_event')
|
527
|
-
expect(el.evaluate_async_script(
|
533
|
+
expect(el.evaluate_async_script('arguments[0](this.value)')).to eq('default value')
|
528
534
|
end
|
529
535
|
|
530
|
-
it
|
536
|
+
it 'should support returning elements after asynchronous operation' do
|
531
537
|
@session.visit('/with_js')
|
532
538
|
change = @session.find(:css, '#change') # ensure page has loaded and element is available
|
533
|
-
el = change.evaluate_async_script(
|
539
|
+
el = change.evaluate_async_script('var cb = arguments[0]; setTimeout(function(el){ cb(el) }, 100, this)')
|
534
540
|
expect(el).to eq(change)
|
535
541
|
end
|
536
542
|
end
|
537
543
|
|
538
544
|
describe '#reload', requires: [:js] do
|
539
|
-
context
|
545
|
+
context 'without automatic reload' do
|
540
546
|
before { Capybara.automatic_reload = false }
|
541
547
|
|
542
|
-
it
|
548
|
+
it 'should reload the current context of the node' do
|
543
549
|
@session.visit('/with_js')
|
544
550
|
node = @session.find(:css, '#reload-me')
|
545
551
|
@session.click_link('Reload!')
|
@@ -548,7 +554,7 @@ Capybara::SpecHelper.spec "node" do
|
|
548
554
|
expect(node.text).to eq('has been reloaded')
|
549
555
|
end
|
550
556
|
|
551
|
-
it
|
557
|
+
it 'should reload a parent node' do
|
552
558
|
@session.visit('/with_js')
|
553
559
|
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
554
560
|
@session.click_link('Reload!')
|
@@ -557,7 +563,7 @@ Capybara::SpecHelper.spec "node" do
|
|
557
563
|
expect(node.text).to eq('has been reloaded')
|
558
564
|
end
|
559
565
|
|
560
|
-
it
|
566
|
+
it 'should not automatically reload' do
|
561
567
|
@session.visit('/with_js')
|
562
568
|
node = @session.find(:css, '#reload-me')
|
563
569
|
@session.click_link('Reload!')
|
@@ -571,12 +577,12 @@ Capybara::SpecHelper.spec "node" do
|
|
571
577
|
after { Capybara.automatic_reload = true }
|
572
578
|
end
|
573
579
|
|
574
|
-
context
|
580
|
+
context 'with automatic reload' do
|
575
581
|
before do
|
576
582
|
Capybara.default_max_wait_time = 4
|
577
583
|
end
|
578
584
|
|
579
|
-
it
|
585
|
+
it 'should reload the current context of the node automatically' do
|
580
586
|
@session.visit('/with_js')
|
581
587
|
node = @session.find(:css, '#reload-me')
|
582
588
|
@session.click_link('Reload!')
|
@@ -584,7 +590,7 @@ Capybara::SpecHelper.spec "node" do
|
|
584
590
|
expect(node.text).to eq('has been reloaded')
|
585
591
|
end
|
586
592
|
|
587
|
-
it
|
593
|
+
it 'should reload a parent node automatically' do
|
588
594
|
@session.visit('/with_js')
|
589
595
|
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
590
596
|
@session.click_link('Reload!')
|
@@ -592,7 +598,7 @@ Capybara::SpecHelper.spec "node" do
|
|
592
598
|
expect(node.text).to eq('has been reloaded')
|
593
599
|
end
|
594
600
|
|
595
|
-
it
|
601
|
+
it 'should reload a node automatically when using find' do
|
596
602
|
@session.visit('/with_js')
|
597
603
|
node = @session.find(:css, '#reload-me')
|
598
604
|
@session.click_link('Reload!')
|
@@ -614,9 +620,9 @@ Capybara::SpecHelper.spec "node" do
|
|
614
620
|
end.to(raise_error { |error| expect(error).to be_an_invalid_element_error(@session) })
|
615
621
|
end
|
616
622
|
|
617
|
-
it
|
623
|
+
it 'should reload nodes with options' do
|
618
624
|
@session.visit('/with_js')
|
619
|
-
node = @session.find(:css, 'em', text:
|
625
|
+
node = @session.find(:css, 'em', text: 'reloaded')
|
620
626
|
@session.click_link('Reload!')
|
621
627
|
sleep(1)
|
622
628
|
expect(node.text).to eq('has been reloaded')
|
@@ -624,9 +630,9 @@ Capybara::SpecHelper.spec "node" do
|
|
624
630
|
end
|
625
631
|
end
|
626
632
|
|
627
|
-
context
|
628
|
-
it
|
629
|
-
quietly { @session.visit(
|
633
|
+
context 'when #synchronize raises server errors' do
|
634
|
+
it 'sets an explanatory exception as the cause of server exceptions', requires: %i[server js] do
|
635
|
+
quietly { @session.visit('/error') }
|
630
636
|
expect do
|
631
637
|
@session.find(:css, 'span')
|
632
638
|
end.to(raise_error(TestApp::TestAppError) do |e|
|
@@ -635,8 +641,8 @@ Capybara::SpecHelper.spec "node" do
|
|
635
641
|
end)
|
636
642
|
end
|
637
643
|
|
638
|
-
it
|
639
|
-
quietly { @session.visit(
|
644
|
+
it 'sets an explanatory exception as the cause of server exceptions with errors with initializers', requires: %i[server js] do
|
645
|
+
quietly { @session.visit('/other_error') }
|
640
646
|
expect do
|
641
647
|
@session.find(:css, 'span')
|
642
648
|
end.to(raise_error(TestApp::TestAppOtherError) do |e|
|