capybara 3.36.0 → 3.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +20 -1
- data/README.md +1 -1
- data/lib/capybara/driver/node.rb +4 -0
- data/lib/capybara/dsl.rb +4 -10
- data/lib/capybara/minitest/spec.rb +2 -2
- data/lib/capybara/node/element.rb +12 -1
- data/lib/capybara/node/finders.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +20 -7
- data/lib/capybara/rack_test/browser.rb +41 -6
- data/lib/capybara/rack_test/driver.rb +4 -4
- data/lib/capybara/rack_test/node.rb +1 -1
- data/lib/capybara/registration_container.rb +0 -3
- data/lib/capybara/rspec/matchers/have_selector.rb +4 -4
- data/lib/capybara/rspec/matchers.rb +14 -14
- data/lib/capybara/selector/definition.rb +2 -1
- data/lib/capybara/selenium/driver.rb +6 -2
- data/lib/capybara/selenium/node.rb +12 -0
- data/lib/capybara/server/animation_disabler.rb +29 -17
- data/lib/capybara/session/config.rb +1 -1
- data/lib/capybara/session.rb +8 -21
- data/lib/capybara/spec/session/all_spec.rb +5 -7
- data/lib/capybara/spec/session/assert_text_spec.rb +17 -17
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +1 -1
- data/lib/capybara/spec/session/has_select_spec.rb +4 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +15 -0
- data/lib/capybara/spec/session/has_text_spec.rb +1 -5
- data/lib/capybara/spec/session/node_spec.rb +42 -0
- data/lib/capybara/spec/session/visit_spec.rb +14 -0
- data/lib/capybara/spec/session/window/window_spec.rb +1 -1
- data/lib/capybara/spec/test_app.rb +33 -0
- data/lib/capybara/spec/views/with_shadow.erb +31 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +1 -1
- data/lib/capybara.rb +1 -0
- data/spec/dsl_spec.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/rack_test_spec.rb +6 -0
- data/spec/result_spec.rb +27 -29
- data/spec/rspec/features_spec.rb +2 -2
- data/spec/rspec/scenarios_spec.rb +1 -1
- data/spec/sauce_spec_chrome.rb +3 -3
- data/spec/selector_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +1 -1
- data/spec/selenium_spec_firefox.rb +5 -1
- data/spec/selenium_spec_safari.rb +5 -1
- data/spec/server_spec.rb +5 -5
- data/spec/shared_selenium_session.rb +9 -2
- data/spec/spec_helper.rb +1 -1
- metadata +6 -4
@@ -3,16 +3,16 @@
|
|
3
3
|
Capybara::SpecHelper.spec '#assert_text' do
|
4
4
|
it 'should be true if the given text is on the page' do
|
5
5
|
@session.visit('/with_html')
|
6
|
-
expect(@session.assert_text('est')).to
|
7
|
-
expect(@session.assert_text('Lorem')).to
|
8
|
-
expect(@session.assert_text('Redirect')).to
|
9
|
-
expect(@session.assert_text(:Redirect)).to
|
10
|
-
expect(@session.assert_text('text with whitespace')).to
|
6
|
+
expect(@session.assert_text('est')).to be(true)
|
7
|
+
expect(@session.assert_text('Lorem')).to be(true)
|
8
|
+
expect(@session.assert_text('Redirect')).to be(true)
|
9
|
+
expect(@session.assert_text(:Redirect)).to be(true)
|
10
|
+
expect(@session.assert_text('text with whitespace')).to be(true)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should support collapsing whitespace' do
|
14
14
|
@session.visit('/with_html')
|
15
|
-
expect(@session.assert_text('text with whitespace', normalize_ws: true)).to
|
15
|
+
expect(@session.assert_text('text with whitespace', normalize_ws: true)).to be(true)
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with enabled default collapsing whitespace' do
|
@@ -20,19 +20,19 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
20
20
|
|
21
21
|
it 'should be true if the given unnormalized text is on the page' do
|
22
22
|
@session.visit('/with_html')
|
23
|
-
expect(@session.assert_text('text with whitespace', normalize_ws: false)).to
|
23
|
+
expect(@session.assert_text('text with whitespace', normalize_ws: false)).to be(true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should support collapsing whitespace' do
|
27
27
|
@session.visit('/with_html')
|
28
|
-
expect(@session.assert_text('text with whitespace')).to
|
28
|
+
expect(@session.assert_text('text with whitespace')).to be(true)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should take scopes into account' do
|
33
33
|
@session.visit('/with_html')
|
34
34
|
@session.within("//a[@title='awesome title']") do
|
35
|
-
expect(@session.assert_text('labore')).to
|
35
|
+
expect(@session.assert_text('labore')).to be(true)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -47,13 +47,13 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
47
47
|
|
48
48
|
it 'should be true if :all given and text is invisible.' do
|
49
49
|
@session.visit('/with_html')
|
50
|
-
expect(@session.assert_text(:all, 'Some of this text is hidden!')).to
|
50
|
+
expect(@session.assert_text(:all, 'Some of this text is hidden!')).to be(true)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should be true if `Capybara.ignore_hidden_elements = true` and text is invisible.' do
|
54
54
|
Capybara.ignore_hidden_elements = false
|
55
55
|
@session.visit('/with_html')
|
56
|
-
expect(@session.assert_text('Some of this text is hidden!')).to
|
56
|
+
expect(@session.assert_text('Some of this text is hidden!')).to be(true)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should raise error with a helpful message if the requested text is present but invisible' do
|
@@ -88,7 +88,7 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
88
88
|
|
89
89
|
it 'should be true if the text in the page matches given regexp' do
|
90
90
|
@session.visit('/with_html')
|
91
|
-
expect(@session.assert_text(/Lorem/)).to
|
91
|
+
expect(@session.assert_text(/Lorem/)).to be(true)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should raise error if the text in the page doesn't match given regexp" do
|
@@ -109,13 +109,13 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
109
109
|
Capybara.default_max_wait_time = 2
|
110
110
|
@session.visit('/with_js')
|
111
111
|
@session.click_link('Click me')
|
112
|
-
expect(@session.assert_text('Has been clicked')).to
|
112
|
+
expect(@session.assert_text('Has been clicked')).to be(true)
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'with between' do
|
116
116
|
it 'should be true if the text occurs within the range given' do
|
117
117
|
@session.visit('/with_count')
|
118
|
-
expect(@session.assert_text('count', between: 1..3)).to
|
118
|
+
expect(@session.assert_text('count', between: 1..3)).to be(true)
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should be false if the text occurs more or fewer times than range' do
|
@@ -203,13 +203,13 @@ Capybara::SpecHelper.spec '#assert_no_text' do
|
|
203
203
|
it 'should be true if scoped to an element which does not have the text' do
|
204
204
|
@session.visit('/with_html')
|
205
205
|
@session.within("//a[@title='awesome title']") do
|
206
|
-
expect(@session.assert_no_text('monkey')).to
|
206
|
+
expect(@session.assert_no_text('monkey')).to be(true)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should be true if the given text is on the page but not visible' do
|
211
211
|
@session.visit('/with_html')
|
212
|
-
expect(@session.assert_no_text('Inside element with hidden ancestor')).to
|
212
|
+
expect(@session.assert_no_text('Inside element with hidden ancestor')).to be(true)
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'should raise error if :all given and text is invisible.' do
|
@@ -236,7 +236,7 @@ Capybara::SpecHelper.spec '#assert_no_text' do
|
|
236
236
|
context 'with count' do
|
237
237
|
it 'should be true if the text occurs within the range given' do
|
238
238
|
@session.visit('/with_count')
|
239
|
-
expect(@session.assert_text('count', count: 2)).to
|
239
|
+
expect(@session.assert_text('count', count: 2)).to be(true)
|
240
240
|
end
|
241
241
|
|
242
242
|
it 'should be false if the text occurs more or fewer times than range' do
|
@@ -16,8 +16,8 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
16
16
|
|
17
17
|
it 'should not raise an error when non-http' do
|
18
18
|
@session.reset_session!
|
19
|
-
expect(@session.has_current_path?(/monkey/)).to
|
20
|
-
expect(@session.has_current_path?('/with_js')).to
|
19
|
+
expect(@session.has_current_path?(/monkey/)).to be false
|
20
|
+
expect(@session.has_current_path?('/with_js')).to be false
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should handle non-escaped query options' do
|
@@ -383,7 +383,7 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|
383
383
|
end
|
384
384
|
|
385
385
|
it 'should support locator-less usage' do
|
386
|
-
expect(@session.has_no_unchecked_field?(disabled: false, id: 'form_disabled_unchecked_checkbox')).to
|
386
|
+
expect(@session.has_no_unchecked_field?(disabled: false, id: 'form_disabled_unchecked_checkbox')).to be true
|
387
387
|
expect(@session).to have_no_unchecked_field(disabled: false, id: 'form_disabled_unchecked_checkbox')
|
388
388
|
end
|
389
389
|
end
|
@@ -180,9 +180,9 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should support locator-less usage' do
|
183
|
-
expect(@session.has_select?(with_options: %w[Norway Sweden])).to
|
183
|
+
expect(@session.has_select?(with_options: %w[Norway Sweden])).to be true
|
184
184
|
expect(@session).to have_select(with_options: ['London'])
|
185
|
-
expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to
|
185
|
+
expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to be true
|
186
186
|
expect(@session).to have_select(with_selected: ['Briefs'])
|
187
187
|
end
|
188
188
|
end
|
@@ -302,9 +302,9 @@ Capybara::SpecHelper.spec '#has_no_select?' do
|
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should support locator-less usage' do
|
305
|
-
expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to
|
305
|
+
expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to be true
|
306
306
|
expect(@session).to have_no_select(with_options: ['New London'])
|
307
|
-
expect(@session.has_no_select?(id: 'form_underwear', with_selected: ['Boxers'])).to
|
307
|
+
expect(@session.has_no_select?(id: 'form_underwear', with_selected: ['Boxers'])).to be true
|
308
308
|
expect(@session).to have_no_select(id: 'form_underwear', with_selected: %w[Commando Boxers])
|
309
309
|
end
|
310
310
|
end
|
@@ -117,6 +117,21 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|
117
117
|
expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test One', exact_text: false)
|
118
118
|
expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test', exact_text: false)
|
119
119
|
end
|
120
|
+
|
121
|
+
it 'should warn if text option is a regexp that it is ignoring exact_text' do
|
122
|
+
allow(Capybara::Helpers).to receive(:warn)
|
123
|
+
expect(@session).to have_selector(:id, 'h2one', text: /Class Test/, exact_text: true)
|
124
|
+
expect(Capybara::Helpers).to have_received(:warn).with(/'exact_text' option is not supported/)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'regexp' do
|
129
|
+
it 'should only match when it fully matches' do
|
130
|
+
expect(@session).to have_selector(:id, 'h2one', exact_text: /Header Class Test One/)
|
131
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Header Class Test/)
|
132
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test One/)
|
133
|
+
expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test/)
|
134
|
+
end
|
120
135
|
end
|
121
136
|
end
|
122
137
|
|
@@ -127,11 +127,7 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
127
127
|
def to_hash; { value: 'Other hash' } end
|
128
128
|
end.new
|
129
129
|
@session.visit('/with_html')
|
130
|
-
|
131
|
-
expect(@session).to have_text(:visible, with_to_hash, **{})
|
132
|
-
else
|
133
|
-
expect(@session).to have_text(:visible, with_to_hash, {})
|
134
|
-
end
|
130
|
+
expect(@session).to have_text(:visible, with_to_hash, **{})
|
135
131
|
end
|
136
132
|
end
|
137
133
|
|
@@ -1176,6 +1176,48 @@ Capybara::SpecHelper.spec 'node' do
|
|
1176
1176
|
end
|
1177
1177
|
end
|
1178
1178
|
|
1179
|
+
describe '#shadow_root', requires: %i[js] do
|
1180
|
+
it 'should get the shadow root' do
|
1181
|
+
@session.visit('/with_shadow')
|
1182
|
+
expect do
|
1183
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1184
|
+
expect(shadow_root).not_to be_nil
|
1185
|
+
end.not_to raise_error
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
it 'should find elements inside the shadow dom using CSS' do
|
1189
|
+
@session.visit('/with_shadow')
|
1190
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1191
|
+
expect(shadow_root).to have_css('#shadow_content', text: 'some text')
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
it 'should find nested shadow roots' do
|
1195
|
+
@session.visit('/with_shadow')
|
1196
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1197
|
+
nested_shadow_root = shadow_root.find(:css, '#nested_shadow_host').shadow_root
|
1198
|
+
expect(nested_shadow_root).to have_css('#nested_shadow_content', text: 'nested text')
|
1199
|
+
end
|
1200
|
+
|
1201
|
+
it 'should click on elements' do
|
1202
|
+
@session.visit('/with_shadow')
|
1203
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1204
|
+
checkbox = shadow_root.find(:css, 'input[type="checkbox"]')
|
1205
|
+
expect(checkbox).not_to be_checked
|
1206
|
+
checkbox.click
|
1207
|
+
expect(checkbox).to be_checked
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
it 'should use convenience methods once moved to a descendant of the shadow root' do
|
1211
|
+
@session.visit('/with_shadow')
|
1212
|
+
shadow_root = @session.find(:css, '#shadow_host').shadow_root
|
1213
|
+
descendant = shadow_root.find(:css, '#controls_wrapper')
|
1214
|
+
expect do
|
1215
|
+
descendant.check('shadow_checkbox')
|
1216
|
+
end.not_to raise_error
|
1217
|
+
expect(descendant).to have_checked_field('shadow_checkbox')
|
1218
|
+
end
|
1219
|
+
end
|
1220
|
+
|
1179
1221
|
describe '#reload', requires: [:js] do
|
1180
1222
|
it 'should reload elements found via ancestor with CSS' do
|
1181
1223
|
@session.visit('/with_js')
|
@@ -201,4 +201,18 @@ Capybara::SpecHelper.spec '#visit' do
|
|
201
201
|
@session.visit('/get_cookie')
|
202
202
|
expect(@session).to have_content('root cookie')
|
203
203
|
end
|
204
|
+
|
205
|
+
context 'with base element' do
|
206
|
+
it 'should use base href with relative links' do
|
207
|
+
@session.visit('/base/with_base')
|
208
|
+
@session.click_link('Title page')
|
209
|
+
expect(@session).to have_current_path('/with_title')
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should use base href with bare queries' do
|
213
|
+
@session.visit('/base/with_base')
|
214
|
+
@session.click_link('Bare query')
|
215
|
+
expect(@session).to have_current_path('/?a=3')
|
216
|
+
end
|
217
|
+
end
|
204
218
|
end
|
@@ -59,7 +59,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
59
59
|
it 'should return false if window is closed' do
|
60
60
|
@session.switch_to_window(other_window)
|
61
61
|
other_window.close
|
62
|
-
expect(other_window.current?).to
|
62
|
+
expect(other_window.current?).to be(false)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -177,6 +177,39 @@ class TestApp < Sinatra::Base
|
|
177
177
|
HTML
|
178
178
|
end
|
179
179
|
|
180
|
+
get '/base/with_base' do
|
181
|
+
<<-HTML
|
182
|
+
<!DOCTYPE html>
|
183
|
+
<html>
|
184
|
+
<head>
|
185
|
+
<base href="/">
|
186
|
+
<title>Origin</title>
|
187
|
+
</head>
|
188
|
+
<body>
|
189
|
+
<a href="with_title">Title page</a>
|
190
|
+
<a href="?a=3">Bare query</a>
|
191
|
+
</body>
|
192
|
+
</html>
|
193
|
+
HTML
|
194
|
+
end
|
195
|
+
|
196
|
+
get '/csp' do
|
197
|
+
response.headers['Content-Security-Policy'] = "default-src 'none'; connect-src 'self'; base-uri 'none'; font-src 'self'; img-src 'self' data:; object-src 'none'; script-src 'self' 'nonce-jAviMuMisoTisVXjgLoWdA=='; style-src 'self' 'nonce-jAviMuMisoTisVXjgLoWdA=='; form-action 'self';"
|
198
|
+
<<-HTML
|
199
|
+
<!DOCTYPE html>
|
200
|
+
<html lang="en">
|
201
|
+
<head>
|
202
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
203
|
+
<title>CSP</title>
|
204
|
+
</head>
|
205
|
+
|
206
|
+
<body>
|
207
|
+
<div>CSP</div>
|
208
|
+
</body>
|
209
|
+
</html>
|
210
|
+
HTML
|
211
|
+
end
|
212
|
+
|
180
213
|
get '/download.csv' do
|
181
214
|
content_type 'text/csv'
|
182
215
|
'This, is, comma, separated' \
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<%# Borrowed from Titus Fortner %>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6
|
+
<title>Shadow DOM</title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div id="no_host"></div>
|
10
|
+
<div id="shadow_host"></div>
|
11
|
+
<a href="scroll.html">scroll.html</a>
|
12
|
+
<script>
|
13
|
+
let shadowRoot = document.getElementById('shadow_host').attachShadow({mode: 'open'});
|
14
|
+
shadowRoot.innerHTML = `
|
15
|
+
<span class="wrapper" id="shadow_content"><span class="info">some text</span></span>
|
16
|
+
<div id="nested_shadow_host"></div>
|
17
|
+
<a href="scroll.html">scroll.html</a>
|
18
|
+
<div id="controls_wrapper">
|
19
|
+
<input type="text" />
|
20
|
+
<input type="checkbox" id="shadow_checkbox" />
|
21
|
+
<input type="file" />
|
22
|
+
</div>
|
23
|
+
`;
|
24
|
+
|
25
|
+
let nestedShadowRoot = shadowRoot.getElementById('nested_shadow_host').attachShadow({mode: 'open'});
|
26
|
+
nestedShadowRoot.innerHTML = `
|
27
|
+
<div id="nested_shadow_content"><div>nested text</div></div>
|
28
|
+
`;
|
29
|
+
</script>
|
30
|
+
</body>
|
31
|
+
</html>
|
data/lib/capybara/version.rb
CHANGED
data/lib/capybara/window.rb
CHANGED
data/lib/capybara.rb
CHANGED
@@ -96,6 +96,7 @@ module Capybara
|
|
96
96
|
# {Capybara::Session#save_and_open_page save_and_open_page}, or {Capybara::Session#save_and_open_screenshot save_and_open_screenshot}.
|
97
97
|
# - **server** (Symbol = `:default` (which uses puma)) - The name of the registered server to use when running the app under test.
|
98
98
|
# - **server_port** (Integer) - The port Capybara will run the application server on, if not specified a random port will be used.
|
99
|
+
# - **server_host** (String = "127.0.0.1") - The IP address Capybara will bind the application server to. If the test application is to be accessed from an external host, you will want to change this to "0.0.0.0" or to a more specific IP address that your test client can reach.
|
99
100
|
# - **server_errors** (Array\<Class> = `[Exception]`) - Error classes that should be raised in the tests if they are raised in the server
|
100
101
|
# and {configure raise_server_errors} is `true`.
|
101
102
|
# - **test_id** (Symbol, String, `nil` = `nil`) - Optional attribute to match locator against with built-in selectors along with id.
|
data/spec/dsl_spec.rb
CHANGED
@@ -115,7 +115,7 @@ RSpec.describe Capybara::DSL do
|
|
115
115
|
it 'should yield the passed block' do
|
116
116
|
called = false
|
117
117
|
Capybara.using_driver(:selenium) { called = true }
|
118
|
-
expect(called).to
|
118
|
+
expect(called).to be(true)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -220,7 +220,7 @@ RSpec.describe Capybara::DSL do
|
|
220
220
|
it 'should yield the passed block' do
|
221
221
|
called = false
|
222
222
|
Capybara.using_session(:administrator) { called = true }
|
223
|
-
expect(called).to
|
223
|
+
expect(called).to be(true)
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'should be nestable' do
|
@@ -5,9 +5,9 @@ require 'selenium-webdriver'
|
|
5
5
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a non-zero exit status' do
|
8
|
-
options = { browser: (
|
8
|
+
options = { browser: ENV.fetch('SELENIUM_BROWSER', :firefox).to_sym }
|
9
9
|
browser = described_class.new(TestApp, options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
|
-
expect(true).to
|
11
|
+
expect(true).to be(false) # rubocop:disable RSpec/ExpectActual
|
12
12
|
end
|
13
13
|
end
|
@@ -5,9 +5,9 @@ require 'selenium-webdriver'
|
|
5
5
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a zero exit status' do
|
8
|
-
options = { browser: (
|
8
|
+
options = { browser: ENV.fetch('SELENIUM_BROWSER', :firefox).to_sym }
|
9
9
|
browser = described_class.new(TestApp, **options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
|
-
expect(true).to
|
11
|
+
expect(true).to be(true) # rubocop:disable RSpec/ExpectActual,RSpec/IdenticalEqualityAssertion
|
12
12
|
end
|
13
13
|
end
|
data/spec/rack_test_spec.rb
CHANGED
@@ -216,6 +216,12 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
216
216
|
expect(driver.current_url).to match %r{/landed$}
|
217
217
|
end
|
218
218
|
|
219
|
+
it 'should not include fragments in the referer header' do
|
220
|
+
driver.visit('/header_links#an-anchor')
|
221
|
+
driver.find_xpath('.//input').first.click
|
222
|
+
expect(driver.request.get_header('HTTP_REFERER')).to eq('http://www.example.com/header_links')
|
223
|
+
end
|
224
|
+
|
219
225
|
it 'is possible to not follow redirects' do
|
220
226
|
driver = described_class.new(TestApp, follow_redirects: false)
|
221
227
|
|
data/spec/result_spec.rb
CHANGED
@@ -86,25 +86,23 @@ RSpec.describe Capybara::Result do
|
|
86
86
|
expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
89
|
+
it 'supports inclusive positive beginless ranges' do
|
90
|
+
expect(result[..2].map(&:text)).to eq %w[Alpha Beta Gamma]
|
91
|
+
end
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
it 'supports inclusive negative beginless ranges' do
|
94
|
+
expect(result[..-2].map(&:text)).to eq %w[Alpha Beta Gamma]
|
95
|
+
expect(result[..-1].map(&:text)).to eq %w[Alpha Beta Gamma Delta]
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
it 'supports exclusive positive beginless ranges' do
|
99
|
+
expect(result[...2].map(&:text)).to eq %w[Alpha Beta]
|
100
|
+
end
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
TEST
|
102
|
+
it 'supports exclusive negative beginless ranges' do
|
103
|
+
expect(result[...-2].map(&:text)).to eq %w[Alpha Beta]
|
104
|
+
expect(result[...-1].map(&:text)).to eq %w[Alpha Beta Gamma]
|
105
|
+
end
|
108
106
|
|
109
107
|
it 'works with filter blocks' do
|
110
108
|
result = string.all('//li') { |node| node.text == 'Alpha' }
|
@@ -115,52 +113,52 @@ RSpec.describe Capybara::Result do
|
|
115
113
|
it 'should evaluate filters lazily for idx' do
|
116
114
|
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
|
117
115
|
# Not processed until accessed
|
118
|
-
expect(result.instance_variable_get(
|
116
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 0
|
119
117
|
|
120
118
|
# Only one retrieved when needed
|
121
119
|
result.first
|
122
|
-
expect(result.instance_variable_get(
|
120
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 1
|
123
121
|
|
124
122
|
# works for indexed access
|
125
123
|
result[0]
|
126
|
-
expect(result.instance_variable_get(
|
124
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 1
|
127
125
|
|
128
126
|
result[2]
|
129
|
-
expect(result.instance_variable_get(
|
127
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 3
|
130
128
|
|
131
129
|
# All cached when converted to array
|
132
130
|
result.to_a
|
133
|
-
expect(result.instance_variable_get(
|
131
|
+
expect(result.instance_variable_get(:@result_cache).size).to eq 4
|
134
132
|
end
|
135
133
|
|
136
134
|
it 'should evaluate filters lazily for range' do
|
137
135
|
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
|
138
136
|
result[0..1]
|
139
|
-
expect(result.instance_variable_get(
|
137
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 2
|
140
138
|
|
141
139
|
expect(result[0..7].size).to eq 4
|
142
|
-
expect(result.instance_variable_get(
|
140
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 4
|
143
141
|
end
|
144
142
|
|
145
143
|
it 'should evaluate filters lazily for idx and length' do
|
146
144
|
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
|
147
145
|
result[1, 2]
|
148
|
-
expect(result.instance_variable_get(
|
146
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 3
|
149
147
|
|
150
148
|
expect(result[2, 5].size).to eq 2
|
151
|
-
expect(result.instance_variable_get(
|
149
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 4
|
152
150
|
end
|
153
151
|
|
154
152
|
it 'should only need to evaluate one result for any?' do
|
155
153
|
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
|
156
154
|
result.any?
|
157
|
-
expect(result.instance_variable_get(
|
155
|
+
expect(result.instance_variable_get(:@result_cache).size).to be 1
|
158
156
|
end
|
159
157
|
|
160
158
|
it 'should evaluate all elements when #to_a called' do
|
161
159
|
# All cached when converted to array
|
162
160
|
result.to_a
|
163
|
-
expect(result.instance_variable_get(
|
161
|
+
expect(result.instance_variable_get(:@result_cache).size).to eq 4
|
164
162
|
end
|
165
163
|
|
166
164
|
describe '#each' do
|
@@ -169,7 +167,7 @@ RSpec.describe Capybara::Result do
|
|
169
167
|
results = []
|
170
168
|
result.each do |el|
|
171
169
|
results << el
|
172
|
-
expect(result.instance_variable_get(
|
170
|
+
expect(result.instance_variable_get(:@result_cache).size).to eq results.size
|
173
171
|
end
|
174
172
|
|
175
173
|
expect(results.size).to eq 4
|
@@ -183,7 +181,7 @@ RSpec.describe Capybara::Result do
|
|
183
181
|
it 'lazily evaluates' do
|
184
182
|
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
|
185
183
|
result.each.with_index do |_el, idx|
|
186
|
-
expect(result.instance_variable_get(
|
184
|
+
expect(result.instance_variable_get(:@result_cache).size).to eq(idx + 1) # 0 indexing
|
187
185
|
end
|
188
186
|
end
|
189
187
|
end
|
data/spec/rspec/features_spec.rb
CHANGED
@@ -91,11 +91,11 @@ end
|
|
91
91
|
|
92
92
|
ffeature 'if ffeature aliases focused tag then' do # rubocop:disable RSpec/Focus
|
93
93
|
scenario 'scenario inside this feature has metatag focus tag' do |example|
|
94
|
-
expect(example.metadata[:focus]).to
|
94
|
+
expect(example.metadata[:focus]).to be true
|
95
95
|
end
|
96
96
|
|
97
97
|
scenario 'other scenarios also has metatag focus tag' do |example|
|
98
|
-
expect(example.metadata[:focus]).to
|
98
|
+
expect(example.metadata[:focus]).to be true
|
99
99
|
end
|
100
100
|
end
|
101
101
|
# rubocop:enable RSpec/RepeatedExample, RSpec/MultipleDescribes
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
feature 'if fscenario aliases focused tag then' do
|
13
13
|
fscenario 'scenario should have focused meta tag' do |example| # rubocop:disable RSpec/Focus
|
14
|
-
expect(example.metadata[:focus]).to
|
14
|
+
expect(example.metadata[:focus]).to be true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/spec/sauce_spec_chrome.rb
CHANGED
@@ -15,9 +15,9 @@ Capybara.register_driver :sauce_chrome do |app|
|
|
15
15
|
browser_name: 'chrome',
|
16
16
|
version: '65.0',
|
17
17
|
name: 'Capybara test',
|
18
|
-
build: ENV
|
19
|
-
username: ENV
|
20
|
-
access_key: ENV
|
18
|
+
build: ENV.fetch('TRAVIS_REPO_SLUG', "Ruby-RSpec-Selenium: Local-#{Time.now.to_i}"),
|
19
|
+
username: ENV.fetch('SAUCE_USERNAME', nil),
|
20
|
+
access_key: ENV.fetch('SAUCE_ACCESS_KEY', nil)
|
21
21
|
}
|
22
22
|
|
23
23
|
options.delete(:browser_name)
|
data/spec/selector_spec.rb
CHANGED
@@ -8,7 +8,7 @@ require 'rspec/shared_spec_matchers'
|
|
8
8
|
|
9
9
|
CHROME_DRIVER = :selenium_chrome
|
10
10
|
|
11
|
-
Selenium::WebDriver::Chrome.path = '/usr/bin/google-chrome-beta' if ENV
|
11
|
+
Selenium::WebDriver::Chrome.path = '/usr/bin/google-chrome-beta' if ENV.fetch('CI', nil) && ENV.fetch('CHROME_BETA', nil)
|
12
12
|
|
13
13
|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
14
14
|
browser_options.headless! if ENV['HEADLESS']
|
@@ -72,6 +72,10 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumFirefox, 'selenium', capyba
|
|
72
72
|
when 'Capybara::Session selenium #accept_alert should handle the alert if the page changes',
|
73
73
|
'Capybara::Session selenium #accept_alert with an asynchronous alert should accept the alert'
|
74
74
|
skip 'No clue what Firefox is doing here - works fine on MacOS locally'
|
75
|
+
when 'Capybara::Session selenium node #shadow_root should get the shadow root',
|
76
|
+
'Capybara::Session selenium node #shadow_root should find elements inside the shadow dom using CSS',
|
77
|
+
'Capybara::Session selenium node #shadow_root should find nested shadow roots'
|
78
|
+
pending "Firefox doesn't yet have W3C shadow root support"
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
@@ -103,7 +107,7 @@ RSpec.describe 'Capybara::Session with firefox' do # rubocop:disable RSpec/Multi
|
|
103
107
|
end
|
104
108
|
|
105
109
|
it 'should fill in a datetime input with a String' do
|
106
|
-
pending
|
110
|
+
pending 'Need to figure out what string format this will actually accept'
|
107
111
|
session.fill_in('form_datetime', with: datetime.iso8601)
|
108
112
|
session.click_button('awesome')
|
109
113
|
expect(Time.parse(extract_results(session)['datetime'])).to eq datetime
|