capybara 3.23.0 → 3.35.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +264 -11
- data/README.md +10 -6
- data/lib/capybara.rb +20 -8
- data/lib/capybara/config.rb +10 -8
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/driver/node.rb +4 -0
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +28 -2
- data/lib/capybara/minitest.rb +232 -144
- data/lib/capybara/minitest/spec.rb +156 -97
- data/lib/capybara/node/actions.rb +36 -36
- data/lib/capybara/node/base.rb +6 -6
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +77 -33
- data/lib/capybara/node/finders.rb +24 -17
- data/lib/capybara/node/matchers.rb +79 -64
- data/lib/capybara/node/simple.rb +11 -4
- data/lib/capybara/queries/ancestor_query.rb +6 -10
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/current_path_query.rb +14 -4
- data/lib/capybara/queries/selector_query.rb +259 -23
- data/lib/capybara/queries/sibling_query.rb +5 -11
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/rack_test/browser.rb +13 -4
- data/lib/capybara/rack_test/driver.rb +2 -1
- data/lib/capybara/rack_test/form.rb +2 -2
- data/lib/capybara/rack_test/node.rb +42 -6
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +18 -12
- data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
- data/lib/capybara/registrations/servers.rb +9 -2
- data/lib/capybara/result.rb +39 -19
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/rspec/matcher_proxies.rb +5 -5
- data/lib/capybara/rspec/matchers.rb +97 -74
- data/lib/capybara/rspec/matchers/base.rb +19 -6
- data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
- data/lib/capybara/rspec/matchers/have_ancestor.rb +5 -7
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +15 -10
- data/lib/capybara/rspec/matchers/have_sibling.rb +4 -7
- data/lib/capybara/rspec/matchers/have_text.rb +4 -7
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +7 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/selector.rb +46 -19
- data/lib/capybara/selector/builders/css_builder.rb +10 -6
- data/lib/capybara/selector/builders/xpath_builder.rb +4 -2
- data/lib/capybara/selector/css.rb +1 -1
- data/lib/capybara/selector/definition.rb +13 -11
- data/lib/capybara/selector/definition/button.rb +32 -15
- data/lib/capybara/selector/definition/checkbox.rb +2 -2
- data/lib/capybara/selector/definition/css.rb +3 -1
- data/lib/capybara/selector/definition/datalist_input.rb +2 -2
- data/lib/capybara/selector/definition/datalist_option.rb +1 -1
- data/lib/capybara/selector/definition/element.rb +3 -2
- data/lib/capybara/selector/definition/field.rb +1 -1
- data/lib/capybara/selector/definition/file_field.rb +1 -1
- data/lib/capybara/selector/definition/fillable_field.rb +2 -2
- data/lib/capybara/selector/definition/label.rb +5 -3
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/option.rb +1 -1
- data/lib/capybara/selector/definition/radio_button.rb +2 -2
- data/lib/capybara/selector/definition/select.rb +33 -14
- data/lib/capybara/selector/definition/table.rb +6 -3
- data/lib/capybara/selector/definition/table_row.rb +2 -2
- data/lib/capybara/selector/filter_set.rb +13 -11
- data/lib/capybara/selector/filters/base.rb +6 -1
- data/lib/capybara/selector/filters/locator_filter.rb +1 -1
- data/lib/capybara/selector/regexp_disassembler.rb +7 -0
- data/lib/capybara/selector/selector.rb +13 -3
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -1
- data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +10 -10
- data/lib/capybara/selenium/driver.rb +86 -24
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +24 -21
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +21 -19
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +17 -1
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +0 -4
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +37 -26
- data/lib/capybara/selenium/extensions/html5_drag.rb +55 -11
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/logger_suppressor.rb +8 -2
- data/lib/capybara/selenium/node.rb +160 -40
- data/lib/capybara/selenium/nodes/chrome_node.rb +72 -12
- data/lib/capybara/selenium/nodes/edge_node.rb +32 -14
- data/lib/capybara/selenium/nodes/firefox_node.rb +28 -32
- data/lib/capybara/selenium/nodes/safari_node.rb +5 -29
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +4 -4
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +32 -7
- data/lib/capybara/server.rb +19 -3
- data/lib/capybara/server/animation_disabler.rb +8 -3
- data/lib/capybara/server/checker.rb +1 -1
- data/lib/capybara/server/middleware.rb +22 -10
- data/lib/capybara/session.rb +66 -40
- data/lib/capybara/session/config.rb +11 -3
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +75 -7
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
- data/lib/capybara/spec/session/all_spec.rb +60 -5
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/check_spec.rb +6 -0
- data/lib/capybara/spec/session/click_button_spec.rb +16 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
- data/lib/capybara/spec/session/current_url_spec.rb +11 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
- data/lib/capybara/spec/session/find_spec.rb +55 -0
- data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -0
- data/lib/capybara/spec/session/has_button_spec.rb +51 -0
- data/lib/capybara/spec/session/has_css_spec.rb +26 -4
- data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
- data/lib/capybara/spec/session/has_field_spec.rb +34 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +30 -0
- data/lib/capybara/spec/session/html_spec.rb +1 -1
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +394 -9
- data/lib/capybara/spec/session/refresh_spec.rb +2 -1
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +4 -4
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -15
- data/lib/capybara/spec/session/selectors_spec.rb +16 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +8 -8
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/spec_helper.rb +14 -14
- data/lib/capybara/spec/test_app.rb +27 -21
- data/lib/capybara/spec/views/form.erb +47 -4
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/with_animation.erb +37 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_html.erb +24 -2
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +4 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +3 -7
- data/spec/basic_node_spec.rb +15 -14
- data/spec/capybara_spec.rb +28 -28
- data/spec/dsl_spec.rb +16 -3
- data/spec/filter_set_spec.rb +5 -5
- 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 +3 -2
- data/spec/minitest_spec_spec.rb +46 -46
- data/spec/rack_test_spec.rb +38 -15
- data/spec/regexp_dissassembler_spec.rb +52 -38
- data/spec/result_spec.rb +43 -32
- data/spec/rspec/features_spec.rb +4 -1
- data/spec/rspec/scenarios_spec.rb +4 -0
- data/spec/rspec/shared_spec_matchers.rb +68 -56
- data/spec/rspec_spec.rb +9 -5
- data/spec/selector_spec.rb +32 -17
- data/spec/selenium_spec_chrome.rb +78 -11
- data/spec/selenium_spec_chrome_remote.rb +23 -6
- data/spec/selenium_spec_edge.rb +15 -12
- data/spec/selenium_spec_firefox.rb +24 -19
- data/spec/selenium_spec_firefox_remote.rb +0 -8
- data/spec/selenium_spec_ie.rb +1 -6
- data/spec/server_spec.rb +106 -44
- data/spec/session_spec.rb +5 -5
- data/spec/shared_selenium_node.rb +56 -2
- data/spec/shared_selenium_session.rb +122 -15
- data/spec/spec_helper.rb +2 -2
- metadata +63 -17
- data/lib/capybara/spec/session/source_spec.rb +0 -0
@@ -1,21 +1,57 @@
|
|
1
1
|
var activeRequests = 0;
|
2
2
|
$(function() {
|
3
3
|
$('#change').text('I changed it');
|
4
|
-
$('#drag, #drag_scroll, #drag_link').draggable(
|
4
|
+
$('#drag, #drag_scroll, #drag_link').draggable({
|
5
|
+
start: function(event, ui){
|
6
|
+
$(document.body).append(
|
7
|
+
"<div class='drag_start'>Dragged!" +
|
8
|
+
(event.altKey ? "-alt" : "") +
|
9
|
+
(event.ctrlKey ? "-ctrl" : "") +
|
10
|
+
(event.metaKey ? "-meta" : "") +
|
11
|
+
(event.shiftKey ? "-shift" : "") +
|
12
|
+
"</div>"
|
13
|
+
);
|
14
|
+
}
|
15
|
+
});
|
5
16
|
$('#drop, #drop_scroll').droppable({
|
6
17
|
tolerance: 'touch',
|
7
18
|
drop: function(event, ui) {
|
8
19
|
ui.draggable.remove();
|
9
|
-
$(this).html(
|
20
|
+
$(this).html(
|
21
|
+
"Dropped!" +
|
22
|
+
(event.altKey ? "-alt" : "") +
|
23
|
+
(event.ctrlKey ? "-ctrl" : "") +
|
24
|
+
(event.metaKey ? "-meta" : "") +
|
25
|
+
(event.shiftKey ? "-shift" : "")
|
26
|
+
);
|
10
27
|
}
|
11
28
|
});
|
12
29
|
$('#drag_html5, #drag_html5_scroll').on('dragstart', function(ev){
|
30
|
+
$(document.body).append(
|
31
|
+
"<div class='drag_start'>HTML5 Dragged!" +
|
32
|
+
(event.altKey ? "-alt" : "") +
|
33
|
+
(event.ctrlKey ? "-ctrl" : "") +
|
34
|
+
(event.metaKey ? "-meta" : "") +
|
35
|
+
(event.shiftKey ? "-shift" : "") +
|
36
|
+
"</div>"
|
37
|
+
);
|
13
38
|
ev.originalEvent.dataTransfer.setData("text", ev.target.id);
|
14
39
|
});
|
40
|
+
$('#drag_html5, #drag_html5_scroll').on('dragend', function(ev){
|
41
|
+
$(this).after('<div class="log">DragEnd with client position: ' + ev.clientX + ',' + ev.clientY)
|
42
|
+
});
|
15
43
|
$('#drop_html5, #drop_html5_scroll').on('dragover', function(ev){
|
16
44
|
$(this).after('<div class="log">DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
|
17
45
|
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
18
46
|
});
|
47
|
+
$('#drop_html5, #drop_html5_scroll').on('dragleave', function(ev){
|
48
|
+
$(this).after('<div class="log">DragLeave with client position: ' + ev.clientX + ',' + ev.clientY)
|
49
|
+
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
50
|
+
});
|
51
|
+
$('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
|
52
|
+
$(this).after('<div class="log">Drop with client position: ' + ev.clientX + ',' + ev.clientY)
|
53
|
+
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
54
|
+
});
|
19
55
|
$('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
|
20
56
|
ev.preventDefault();
|
21
57
|
var oev = ev.originalEvent;
|
@@ -27,10 +63,19 @@ $(function() {
|
|
27
63
|
$(this).append('HTML5 Dropped file: ' + file.name);
|
28
64
|
} else {
|
29
65
|
var _this = this;
|
30
|
-
var callback = (function(type){
|
31
|
-
return function(s){
|
32
|
-
$(_this).append(
|
33
|
-
|
66
|
+
var callback = (function(type) {
|
67
|
+
return function(s) {
|
68
|
+
$(_this).append(
|
69
|
+
"HTML5 Dropped string: " +
|
70
|
+
type +
|
71
|
+
" " +
|
72
|
+
s +
|
73
|
+
(ev.altKey ? "-alt" : "") +
|
74
|
+
(ev.ctrlKey ? "-ctrl" : "") +
|
75
|
+
(ev.metaKey ? "-meta" : "") +
|
76
|
+
(ev.shiftKey ? "-shift" : "")
|
77
|
+
);
|
78
|
+
};
|
34
79
|
})(item.type);
|
35
80
|
item.getAsString(callback);
|
36
81
|
}
|
@@ -63,6 +108,13 @@ $(function() {
|
|
63
108
|
}, 4000);
|
64
109
|
return false;
|
65
110
|
});
|
111
|
+
$('#aria-button').click(function() {
|
112
|
+
var span = $(this);
|
113
|
+
setTimeout(function() {
|
114
|
+
$(span).after('<span role="button">ARIA button has been clicked</span>')
|
115
|
+
}, 1000);
|
116
|
+
return false;
|
117
|
+
});
|
66
118
|
$('#waiter').change(function() {
|
67
119
|
activeRequests = 1;
|
68
120
|
setTimeout(function() {
|
@@ -108,6 +160,7 @@ $(function() {
|
|
108
160
|
});
|
109
161
|
$('#click-test').on({
|
110
162
|
click: function(e) {
|
163
|
+
window.click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
|
111
164
|
var desc = "";
|
112
165
|
if (e.altKey) desc += 'alt ';
|
113
166
|
if (e.ctrlKey) desc += 'control ';
|
@@ -134,6 +187,16 @@ $(function() {
|
|
134
187
|
if (e.shiftKey) desc += 'shift ';
|
135
188
|
var pos = this.getBoundingClientRect();
|
136
189
|
$(this).after('<a id="has-been-right-clicked" href="#">Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
|
190
|
+
},
|
191
|
+
mousedown: function(e) {
|
192
|
+
window.click_delay = undefined;
|
193
|
+
window.right_click_delay = undefined;
|
194
|
+
window.mouse_down_time = new Date().getTime();
|
195
|
+
},
|
196
|
+
mouseup: function(e) {
|
197
|
+
if (e.button == 2){
|
198
|
+
window.right_click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
|
199
|
+
}
|
137
200
|
}
|
138
201
|
});
|
139
202
|
$('#open-alert').click(function() {
|
@@ -208,5 +271,10 @@ $(function() {
|
|
208
271
|
});
|
209
272
|
$('#multiple-file, #hidden_file').change(function(e){
|
210
273
|
$('body').append($('<p class="file_change">File input changed</p>'));
|
211
|
-
})
|
274
|
+
});
|
275
|
+
|
276
|
+
var shadow = document.querySelector('#shadow').attachShadow({mode: 'open'});
|
277
|
+
var span = document.createElement('span');
|
278
|
+
span.textContent = 'The things we do in the shadows';
|
279
|
+
shadow.appendChild(span);
|
212
280
|
});
|
@@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
|
|
53
53
|
@session.click_link('Alert page change')
|
54
54
|
sleep 1 # ensure page change occurs before the accept_alert block exits
|
55
55
|
end
|
56
|
-
expect(@session).to have_current_path('/with_html')
|
56
|
+
expect(@session).to have_current_path('/with_html', wait: 5)
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'with an asynchronous alert' do
|
@@ -36,10 +36,50 @@ Capybara::SpecHelper.spec '#all' do
|
|
36
36
|
expect(@result).to include('Smith', 'John', 'John Smith')
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'should allow reversing the order' do
|
40
|
+
@session.visit('/form')
|
41
|
+
fields = @session.all(:fillable_field, 'Name', exact: false).to_a
|
42
|
+
reverse_fields = @session.all(:fillable_field, 'Name', order: :reverse, exact: false).to_a
|
43
|
+
expect(fields).to eq(reverse_fields.reverse)
|
44
|
+
end
|
45
|
+
|
39
46
|
it 'should raise an error when given invalid options' do
|
40
47
|
expect { @session.all('//p', schmoo: 'foo') }.to raise_error(ArgumentError)
|
41
48
|
end
|
42
49
|
|
50
|
+
it 'should not reload by default', requires: [:driver] do
|
51
|
+
paras = @session.all(:css, 'p', minimum: 3)
|
52
|
+
expect { paras[0].text }.not_to raise_error
|
53
|
+
@session.refresh
|
54
|
+
expect { paras[0].text }.to raise_error do |err|
|
55
|
+
expect(err).to be_an_invalid_element_error(@session)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with allow_reload' do
|
60
|
+
it 'should reload if true' do
|
61
|
+
paras = @session.all(:css, 'p', allow_reload: true, minimum: 3)
|
62
|
+
expect { paras[0].text }.not_to raise_error
|
63
|
+
@session.refresh
|
64
|
+
sleep 1 # Ensure page has started to reload
|
65
|
+
expect(paras[0]).to have_text('Lorem ipsum dolor')
|
66
|
+
expect(paras[1]).to have_text('Duis aute irure dolor')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should not reload if false', requires: [:driver] do
|
70
|
+
paras = @session.all(:css, 'p', allow_reload: false, minimum: 3)
|
71
|
+
expect { paras[0].text }.not_to raise_error
|
72
|
+
@session.refresh
|
73
|
+
sleep 1 # Ensure page has started to reload
|
74
|
+
expect { paras[0].text }.to raise_error do |err|
|
75
|
+
expect(err).to be_an_invalid_element_error(@session)
|
76
|
+
end
|
77
|
+
expect { paras[2].text }.to raise_error do |err|
|
78
|
+
expect(err).to be_an_invalid_element_error(@session)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
43
83
|
context 'with css selectors' do
|
44
84
|
it 'should find all elements using the given selector' do
|
45
85
|
expect(@session.all(:css, 'h1').first.text).to eq('This is a test')
|
@@ -128,6 +168,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
128
168
|
it 'should succeed when the number of elements founds matches the expectation' do
|
129
169
|
expect { @session.all(:css, 'h1, p', count: 4) }.not_to raise_error
|
130
170
|
end
|
171
|
+
|
131
172
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
132
173
|
expect { @session.all(:css, 'h1, p', count: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
133
174
|
end
|
@@ -137,6 +178,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
137
178
|
it 'should succeed when the number of elements founds matches the expectation' do
|
138
179
|
expect { @session.all(:css, 'h1, p', minimum: 0) }.not_to raise_error
|
139
180
|
end
|
181
|
+
|
140
182
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
141
183
|
expect { @session.all(:css, 'h1, p', minimum: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
142
184
|
end
|
@@ -146,6 +188,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
146
188
|
it 'should succeed when the number of elements founds matches the expectation' do
|
147
189
|
expect { @session.all(:css, 'h1, p', maximum: 4) }.not_to raise_error
|
148
190
|
end
|
191
|
+
|
149
192
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
150
193
|
expect { @session.all(:css, 'h1, p', maximum: 0) }.to raise_error(Capybara::ExpectationNotMet)
|
151
194
|
end
|
@@ -155,6 +198,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
155
198
|
it 'should succeed when the number of elements founds matches the expectation' do
|
156
199
|
expect { @session.all(:css, 'h1, p', between: 2..7) }.not_to raise_error
|
157
200
|
end
|
201
|
+
|
158
202
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
159
203
|
expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
|
160
204
|
end
|
@@ -165,6 +209,13 @@ Capybara::SpecHelper.spec '#all' do
|
|
165
209
|
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
|
166
210
|
end
|
167
211
|
TEST
|
212
|
+
|
213
|
+
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
|
214
|
+
it'treats a beginless range as maximum' do
|
215
|
+
expect { @session.all(:css, 'h1, p', between: ..7) }.not_to raise_error
|
216
|
+
expect { @session.all(:css, 'h1, p', between: ..3) }.to raise_error(Capybara::ExpectationNotMet)
|
217
|
+
end
|
218
|
+
TEST
|
168
219
|
end
|
169
220
|
|
170
221
|
context 'with multiple count filters' do
|
@@ -173,32 +224,36 @@ Capybara::SpecHelper.spec '#all' do
|
|
173
224
|
minimum: 5,
|
174
225
|
maximum: 0,
|
175
226
|
between: 0..3 }
|
176
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
227
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
177
228
|
end
|
229
|
+
|
178
230
|
context 'with no :count expectation' do
|
179
231
|
it 'fails if :minimum is not met' do
|
180
232
|
o = { minimum: 5,
|
181
233
|
maximum: 4,
|
182
234
|
between: 2..7 }
|
183
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
235
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
184
236
|
end
|
237
|
+
|
185
238
|
it 'fails if :maximum is not met' do
|
186
239
|
o = { minimum: 0,
|
187
240
|
maximum: 0,
|
188
241
|
between: 2..7 }
|
189
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
242
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
190
243
|
end
|
244
|
+
|
191
245
|
it 'fails if :between is not met' do
|
192
246
|
o = { minimum: 0,
|
193
247
|
maximum: 4,
|
194
248
|
between: 0..3 }
|
195
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
249
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
196
250
|
end
|
251
|
+
|
197
252
|
it 'succeeds if all combineable expectations are met' do
|
198
253
|
o = { minimum: 0,
|
199
254
|
maximum: 4,
|
200
255
|
between: 2..7 }
|
201
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
256
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
202
257
|
end
|
203
258
|
end
|
204
259
|
end
|
@@ -20,6 +20,11 @@ Capybara::SpecHelper.spec '#ancestor' do
|
|
20
20
|
expect(el.ancestor('//div', text: "Ancestor\nAncestor\nAncestor")[:id]).to eq('ancestor3')
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'should find the closest ancestor' do
|
24
|
+
el = @session.find(:css, '#child')
|
25
|
+
expect(el.ancestor('.//div', order: :reverse, match: :first)[:id]).to eq('ancestor1')
|
26
|
+
end
|
27
|
+
|
23
28
|
it 'should raise an error if there are multiple matches' do
|
24
29
|
el = @session.find(:css, '#child')
|
25
30
|
expect { el.ancestor('//div') }.to raise_error(Capybara::Ambiguous)
|
@@ -157,32 +157,36 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
157
157
|
minimum: 6,
|
158
158
|
maximum: 0,
|
159
159
|
between: 0..4 }
|
160
|
-
expect { @session.assert_text('Header', o) }.not_to raise_error
|
160
|
+
expect { @session.assert_text('Header', **o) }.not_to raise_error
|
161
161
|
end
|
162
|
+
|
162
163
|
context 'with no :count expectation' do
|
163
164
|
it 'fails if :minimum is not met' do
|
164
165
|
o = { minimum: 6,
|
165
166
|
maximum: 5,
|
166
167
|
between: 2..7 }
|
167
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
168
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
168
169
|
end
|
170
|
+
|
169
171
|
it 'fails if :maximum is not met' do
|
170
172
|
o = { minimum: 0,
|
171
173
|
maximum: 0,
|
172
174
|
between: 2..7 }
|
173
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
175
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
174
176
|
end
|
177
|
+
|
175
178
|
it 'fails if :between is not met' do
|
176
179
|
o = { minimum: 0,
|
177
180
|
maximum: 5,
|
178
181
|
between: 0..4 }
|
179
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
182
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
180
183
|
end
|
184
|
+
|
181
185
|
it 'succeeds if all combineable expectations are met' do
|
182
186
|
o = { minimum: 0,
|
183
187
|
maximum: 5,
|
184
188
|
between: 2..7 }
|
185
|
-
expect { @session.assert_text('Header', o) }.not_to raise_error
|
189
|
+
expect { @session.assert_text('Header', **o) }.not_to raise_error
|
186
190
|
end
|
187
191
|
end
|
188
192
|
end
|
@@ -229,6 +229,12 @@ Capybara::SpecHelper.spec '#check' do
|
|
229
229
|
@session.click_button('awesome')
|
230
230
|
expect(extract_results(@session)['cars']).to include('bugatti')
|
231
231
|
end
|
232
|
+
|
233
|
+
it 'should check via label if multiple labels' do
|
234
|
+
expect(@session).to have_field('multi_label_checkbox', checked: false, visible: :hidden)
|
235
|
+
@session.check('Label to click', allow_label_click: true)
|
236
|
+
expect(@session).to have_field('multi_label_checkbox', checked: true, visible: :hidden)
|
237
|
+
end
|
232
238
|
end
|
233
239
|
end
|
234
240
|
end
|
@@ -186,6 +186,22 @@ Capybara::SpecHelper.spec '#click_button' do
|
|
186
186
|
@session.click_button(name: 'form[awesome]')
|
187
187
|
expect(extract_results(@session)['first_name']).to eq('John')
|
188
188
|
end
|
189
|
+
|
190
|
+
it 'should submit by specific button name regex' do
|
191
|
+
@session.click_button(name: /form\[awes.*\]/)
|
192
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when Capybara.enable_aria_role = true' do
|
197
|
+
it 'should click on a button role', requires: [:js] do
|
198
|
+
Capybara.enable_aria_role = true
|
199
|
+
@session.using_wait_time(1.5) do
|
200
|
+
@session.visit('/with_js')
|
201
|
+
@session.click_button('ARIA button')
|
202
|
+
expect(@session).to have_button('ARIA button has been clicked')
|
203
|
+
end
|
204
|
+
end
|
189
205
|
end
|
190
206
|
|
191
207
|
context 'with fields associated with the form using the form attribute', requires: [:form_attribute] do
|
@@ -38,6 +38,15 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|
38
38
|
expect(extract_results(@session)['first_name']).to eq('John')
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'with test_id' do
|
42
|
+
it 'should click on a button' do
|
43
|
+
Capybara.test_id = 'data-test-id'
|
44
|
+
@session.visit('/form')
|
45
|
+
@session.click_link_or_button('test_id_button')
|
46
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
41
50
|
context 'with :exact option' do
|
42
51
|
context 'when `false`' do
|
43
52
|
it 'clicks on approximately matching link' do
|
@@ -22,7 +22,7 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|
22
22
|
|
23
23
|
expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
|
24
24
|
expect(@session.current_host).to eq("#{scheme}://#{s.host}") # no port
|
25
|
-
expect(@session.current_path).to eq(path)
|
25
|
+
expect(@session.current_path).to eq(path.split('#')[0])
|
26
26
|
# Server should agree with us
|
27
27
|
expect(@session).to have_content("Current host is #{scheme}://#{s.host}:#{s.port}") if path == '/host'
|
28
28
|
end
|
@@ -84,6 +84,16 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|
84
84
|
should_be_on 0, '/landed'
|
85
85
|
end
|
86
86
|
|
87
|
+
it 'maintains fragment' do
|
88
|
+
@session.visit("#{bases[0]}/redirect#fragment")
|
89
|
+
should_be_on 0, '/landed#fragment'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'redirects to a fragment' do
|
93
|
+
@session.visit("#{bases[0]}/redirect_with_fragment")
|
94
|
+
should_be_on 0, '/landed#with_fragment'
|
95
|
+
end
|
96
|
+
|
87
97
|
it 'is affected by pushState', requires: [:js] do
|
88
98
|
@session.visit('/with_js')
|
89
99
|
@session.execute_script("window.history.pushState({}, '', '/pushed')")
|
@@ -47,6 +47,15 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
47
47
|
expect(extract_results(@session)['description']).to eq('Texty text')
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'should fill in a textarea in a reasonable time by default' do
|
51
|
+
textarea = @session.find(:fillable_field, 'form[description]')
|
52
|
+
value = 'a' * 4000
|
53
|
+
start = Time.now
|
54
|
+
textarea.fill_in(with: value)
|
55
|
+
expect(Time.now.to_f).to be_within(0.25).of start.to_f
|
56
|
+
expect(textarea.value).to eq value
|
57
|
+
end
|
58
|
+
|
50
59
|
it 'should fill in a password field by id' do
|
51
60
|
@session.fill_in('form_password', with: 'supasikrit')
|
52
61
|
@session.click_button('awesome')
|
@@ -95,6 +104,26 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
95
104
|
expect(extract_results(@session)['html5_color']).to eq('#112233')
|
96
105
|
end
|
97
106
|
|
107
|
+
describe 'with input[type="range"]' do
|
108
|
+
it 'should set the range slider correctly' do
|
109
|
+
@session.fill_in('form_age', with: 51)
|
110
|
+
@session.click_button('awesome')
|
111
|
+
expect(extract_results(@session)['age'].to_f).to eq 51
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should set the range slider to valid values' do
|
115
|
+
@session.fill_in('form_age', with: '37.6')
|
116
|
+
@session.click_button('awesome')
|
117
|
+
expect(extract_results(@session)['age'].to_f).to eq 37.5
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should respect the range slider limits' do
|
121
|
+
@session.fill_in('form_age', with: '3')
|
122
|
+
@session.click_button('awesome')
|
123
|
+
expect(extract_results(@session)['age'].to_f).to eq 13
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
98
127
|
it 'should fill in a field with a custom type' do
|
99
128
|
@session.fill_in('Schmooo', with: 'Schmooo is the game')
|
100
129
|
@session.click_button('awesome')
|