capybara 3.29.0 → 3.36.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 +203 -15
- data/README.md +13 -4
- data/lib/capybara/config.rb +24 -10
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +8 -0
- data/lib/capybara/driver/node.rb +1 -1
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +19 -2
- data/lib/capybara/minitest/spec.rb +156 -97
- data/lib/capybara/minitest.rb +232 -144
- data/lib/capybara/node/actions.rb +41 -37
- 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 +24 -21
- data/lib/capybara/node/finders.rb +25 -18
- data/lib/capybara/node/matchers.rb +72 -57
- data/lib/capybara/node/simple.rb +13 -3
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +4 -3
- 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 +71 -23
- data/lib/capybara/queries/sibling_query.rb +4 -3
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +7 -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 +43 -15
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +18 -12
- data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
- data/lib/capybara/registrations/servers.rb +3 -2
- data/lib/capybara/result.rb +35 -15
- data/lib/capybara/rspec/matcher_proxies.rb +8 -8
- data/lib/capybara/rspec/matchers/base.rb +12 -6
- data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
- data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
- data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
- data/lib/capybara/rspec/matchers/have_text.rb +3 -3
- 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 +2 -1
- data/lib/capybara/rspec/matchers.rb +33 -32
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/selector/builders/css_builder.rb +2 -2
- data/lib/capybara/selector/builders/xpath_builder.rb +4 -2
- data/lib/capybara/selector/css.rb +2 -2
- data/lib/capybara/selector/definition/button.rb +35 -13
- data/lib/capybara/selector/definition/checkbox.rb +3 -3
- 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 +2 -2
- data/lib/capybara/selector/definition/fillable_field.rb +3 -3
- data/lib/capybara/selector/definition/label.rb +5 -3
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/radio_button.rb +3 -3
- 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/definition.rb +14 -11
- data/lib/capybara/selector/filter_set.rb +17 -17
- data/lib/capybara/selector/filters/base.rb +6 -1
- data/lib/capybara/selector/filters/locator_filter.rb +1 -1
- data/lib/capybara/selector/selector.rb +13 -3
- data/lib/capybara/selector.rb +37 -19
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
- data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
- data/lib/capybara/selenium/driver.rb +79 -16
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +11 -13
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +10 -12
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +4 -4
- data/lib/capybara/selenium/extensions/find.rb +4 -4
- data/lib/capybara/selenium/extensions/html5_drag.rb +30 -13
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/logger_suppressor.rb +8 -2
- data/lib/capybara/selenium/node.rb +110 -26
- data/lib/capybara/selenium/nodes/chrome_node.rb +34 -19
- data/lib/capybara/selenium/nodes/edge_node.rb +5 -3
- data/lib/capybara/selenium/nodes/firefox_node.rb +11 -6
- data/lib/capybara/selenium/nodes/safari_node.rb +3 -3
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +4 -4
- data/lib/capybara/selenium/patches/logs.rb +7 -9
- data/lib/capybara/server/animation_disabler.rb +17 -6
- data/lib/capybara/server/checker.rb +1 -1
- data/lib/capybara/server/middleware.rb +22 -10
- data/lib/capybara/server.rb +15 -3
- data/lib/capybara/session/config.rb +9 -3
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/session.rb +73 -37
- 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/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +62 -9
- 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 +15 -0
- data/lib/capybara/spec/session/choose_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 +31 -8
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +4 -0
- data/lib/capybara/spec/session/has_button_spec.rb +75 -0
- data/lib/capybara/spec/session/has_css_spec.rb +14 -10
- data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
- data/lib/capybara/spec/session/has_field_spec.rb +40 -0
- data/lib/capybara/spec/session/has_link_spec.rb +24 -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 +25 -1
- 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 +184 -33
- 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 -4
- data/lib/capybara/spec/session/scroll_spec.rb +4 -4
- data/lib/capybara/spec/session/selectors_spec.rb +15 -2
- 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 +17 -17
- data/lib/capybara/spec/test_app.rb +40 -29
- data/lib/capybara/spec/views/animated.erb +1 -1
- data/lib/capybara/spec/views/form.erb +52 -6
- data/lib/capybara/spec/views/frame_child.erb +1 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +1 -1
- data/lib/capybara/spec/views/offset.erb +2 -1
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +2 -2
- data/lib/capybara/spec/views/scroll.erb +2 -1
- data/lib/capybara/spec/views/spatial.erb +1 -1
- data/lib/capybara/spec/views/with_animation.erb +10 -3
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +5 -3
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +2 -2
- data/lib/capybara/spec/views/with_html.erb +3 -3
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +5 -3
- data/lib/capybara/spec/views/with_jstree.erb +1 -1
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +3 -3
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +3 -7
- data/lib/capybara.rb +35 -29
- data/spec/basic_node_spec.rb +25 -11
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +16 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/minitest_spec.rb +3 -2
- data/spec/minitest_spec_spec.rb +46 -46
- data/spec/rack_test_spec.rb +37 -11
- data/spec/regexp_dissassembler_spec.rb +40 -36
- data/spec/result_spec.rb +42 -32
- data/spec/rspec/features_spec.rb +5 -2
- data/spec/rspec/scenarios_spec.rb +4 -0
- data/spec/rspec/shared_spec_matchers.rb +68 -56
- data/spec/rspec_spec.rb +8 -4
- data/spec/selector_spec.rb +17 -2
- data/spec/selenium_spec_chrome.rb +48 -25
- data/spec/selenium_spec_chrome_remote.rb +13 -6
- data/spec/selenium_spec_firefox.rb +25 -17
- data/spec/selenium_spec_firefox_remote.rb +2 -2
- data/spec/selenium_spec_ie.rb +3 -6
- data/spec/selenium_spec_safari.rb +27 -19
- data/spec/server_spec.rb +84 -31
- data/spec/session_spec.rb +1 -1
- data/spec/shared_selenium_node.rb +21 -7
- data/spec/shared_selenium_session.rb +114 -19
- data/spec/spec_helper.rb +1 -1
- metadata +78 -21
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#active_element', requires: [:active_element] do
|
4
|
+
it 'should return the active element' do
|
5
|
+
@session.visit('/form')
|
6
|
+
@session.send_keys(:tab)
|
7
|
+
|
8
|
+
expect(@session.active_element).to match_selector(:css, '[tabindex="1"]')
|
9
|
+
|
10
|
+
@session.send_keys(:tab)
|
11
|
+
|
12
|
+
expect(@session.active_element).to match_selector(:css, '[tabindex="2"]')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should support reloading' do
|
16
|
+
@session.visit('/form')
|
17
|
+
expect(@session.active_element).to match_selector(:css, 'body')
|
18
|
+
@session.execute_script <<-JS
|
19
|
+
window.setTimeout(() => {
|
20
|
+
document.querySelector('#form_title').focus();
|
21
|
+
}, 1000)
|
22
|
+
JS
|
23
|
+
expect(@session.active_element).to match_selector(:css, 'body', wait: false)
|
24
|
+
expect(@session.active_element).to match_selector(:css, '#form_title', wait: 2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return a Capybara::Element' do
|
28
|
+
@session.visit('/form')
|
29
|
+
expect(@session.active_element).to be_a Capybara::Node::Element
|
30
|
+
end
|
31
|
+
end
|
@@ -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,14 +198,20 @@ 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
|
161
205
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
206
|
+
it 'treats an endless range as minimum' do
|
207
|
+
expect { @session.all(:css, 'h1, p', between: 2..) }.not_to raise_error
|
208
|
+
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
|
209
|
+
end
|
210
|
+
|
211
|
+
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
|
212
|
+
it'treats a beginless range as maximum' do
|
213
|
+
expect { @session.all(:css, 'h1, p', between: ..7) }.not_to raise_error
|
214
|
+
expect { @session.all(:css, 'h1, p', between: ..3) }.to raise_error(Capybara::ExpectationNotMet)
|
166
215
|
end
|
167
216
|
TEST
|
168
217
|
end
|
@@ -173,32 +222,36 @@ Capybara::SpecHelper.spec '#all' do
|
|
173
222
|
minimum: 5,
|
174
223
|
maximum: 0,
|
175
224
|
between: 0..3 }
|
176
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
225
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
177
226
|
end
|
227
|
+
|
178
228
|
context 'with no :count expectation' do
|
179
229
|
it 'fails if :minimum is not met' do
|
180
230
|
o = { minimum: 5,
|
181
231
|
maximum: 4,
|
182
232
|
between: 2..7 }
|
183
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
233
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
184
234
|
end
|
235
|
+
|
185
236
|
it 'fails if :maximum is not met' do
|
186
237
|
o = { minimum: 0,
|
187
238
|
maximum: 0,
|
188
239
|
between: 2..7 }
|
189
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
240
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
190
241
|
end
|
242
|
+
|
191
243
|
it 'fails if :between is not met' do
|
192
244
|
o = { minimum: 0,
|
193
245
|
maximum: 4,
|
194
246
|
between: 0..3 }
|
195
|
-
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
247
|
+
expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
196
248
|
end
|
249
|
+
|
197
250
|
it 'succeeds if all combineable expectations are met' do
|
198
251
|
o = { minimum: 0,
|
199
252
|
maximum: 4,
|
200
253
|
between: 2..7 }
|
201
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
254
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
202
255
|
end
|
203
256
|
end
|
204
257
|
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,21 @@ 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
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'with allow_label_click options', requires: [:js] do
|
241
|
+
it 'should allow offsets to click location on label' do
|
242
|
+
expect(@session.find(:checkbox, 'form_cars_lotus', unchecked: true, visible: :hidden)).to be_truthy
|
243
|
+
@session.check('form_cars_lotus', allow_label_click: { x: 90, y: 10 })
|
244
|
+
@session.click_button('awesome')
|
245
|
+
expect(extract_results(@session)['cars']).to include('lotus')
|
246
|
+
end
|
232
247
|
end
|
233
248
|
end
|
234
249
|
end
|
@@ -11,6 +11,12 @@ Capybara::SpecHelper.spec '#choose' do
|
|
11
11
|
expect(extract_results(@session)['gender']).to eq('male')
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'ignores readonly attribute on radio buttons' do
|
15
|
+
@session.choose('gender_both')
|
16
|
+
@session.click_button('awesome')
|
17
|
+
expect(extract_results(@session)['gender']).to eq('both')
|
18
|
+
end
|
19
|
+
|
14
20
|
it 'should choose a radio button by label' do
|
15
21
|
@session.choose('Both')
|
16
22
|
@session.click_button('awesome')
|
@@ -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')
|