capybara 3.30.0 → 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/History.md +72 -0
- data/README.md +10 -3
- data/lib/capybara.rb +17 -7
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/minitest.rb +232 -144
- data/lib/capybara/minitest/spec.rb +153 -97
- data/lib/capybara/node/actions.rb +16 -20
- data/lib/capybara/node/element.rb +13 -8
- data/lib/capybara/node/finders.rb +5 -1
- data/lib/capybara/node/matchers.rb +28 -21
- data/lib/capybara/node/simple.rb +1 -1
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/selector_query.rb +8 -1
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +6 -0
- data/lib/capybara/rack_test/browser.rb +3 -1
- data/lib/capybara/rack_test/node.rb +34 -9
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/servers.rb +1 -1
- data/lib/capybara/result.rb +29 -5
- data/lib/capybara/rspec/matcher_proxies.rb +4 -4
- data/lib/capybara/rspec/matchers.rb +27 -27
- 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 +15 -7
- 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 +2 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +2 -1
- data/lib/capybara/selector.rb +12 -1
- data/lib/capybara/selector/definition.rb +5 -4
- data/lib/capybara/selector/definition/button.rb +1 -0
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/label.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/select.rb +31 -12
- data/lib/capybara/selector/definition/table.rb +1 -1
- data/lib/capybara/selector/selector.rb +4 -0
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
- data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
- data/lib/capybara/selenium/driver.rb +7 -4
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -10
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +7 -9
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -2
- data/lib/capybara/selenium/extensions/html5_drag.rb +24 -8
- data/lib/capybara/selenium/node.rb +92 -15
- data/lib/capybara/selenium/nodes/chrome_node.rb +4 -11
- data/lib/capybara/selenium/nodes/edge_node.rb +1 -1
- data/lib/capybara/selenium/nodes/firefox_node.rb +3 -3
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/logs.rb +3 -5
- data/lib/capybara/session.rb +33 -18
- data/lib/capybara/session/config.rb +3 -1
- data/lib/capybara/spec/public/test.js +58 -6
- data/lib/capybara/spec/session/all_spec.rb +45 -5
- data/lib/capybara/spec/session/assert_text_spec.rb +5 -5
- data/lib/capybara/spec/session/click_button_spec.rb +11 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
- data/lib/capybara/spec/session/find_spec.rb +11 -8
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +12 -9
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +16 -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_text_spec.rb +5 -1
- data/lib/capybara/spec/session/node_spec.rb +146 -30
- data/lib/capybara/spec/session/window/window_spec.rb +7 -7
- data/lib/capybara/spec/spec_helper.rb +2 -2
- data/lib/capybara/spec/test_app.rb +14 -18
- data/lib/capybara/spec/views/form.erb +13 -2
- data/lib/capybara/spec/views/with_dragula.erb +3 -1
- data/lib/capybara/spec/views/with_html.erb +2 -2
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +14 -1
- data/spec/minitest_spec.rb +1 -1
- data/spec/rack_test_spec.rb +13 -1
- data/spec/regexp_dissassembler_spec.rb +0 -4
- data/spec/result_spec.rb +40 -29
- data/spec/rspec/shared_spec_matchers.rb +65 -53
- data/spec/selector_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +6 -3
- data/spec/selenium_spec_chrome_remote.rb +2 -0
- data/spec/server_spec.rb +41 -49
- data/spec/shared_selenium_node.rb +18 -0
- data/spec/shared_selenium_session.rb +25 -7
- data/spec/spec_helper.rb +1 -1
- metadata +5 -3
@@ -18,7 +18,7 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
18
18
|
# In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
|
19
19
|
if browser_version >= 75.0
|
20
20
|
driver.execute_script(<<~JS, self)
|
21
|
-
if (arguments[0].multiple &&
|
21
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
22
22
|
arguments[0].value = null;
|
23
23
|
}
|
24
24
|
JS
|
@@ -75,9 +75,11 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
-
def perform_legacy_drag(element)
|
78
|
+
def perform_legacy_drag(element, drop_modifiers)
|
79
79
|
return super if chromedriver_fixed_actions_key_state? || !w3c? || element.obscured?
|
80
80
|
|
81
|
+
raise ArgumentError, 'Modifier keys are not supported while dragging in this version of Chrome.' unless drop_modifiers.empty?
|
82
|
+
|
81
83
|
# W3C Chrome/chromedriver < 77 doesn't maintain mouse button state across actions API performs
|
82
84
|
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2981
|
83
85
|
browser_action.release.perform
|
@@ -90,11 +92,6 @@ private
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
def w3c?
|
94
|
-
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
95
|
-
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
96
|
-
end
|
97
|
-
|
98
95
|
def browser_version(to_float = true)
|
99
96
|
caps = capabilities
|
100
97
|
ver = (caps[:browser_version] || caps[:version])
|
@@ -114,10 +111,6 @@ private
|
|
114
111
|
capabilities['chrome']['chromedriverVersion'].split(' ')[0]
|
115
112
|
end
|
116
113
|
|
117
|
-
def capabilities
|
118
|
-
driver.browser.capabilities
|
119
|
-
end
|
120
|
-
|
121
114
|
def native_displayed?
|
122
115
|
(driver.options[:native_displayed] != false) &&
|
123
116
|
(w3c? && chromedriver_supports_displayed_endpoint?) &&
|
@@ -18,7 +18,7 @@ class Capybara::Selenium::EdgeNode < Capybara::Selenium::Node
|
|
18
18
|
# In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
|
19
19
|
if chrome_edge?
|
20
20
|
driver.execute_script(<<~JS, self)
|
21
|
-
if (arguments[0].multiple &&
|
21
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
22
22
|
arguments[0].value = null;
|
23
23
|
}
|
24
24
|
JS
|
@@ -26,7 +26,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
26
26
|
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
27
27
|
# By default files are appended so we have to clear here if its multiple and already set
|
28
28
|
driver.execute_script(<<~JS, self)
|
29
|
-
if (arguments[0].multiple &&
|
29
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
30
30
|
arguments[0].value = null;
|
31
31
|
}
|
32
32
|
JS
|
@@ -42,7 +42,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
42
42
|
|
43
43
|
def send_keys(*args)
|
44
44
|
# https://github.com/mozilla/geckodriver/issues/846
|
45
|
-
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?
|
45
|
+
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?(Array)
|
46
46
|
|
47
47
|
native.click
|
48
48
|
_send_keys(args).perform
|
@@ -85,7 +85,7 @@ private
|
|
85
85
|
(driver.options[:native_displayed] != false) && !ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS']
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def perform_with_options(click_options)
|
89
89
|
# Firefox/marionette has an issue clicking with offset near viewport edge
|
90
90
|
# scroll element to middle just in case
|
91
91
|
scroll_to_center if click_options.coords?
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPauser
|
4
|
+
def initialize(mouse, keyboard)
|
5
|
+
super
|
6
|
+
@devices[:pauser] = Pauser.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def pause(duration)
|
10
|
+
@actions << [:pauser, :pause, [duration]]
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
class Pauser
|
15
|
+
def pause(duration)
|
16
|
+
sleep duration
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private_constant :Pauser
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined?(::Selenium::WebDriver::VERSION) && (::Selenium::WebDriver::VERSION.to_f < 4) &&
|
24
|
+
defined?(::Selenium::WebDriver::ActionBuilder)
|
25
|
+
::Selenium::WebDriver::ActionBuilder.prepend(ActionPauser)
|
26
|
+
end
|
@@ -33,11 +33,9 @@ module Capybara
|
|
33
33
|
end
|
34
34
|
|
35
35
|
Array(data).map do |l|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
next
|
40
|
-
end
|
36
|
+
::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
|
37
|
+
rescue KeyError
|
38
|
+
next
|
41
39
|
end
|
42
40
|
rescue ::Selenium::WebDriver::Error::UnknownCommandError
|
43
41
|
raise NotImplementedError, LOG_MSG
|
data/lib/capybara/session.rb
CHANGED
@@ -97,8 +97,8 @@ module Capybara
|
|
97
97
|
|
98
98
|
def driver
|
99
99
|
@driver ||= begin
|
100
|
-
unless Capybara.drivers
|
101
|
-
other_drivers = Capybara.drivers.
|
100
|
+
unless Capybara.drivers[mode]
|
101
|
+
other_drivers = Capybara.drivers.names.map(&:inspect)
|
102
102
|
raise Capybara::DriverNotFoundError, "no driver called #{mode.inspect} was found, available drivers: #{other_drivers.join(', ')}"
|
103
103
|
end
|
104
104
|
driver = Capybara.drivers[mode].call(app)
|
@@ -192,7 +192,7 @@ module Capybara
|
|
192
192
|
# @return [String] A snapshot of the DOM of the current document, as it looks right now (potentially modified by JavaScript).
|
193
193
|
#
|
194
194
|
def html
|
195
|
-
driver.html
|
195
|
+
driver.html || ''
|
196
196
|
end
|
197
197
|
alias_method :body, :html
|
198
198
|
alias_method :source, :html
|
@@ -338,8 +338,8 @@ module Capybara
|
|
338
338
|
#
|
339
339
|
# @raise [Capybara::ElementNotFound] If the scope can't be found before time expires
|
340
340
|
#
|
341
|
-
def within(*args)
|
342
|
-
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args)
|
341
|
+
def within(*args, **kw_args)
|
342
|
+
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
|
343
343
|
begin
|
344
344
|
scopes.push(new_scope)
|
345
345
|
yield if block_given?
|
@@ -423,8 +423,8 @@ module Capybara
|
|
423
423
|
# @param [String] locator The locator for the given selector kind. For :frame this is the name/id of a frame/iframe element
|
424
424
|
# @overload within_frame(index)
|
425
425
|
# @param [Integer] index index of a frame (0 based)
|
426
|
-
def within_frame(*args)
|
427
|
-
switch_to_frame(_find_frame(*args))
|
426
|
+
def within_frame(*args, **kw_args)
|
427
|
+
switch_to_frame(_find_frame(*args, **kw_args))
|
428
428
|
begin
|
429
429
|
yield if block_given?
|
430
430
|
ensure
|
@@ -746,15 +746,32 @@ module Capybara
|
|
746
746
|
end
|
747
747
|
|
748
748
|
NODE_METHODS.each do |method|
|
749
|
-
|
750
|
-
|
751
|
-
|
749
|
+
if RUBY_VERSION >= '2.7'
|
750
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
751
|
+
def #{method}(...)
|
752
|
+
@touched = true
|
753
|
+
current_scope.#{method}(...)
|
754
|
+
end
|
755
|
+
METHOD
|
756
|
+
else
|
757
|
+
define_method method do |*args, &block|
|
758
|
+
@touched = true
|
759
|
+
current_scope.send(method, *args, &block)
|
760
|
+
end
|
752
761
|
end
|
753
762
|
end
|
754
763
|
|
755
764
|
DOCUMENT_METHODS.each do |method|
|
756
|
-
|
757
|
-
|
765
|
+
if RUBY_VERSION >= '2.7'
|
766
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
767
|
+
def #{method}(...)
|
768
|
+
document.#{method}(...)
|
769
|
+
end
|
770
|
+
METHOD
|
771
|
+
else
|
772
|
+
define_method method do |*args, &block|
|
773
|
+
document.send(method, *args, &block)
|
774
|
+
end
|
758
775
|
end
|
759
776
|
end
|
760
777
|
|
@@ -873,16 +890,14 @@ module Capybara
|
|
873
890
|
uri.port ||= @server.port if @server && config.always_include_port
|
874
891
|
end
|
875
892
|
|
876
|
-
def _find_frame(*args)
|
877
|
-
return find(:frame) if args.length.zero?
|
878
|
-
|
893
|
+
def _find_frame(*args, **kw_args)
|
879
894
|
case args[0]
|
880
895
|
when Capybara::Node::Element
|
881
896
|
args[0]
|
882
|
-
when String,
|
883
|
-
find(:frame, *args)
|
897
|
+
when String, nil
|
898
|
+
find(:frame, *args, **kw_args)
|
884
899
|
when Symbol
|
885
|
-
find(*args)
|
900
|
+
find(*args, **kw_args)
|
886
901
|
when Integer
|
887
902
|
idx = args[0]
|
888
903
|
all(:frame, minimum: idx + 1)[idx]
|
@@ -8,7 +8,7 @@ module Capybara
|
|
8
8
|
automatic_reload match exact exact_text raise_server_errors visible_text_only
|
9
9
|
automatic_label_click enable_aria_label save_path asset_host default_host app_host
|
10
10
|
server_host server_port server_errors default_set_options disable_animation test_id
|
11
|
-
predicates_wait default_normalize_ws w3c_click_offset].freeze
|
11
|
+
predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze
|
12
12
|
|
13
13
|
attr_accessor(*OPTIONS)
|
14
14
|
|
@@ -37,6 +37,8 @@ module Capybara
|
|
37
37
|
# See {Capybara.configure}
|
38
38
|
# @!method enable_aria_label
|
39
39
|
# See {Capybara.configure}
|
40
|
+
# @!method enable_aria_role
|
41
|
+
# See {Capybara.configure}
|
40
42
|
# @!method save_path
|
41
43
|
# See {Capybara.configure}
|
42
44
|
# @!method asset_host
|
@@ -1,15 +1,40 @@
|
|
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
|
});
|
15
40
|
$('#drag_html5, #drag_html5_scroll').on('dragend', function(ev){
|
@@ -38,10 +63,19 @@ $(function() {
|
|
38
63
|
$(this).append('HTML5 Dropped file: ' + file.name);
|
39
64
|
} else {
|
40
65
|
var _this = this;
|
41
|
-
var callback = (function(type){
|
42
|
-
return function(s){
|
43
|
-
$(_this).append(
|
44
|
-
|
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
|
+
};
|
45
79
|
})(item.type);
|
46
80
|
item.getAsString(callback);
|
47
81
|
}
|
@@ -74,6 +108,13 @@ $(function() {
|
|
74
108
|
}, 4000);
|
75
109
|
return false;
|
76
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
|
+
});
|
77
118
|
$('#waiter').change(function() {
|
78
119
|
activeRequests = 1;
|
79
120
|
setTimeout(function() {
|
@@ -119,6 +160,7 @@ $(function() {
|
|
119
160
|
});
|
120
161
|
$('#click-test').on({
|
121
162
|
click: function(e) {
|
163
|
+
window.click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
|
122
164
|
var desc = "";
|
123
165
|
if (e.altKey) desc += 'alt ';
|
124
166
|
if (e.ctrlKey) desc += 'control ';
|
@@ -145,6 +187,16 @@ $(function() {
|
|
145
187
|
if (e.shiftKey) desc += 'shift ';
|
146
188
|
var pos = this.getBoundingClientRect();
|
147
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
|
+
}
|
148
200
|
}
|
149
201
|
});
|
150
202
|
$('#open-alert').click(function() {
|
@@ -47,6 +47,39 @@ Capybara::SpecHelper.spec '#all' do
|
|
47
47
|
expect { @session.all('//p', schmoo: 'foo') }.to raise_error(ArgumentError)
|
48
48
|
end
|
49
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
|
+
|
50
83
|
context 'with css selectors' do
|
51
84
|
it 'should find all elements using the given selector' do
|
52
85
|
expect(@session.all(:css, 'h1').first.text).to eq('This is a test')
|
@@ -176,6 +209,13 @@ Capybara::SpecHelper.spec '#all' do
|
|
176
209
|
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
|
177
210
|
end
|
178
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
|
179
219
|
end
|
180
220
|
|
181
221
|
context 'with multiple count filters' do
|
@@ -184,7 +224,7 @@ Capybara::SpecHelper.spec '#all' do
|
|
184
224
|
minimum: 5,
|
185
225
|
maximum: 0,
|
186
226
|
between: 0..3 }
|
187
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
227
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
188
228
|
end
|
189
229
|
|
190
230
|
context 'with no :count expectation' do
|
@@ -192,28 +232,28 @@ Capybara::SpecHelper.spec '#all' do
|
|
192
232
|
o = { minimum: 5,
|
193
233
|
maximum: 4,
|
194
234
|
between: 2..7 }
|
195
|
-
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)
|
196
236
|
end
|
197
237
|
|
198
238
|
it 'fails if :maximum is not met' do
|
199
239
|
o = { minimum: 0,
|
200
240
|
maximum: 0,
|
201
241
|
between: 2..7 }
|
202
|
-
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)
|
203
243
|
end
|
204
244
|
|
205
245
|
it 'fails if :between is not met' do
|
206
246
|
o = { minimum: 0,
|
207
247
|
maximum: 4,
|
208
248
|
between: 0..3 }
|
209
|
-
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)
|
210
250
|
end
|
211
251
|
|
212
252
|
it 'succeeds if all combineable expectations are met' do
|
213
253
|
o = { minimum: 0,
|
214
254
|
maximum: 4,
|
215
255
|
between: 2..7 }
|
216
|
-
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
|
256
|
+
expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
|
217
257
|
end
|
218
258
|
end
|
219
259
|
end
|
@@ -157,7 +157,7 @@ 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
163
|
context 'with no :count expectation' do
|
@@ -165,28 +165,28 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|
165
165
|
o = { minimum: 6,
|
166
166
|
maximum: 5,
|
167
167
|
between: 2..7 }
|
168
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
168
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'fails if :maximum is not met' do
|
172
172
|
o = { minimum: 0,
|
173
173
|
maximum: 0,
|
174
174
|
between: 2..7 }
|
175
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
175
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'fails if :between is not met' do
|
179
179
|
o = { minimum: 0,
|
180
180
|
maximum: 5,
|
181
181
|
between: 0..4 }
|
182
|
-
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
182
|
+
expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
|
183
183
|
end
|
184
184
|
|
185
185
|
it 'succeeds if all combineable expectations are met' do
|
186
186
|
o = { minimum: 0,
|
187
187
|
maximum: 5,
|
188
188
|
between: 2..7 }
|
189
|
-
expect { @session.assert_text('Header', o) }.not_to raise_error
|
189
|
+
expect { @session.assert_text('Header', **o) }.not_to raise_error
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|