capybara 3.8.1 → 3.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +465 -0
- data/License.txt +1 -1
- data/README.md +58 -57
- data/lib/capybara/config.rb +10 -4
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +2 -2
- data/lib/capybara/driver/node.rb +26 -5
- data/lib/capybara/dsl.rb +12 -4
- data/lib/capybara/helpers.rb +8 -4
- data/lib/capybara/minitest/spec.rb +162 -85
- data/lib/capybara/minitest.rb +248 -148
- data/lib/capybara/node/actions.rb +149 -96
- data/lib/capybara/node/base.rb +27 -10
- data/lib/capybara/node/document.rb +12 -0
- data/lib/capybara/node/document_matchers.rb +9 -5
- data/lib/capybara/node/element.rb +254 -109
- data/lib/capybara/node/finders.rb +83 -76
- data/lib/capybara/node/matchers.rb +279 -141
- data/lib/capybara/node/simple.rb +25 -6
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +11 -5
- data/lib/capybara/queries/current_path_query.rb +3 -3
- data/lib/capybara/queries/match_query.rb +1 -0
- data/lib/capybara/queries/selector_query.rb +467 -103
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +6 -2
- data/lib/capybara/queries/text_query.rb +17 -3
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +22 -15
- data/lib/capybara/rack_test/driver.rb +10 -1
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +33 -28
- data/lib/capybara/rack_test/node.rb +74 -6
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +55 -23
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matcher_proxies.rb +36 -15
- data/lib/capybara/rspec/matchers/base.rb +111 -0
- data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
- data/lib/capybara/rspec/matchers/compound.rb +88 -0
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
- data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +33 -0
- data/lib/capybara/rspec/matchers/have_title.rb +29 -0
- data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
- data/lib/capybara/rspec/matchers/match_style.rb +38 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +117 -311
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +69 -0
- data/lib/capybara/selector/css.rb +17 -15
- data/lib/capybara/selector/definition/button.rb +52 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +27 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +54 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/definition.rb +277 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +26 -19
- data/lib/capybara/selector/filters/base.rb +24 -5
- data/lib/capybara/selector/filters/expression_filter.rb +3 -3
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -2
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +73 -367
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +221 -480
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +203 -86
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +88 -14
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +110 -0
- data/lib/capybara/selenium/extensions/html5_drag.rb +191 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +78 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +298 -93
- data/lib/capybara/selenium/nodes/chrome_node.rb +100 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +131 -0
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -3
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +4 -3
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/server.rb +30 -7
- data/lib/capybara/session/config.rb +14 -10
- data/lib/capybara/session/matchers.rb +11 -7
- data/lib/capybara/session.rb +152 -111
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +101 -10
- data/lib/capybara/spec/session/all_spec.rb +96 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +29 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_selector_spec.rb +0 -10
- data/lib/capybara/spec/session/assert_style_spec.rb +4 -4
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +63 -36
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +117 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +16 -0
- data/lib/capybara/spec/session/click_link_spec.rb +17 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +13 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +47 -6
- data/lib/capybara/spec/session/find_field_spec.rb +1 -1
- data/lib/capybara/spec/session/find_spec.rb +74 -4
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +13 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +1 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +122 -12
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +55 -0
- data/lib/capybara/spec/session/has_select_spec.rb +34 -6
- data/lib/capybara/spec/session/has_selector_spec.rb +11 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +166 -0
- data/lib/capybara/spec/session/has_text_spec.rb +48 -1
- data/lib/capybara/spec/session/has_xpath_spec.rb +17 -0
- data/lib/capybara/spec/session/html_spec.rb +7 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +643 -18
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +4 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +23 -8
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +10 -10
- data/lib/capybara/spec/session/selectors_spec.rb +36 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_spec.rb +59 -58
- data/lib/capybara/spec/session/window/windows_spec.rb +4 -0
- data/lib/capybara/spec/session/within_spec.rb +23 -0
- data/lib/capybara/spec/spec_helper.rb +16 -6
- data/lib/capybara/spec/test_app.rb +28 -23
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +48 -7
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +20 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +67 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_hover.erb +1 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +32 -6
- data/lib/capybara/spec/views/with_js.erb +3 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +11 -11
- data/lib/capybara.rb +118 -111
- data/spec/basic_node_spec.rb +14 -3
- data/spec/capybara_spec.rb +29 -29
- data/spec/css_builder_spec.rb +101 -0
- data/spec/dsl_spec.rb +46 -21
- 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 +18 -4
- data/spec/minitest_spec_spec.rb +59 -44
- data/spec/rack_test_spec.rb +117 -89
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +51 -49
- data/spec/rspec/features_spec.rb +3 -0
- data/spec/rspec/shared_spec_matchers.rb +112 -97
- data/spec/rspec_spec.rb +35 -17
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +244 -28
- data/spec/selenium_spec_chrome.rb +125 -54
- data/spec/selenium_spec_chrome_remote.rb +26 -12
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +208 -0
- data/spec/selenium_spec_firefox_remote.rb +15 -18
- data/spec/selenium_spec_ie.rb +82 -13
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +118 -77
- data/spec/session_spec.rb +19 -3
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +110 -65
- data/spec/spec_helper.rb +57 -9
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +257 -17
- data/lib/capybara/rspec/compound.rb +0 -94
- data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -49
- data/lib/capybara/selenium/nodes/marionette_node.rb +0 -121
- data/lib/capybara/spec/session/has_style_spec.rb +0 -25
- data/spec/selenium_spec_marionette.rb +0 -172
@@ -1,22 +1,95 @@
|
|
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({
|
17
|
+
tolerance: 'touch',
|
6
18
|
drop: function(event, ui) {
|
7
19
|
ui.draggable.remove();
|
8
|
-
$(this).html(
|
20
|
+
$(this).html(
|
21
|
+
"Dropped!" +
|
22
|
+
(event.altKey ? "-alt" : "") +
|
23
|
+
(event.ctrlKey ? "-ctrl" : "") +
|
24
|
+
(event.metaKey ? "-meta" : "") +
|
25
|
+
(event.shiftKey ? "-shift" : "")
|
26
|
+
);
|
9
27
|
}
|
10
28
|
});
|
11
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
|
+
);
|
12
38
|
ev.originalEvent.dataTransfer.setData("text", ev.target.id);
|
13
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
|
+
});
|
14
43
|
$('#drop_html5, #drop_html5_scroll').on('dragover', function(ev){
|
44
|
+
$(this).after('<div class="log">DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
|
45
|
+
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
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)
|
15
53
|
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
16
54
|
});
|
17
55
|
$('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
|
18
56
|
ev.preventDefault();
|
19
|
-
|
57
|
+
var oev = ev.originalEvent;
|
58
|
+
if (oev.dataTransfer.items) {
|
59
|
+
for (var i = 0; i < oev.dataTransfer.items.length; i++){
|
60
|
+
var item = oev.dataTransfer.items[i];
|
61
|
+
if (item.kind === 'file'){
|
62
|
+
var file = item.getAsFile();
|
63
|
+
$(this).append('HTML5 Dropped file: ' + file.name);
|
64
|
+
} else {
|
65
|
+
var _this = this;
|
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
|
+
};
|
79
|
+
})(item.type);
|
80
|
+
item.getAsString(callback);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
$(this).html('HTML5 Dropped ' + oev.dataTransfer.getData("text"));
|
85
|
+
for (var i = 0; i < oev.dataTransfer.files.length; i++) {
|
86
|
+
$(this).append('HTML5 Dropped file: ' + oev.dataTransfer.files[i].name);
|
87
|
+
}
|
88
|
+
for (var i = 0; i < oev.dataTransfer.types.length; i++) {
|
89
|
+
var type = oev.dataTransfer.types[i];
|
90
|
+
$(this).append('HTML5 Dropped string: ' + type + ' ' + oev.dataTransfer.getData(type));
|
91
|
+
}
|
92
|
+
}
|
20
93
|
});
|
21
94
|
$('#clickable').click(function(e) {
|
22
95
|
var link = $(this);
|
@@ -35,6 +108,13 @@ $(function() {
|
|
35
108
|
}, 4000);
|
36
109
|
return false;
|
37
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
|
+
});
|
38
118
|
$('#waiter').change(function() {
|
39
119
|
activeRequests = 1;
|
40
120
|
setTimeout(function() {
|
@@ -80,6 +160,7 @@ $(function() {
|
|
80
160
|
});
|
81
161
|
$('#click-test').on({
|
82
162
|
click: function(e) {
|
163
|
+
window.click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
|
83
164
|
var desc = "";
|
84
165
|
if (e.altKey) desc += 'alt ';
|
85
166
|
if (e.ctrlKey) desc += 'control ';
|
@@ -106,6 +187,16 @@ $(function() {
|
|
106
187
|
if (e.shiftKey) desc += 'shift ';
|
107
188
|
var pos = this.getBoundingClientRect();
|
108
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
|
+
}
|
109
200
|
}
|
110
201
|
});
|
111
202
|
$('#open-alert').click(function() {
|
@@ -159,26 +250,26 @@ $(function() {
|
|
159
250
|
$(this).attr('confirmed', 'false');
|
160
251
|
}
|
161
252
|
}
|
162
|
-
})
|
253
|
+
});
|
163
254
|
$('#delayed-page-change').click(function() {
|
164
255
|
setTimeout(function() {
|
165
256
|
window.location.pathname = '/with_html'
|
166
257
|
}, 500)
|
167
|
-
})
|
258
|
+
});
|
168
259
|
$('#with-key-events').keydown(function(e){
|
169
260
|
$('#key-events-output').append('keydown:'+e.which+' ')
|
170
261
|
});
|
171
262
|
$('#disable-on-click').click(function(e){
|
172
|
-
var input = this
|
263
|
+
var input = this;
|
173
264
|
setTimeout(function() {
|
174
265
|
input.disabled = true;
|
175
266
|
}, 500)
|
176
|
-
})
|
267
|
+
});
|
177
268
|
$('#set-storage').click(function(e){
|
178
269
|
sessionStorage.setItem('session', 'session_value');
|
179
270
|
localStorage.setItem('local', 'local value');
|
180
|
-
})
|
181
|
-
$('#multiple-file').change(function(e){
|
182
|
-
$('body').append($('<p class="file_change"
|
271
|
+
});
|
272
|
+
$('#multiple-file, #hidden_file').change(function(e){
|
273
|
+
$('body').append($('<p class="file_change">File input changed</p>'));
|
183
274
|
})
|
184
275
|
});
|
@@ -30,16 +30,56 @@ Capybara::SpecHelper.spec '#all' do
|
|
30
30
|
|
31
31
|
it 'should accept an XPath instance', :exact_false do
|
32
32
|
@session.visit('/form')
|
33
|
-
@xpath = Capybara::Selector.
|
33
|
+
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('Name')
|
34
34
|
expect(@xpath).to be_a(::XPath::Union)
|
35
35
|
@result = @session.all(@xpath).map(&:value)
|
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')
|
@@ -56,6 +96,11 @@ Capybara::SpecHelper.spec '#all' do
|
|
56
96
|
expect(@session.all(:xpath, '//h1').first.text).to eq('This is a test')
|
57
97
|
expect(@session.all(:xpath, "//input[@id='test_field']").first.value).to eq('monkey')
|
58
98
|
end
|
99
|
+
|
100
|
+
it 'should use alternated regex for :id' do
|
101
|
+
expect(@session.all(:xpath, './/h2', id: /h2/).unfiltered_size).to eq 3
|
102
|
+
expect(@session.all(:xpath, './/h2', id: /h2(one|two)/).unfiltered_size).to eq 2
|
103
|
+
end
|
59
104
|
end
|
60
105
|
|
61
106
|
context 'with css as default selector' do
|
@@ -95,11 +140,35 @@ Capybara::SpecHelper.spec '#all' do
|
|
95
140
|
end
|
96
141
|
end
|
97
142
|
|
143
|
+
context 'with obscured filter', requires: [:css] do
|
144
|
+
it 'should only find nodes on top in the viewport when false' do
|
145
|
+
expect(@session.all(:css, 'a.simple', obscured: false).size).to eq(1)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should not find nodes on top outside the viewport when false' do
|
149
|
+
expect(@session.all(:link, 'Download Me', obscured: false).size).to eq(0)
|
150
|
+
@session.scroll_to(@session.find_link('Download Me'))
|
151
|
+
expect(@session.all(:link, 'Download Me', obscured: false).size).to eq(1)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should find top nodes outside the viewport when true' do
|
155
|
+
expect(@session.all(:link, 'Download Me', obscured: true).size).to eq(1)
|
156
|
+
@session.scroll_to(@session.find_link('Download Me'))
|
157
|
+
expect(@session.all(:link, 'Download Me', obscured: true).size).to eq(0)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should only find non-top nodes when true' do
|
161
|
+
# Also need visible: false so visibility is ignored
|
162
|
+
expect(@session.all(:css, 'a.simple', visible: false, obscured: true).size).to eq(1)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
98
166
|
context 'with element count filters' do
|
99
167
|
context ':count' do
|
100
168
|
it 'should succeed when the number of elements founds matches the expectation' do
|
101
169
|
expect { @session.all(:css, 'h1, p', count: 4) }.not_to raise_error
|
102
170
|
end
|
171
|
+
|
103
172
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
104
173
|
expect { @session.all(:css, 'h1, p', count: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
105
174
|
end
|
@@ -109,6 +178,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
109
178
|
it 'should succeed when the number of elements founds matches the expectation' do
|
110
179
|
expect { @session.all(:css, 'h1, p', minimum: 0) }.not_to raise_error
|
111
180
|
end
|
181
|
+
|
112
182
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
113
183
|
expect { @session.all(:css, 'h1, p', minimum: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
114
184
|
end
|
@@ -118,6 +188,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
118
188
|
it 'should succeed when the number of elements founds matches the expectation' do
|
119
189
|
expect { @session.all(:css, 'h1, p', maximum: 4) }.not_to raise_error
|
120
190
|
end
|
191
|
+
|
121
192
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
122
193
|
expect { @session.all(:css, 'h1, p', maximum: 0) }.to raise_error(Capybara::ExpectationNotMet)
|
123
194
|
end
|
@@ -127,9 +198,24 @@ Capybara::SpecHelper.spec '#all' do
|
|
127
198
|
it 'should succeed when the number of elements founds matches the expectation' do
|
128
199
|
expect { @session.all(:css, 'h1, p', between: 2..7) }.not_to raise_error
|
129
200
|
end
|
201
|
+
|
130
202
|
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
131
203
|
expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
|
132
204
|
end
|
205
|
+
|
206
|
+
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
|
207
|
+
it'treats an endless range as minimum' do
|
208
|
+
expect { @session.all(:css, 'h1, p', between: 2..) }.not_to raise_error
|
209
|
+
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
|
210
|
+
end
|
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
|
133
219
|
end
|
134
220
|
|
135
221
|
context 'with multiple count filters' do
|
@@ -138,32 +224,36 @@ Capybara::SpecHelper.spec '#all' do
|
|
138
224
|
minimum: 5,
|
139
225
|
maximum: 0,
|
140
226
|
between: 0..3 }
|
141
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
227
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
142
228
|
end
|
229
|
+
|
143
230
|
context 'with no :count expectation' do
|
144
231
|
it 'fails if :minimum is not met' do
|
145
232
|
o = { minimum: 5,
|
146
233
|
maximum: 4,
|
147
234
|
between: 2..7 }
|
148
|
-
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)
|
149
236
|
end
|
237
|
+
|
150
238
|
it 'fails if :maximum is not met' do
|
151
239
|
o = { minimum: 0,
|
152
240
|
maximum: 0,
|
153
241
|
between: 2..7 }
|
154
|
-
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)
|
155
243
|
end
|
244
|
+
|
156
245
|
it 'fails if :between is not met' do
|
157
246
|
o = { minimum: 0,
|
158
247
|
maximum: 4,
|
159
248
|
between: 0..3 }
|
160
|
-
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)
|
161
250
|
end
|
251
|
+
|
162
252
|
it 'succeeds if all combineable expectations are met' do
|
163
253
|
o = { minimum: 0,
|
164
254
|
maximum: 4,
|
165
255
|
between: 2..7 }
|
166
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
256
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
167
257
|
end
|
168
258
|
end
|
169
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)
|
@@ -19,6 +19,10 @@ Capybara::SpecHelper.spec '#assert_all_of_selectors' do
|
|
19
19
|
@session.assert_all_of_selectors('p a#foo', 'h2#h2two', 'h2#h2one')
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should support filter block' do
|
23
|
+
expect { @session.assert_all_of_selectors(:css, 'h2#h2one', 'h2#h2two') { |n| n[:id] == 'h2one' } }.to raise_error(Capybara::ElementNotFound, /custom filter block/)
|
24
|
+
end
|
25
|
+
|
22
26
|
context 'should respect scopes' do
|
23
27
|
it 'when used with `within`' do
|
24
28
|
@session.within "//p[@id='first']" do
|
@@ -109,3 +113,28 @@ Capybara::SpecHelper.spec '#assert_none_of_selectors' do
|
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
116
|
+
|
117
|
+
Capybara::SpecHelper.spec '#assert_any_of_selectors' do
|
118
|
+
before do
|
119
|
+
@session.visit('/with_html')
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should be true if any of the given selectors are on the page' do
|
123
|
+
@session.assert_any_of_selectors(:css, 'a#foo', 'h2#h2three')
|
124
|
+
@session.assert_any_of_selectors(:css, 'h2#h2three', 'a#foo')
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should be false if none of the given selectors are on the page' do
|
128
|
+
expect { @session.assert_any_of_selectors(:css, 'h2#h2three', 'h4#h4four') }.to raise_error(Capybara::ElementNotFound)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should use default selector' do
|
132
|
+
Capybara.default_selector = :css
|
133
|
+
expect { @session.assert_any_of_selectors('h2#h2three', 'h5#h5five') }.to raise_error(Capybara::ElementNotFound)
|
134
|
+
@session.assert_any_of_selectors('p a#foo', 'h2#h2two', 'h2#h2one')
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should support filter block' do
|
138
|
+
expect { @session.assert_any_of_selectors(:css, 'h2#h2one', 'h2#h2two') { |_n| false } }.to raise_error(Capybara::ElementNotFound, /custom filter block/)
|
139
|
+
end
|
140
|
+
end
|
@@ -37,7 +37,9 @@ Capybara::SpecHelper.spec '#assert_current_path' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should not cause an exception when current_url is nil' do
|
40
|
-
|
40
|
+
allow(@session).to receive(:current_url).and_return(nil)
|
41
|
+
allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
|
42
|
+
|
41
43
|
expect { @session.assert_current_path(nil) }.not_to raise_error
|
42
44
|
end
|
43
45
|
end
|
@@ -65,7 +67,8 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
|
|
65
67
|
end
|
66
68
|
|
67
69
|
it 'should not cause an exception when current_url is nil' do
|
68
|
-
|
70
|
+
allow(@session).to receive(:current_url).and_return(nil)
|
71
|
+
allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
|
69
72
|
|
70
73
|
expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
|
71
74
|
end
|
@@ -72,16 +72,6 @@ Capybara::SpecHelper.spec '#assert_selector' do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
Capybara::SpecHelper.spec '#refute_selector', requires: [:driver] do
|
76
|
-
it 'should warn not to use' do
|
77
|
-
@session.visit('/with_html')
|
78
|
-
doc = @session.document
|
79
|
-
allow(doc).to receive(:warn)
|
80
|
-
doc.refute_selector(:xpath, '//abbr')
|
81
|
-
expect(doc).to have_received(:warn)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
75
|
Capybara::SpecHelper.spec '#assert_no_selector' do
|
86
76
|
before do
|
87
77
|
@session.visit('/with_html')
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Capybara::SpecHelper.spec '#
|
3
|
+
Capybara::SpecHelper.spec '#assert_matches_style', requires: [:css] do
|
4
4
|
it 'should not raise if the elements style contains the given properties' do
|
5
5
|
@session.visit('/with_html')
|
6
6
|
expect do
|
7
|
-
@session.find(:css, '#first').
|
7
|
+
@session.find(:css, '#first').assert_matches_style(display: 'block')
|
8
8
|
end.not_to raise_error
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should raise error if the elements style doesn't contain the given properties" do
|
12
12
|
@session.visit('/with_html')
|
13
13
|
expect do
|
14
|
-
@session.find(:css, '#first').
|
14
|
+
@session.find(:css, '#first').assert_matches_style(display: 'inline')
|
15
15
|
end.to raise_error(Capybara::ExpectationNotMet, 'Expected node to have styles {"display"=>"inline"}. Actual styles were {"display"=>"block"}')
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#assert_style', requires: [:css] do
|
|
20
20
|
el = @session.find(:css, '#change')
|
21
21
|
@session.click_link('Change size')
|
22
22
|
expect do
|
23
|
-
el.
|
23
|
+
el.assert_matches_style({ 'font-size': '50px' }, wait: 3)
|
24
24
|
end.not_to raise_error
|
25
25
|
end
|
26
26
|
end
|
@@ -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
|