capybara 3.29.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 +91 -1
- data/README.md +10 -3
- data/lib/capybara.rb +17 -7
- data/lib/capybara/config.rb +7 -3
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +3 -1
- data/lib/capybara/minitest.rb +232 -144
- data/lib/capybara/minitest/spec.rb +153 -97
- data/lib/capybara/node/actions.rb +35 -35
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +23 -16
- data/lib/capybara/node/finders.rb +17 -11
- data/lib/capybara/node/matchers.rb +64 -51
- data/lib/capybara/node/simple.rb +4 -2
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/selector_query.rb +25 -5
- data/lib/capybara/queries/sibling_query.rb +1 -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 +7 -2
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +1 -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 +34 -17
- data/lib/capybara/selector/css.rb +1 -1
- data/lib/capybara/selector/definition.rb +7 -6
- data/lib/capybara/selector/definition/button.rb +8 -2
- 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 +1 -1
- data/lib/capybara/selector/definition/datalist_option.rb +1 -1
- data/lib/capybara/selector/definition/element.rb +1 -1
- 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 +4 -2
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/radio_button.rb +2 -2
- data/lib/capybara/selector/definition/select.rb +32 -13
- data/lib/capybara/selector/definition/table.rb +6 -3
- data/lib/capybara/selector/filter_set.rb +11 -9
- 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 +8 -2
- 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 +22 -11
- 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 +30 -13
- data/lib/capybara/selenium/node.rb +97 -18
- data/lib/capybara/selenium/nodes/chrome_node.rb +11 -14
- data/lib/capybara/selenium/nodes/edge_node.rb +4 -2
- data/lib/capybara/selenium/nodes/firefox_node.rb +4 -4
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/logs.rb +3 -5
- data/lib/capybara/server.rb +15 -3
- data/lib/capybara/server/checker.rb +1 -1
- data/lib/capybara/server/middleware.rb +20 -10
- data/lib/capybara/session.rb +43 -26
- data/lib/capybara/session/config.rb +9 -3
- data/lib/capybara/session/matchers.rb +6 -6
- data/lib/capybara/spec/public/test.js +69 -6
- 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/click_button_spec.rb +16 -0
- 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_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_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +160 -29
- 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/selectors_spec.rb +15 -2
- 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 +18 -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 +16 -3
- data/spec/minitest_spec.rb +1 -1
- data/spec/minitest_spec_spec.rb +46 -46
- data/spec/rack_test_spec.rb +13 -1
- data/spec/regexp_dissassembler_spec.rb +40 -36
- data/spec/result_spec.rb +43 -32
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/shared_spec_matchers.rb +68 -56
- data/spec/rspec_spec.rb +4 -4
- data/spec/selector_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +9 -6
- data/spec/selenium_spec_chrome_remote.rb +2 -0
- data/spec/selenium_spec_firefox.rb +7 -2
- data/spec/server_spec.rb +65 -31
- data/spec/session_spec.rb +1 -1
- data/spec/shared_selenium_node.rb +21 -3
- data/spec/shared_selenium_session.rb +33 -14
- data/spec/spec_helper.rb +1 -1
- metadata +6 -4
@@ -42,7 +42,7 @@ module Capybara
|
|
42
42
|
# @return [Boolean]
|
43
43
|
#
|
44
44
|
def has_title?(title, **options)
|
45
|
-
make_predicate(options) { assert_title(title, options) }
|
45
|
+
make_predicate(options) { assert_title(title, **options) }
|
46
46
|
end
|
47
47
|
|
48
48
|
##
|
@@ -52,13 +52,13 @@ module Capybara
|
|
52
52
|
# @return [Boolean]
|
53
53
|
#
|
54
54
|
def has_no_title?(title, **options)
|
55
|
-
make_predicate(options) { assert_no_title(title, options) }
|
55
|
+
make_predicate(options) { assert_no_title(title, **options) }
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
60
|
def _verify_title(title, options)
|
61
|
-
query = Capybara::Queries::TitleQuery.new(title, options)
|
61
|
+
query = Capybara::Queries::TitleQuery.new(title, **options)
|
62
62
|
synchronize(query.wait) { yield(query) }
|
63
63
|
true
|
64
64
|
end
|
@@ -27,9 +27,11 @@ module Capybara
|
|
27
27
|
@query_scope = query_scope
|
28
28
|
@query = query
|
29
29
|
@allow_reload = false
|
30
|
+
@query_idx = nil
|
30
31
|
end
|
31
32
|
|
32
|
-
def allow_reload!
|
33
|
+
def allow_reload!(idx = nil)
|
34
|
+
@query_idx = idx
|
33
35
|
@allow_reload = true
|
34
36
|
end
|
35
37
|
|
@@ -113,10 +115,12 @@ module Capybara
|
|
113
115
|
#
|
114
116
|
# @return [Capybara::Node::Element] The element
|
115
117
|
def set(value, **options)
|
116
|
-
|
118
|
+
if ENV['CAPYBARA_THOROUGH'] && readonly?
|
119
|
+
raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}"
|
120
|
+
end
|
117
121
|
|
118
122
|
options = session_options.default_set_options.to_h.merge(options)
|
119
|
-
synchronize { base.set(value, options) }
|
123
|
+
synchronize { base.set(value, **options) }
|
120
124
|
self
|
121
125
|
end
|
122
126
|
|
@@ -161,10 +165,11 @@ module Capybara
|
|
161
165
|
# offset will be from the element center, otherwise it will be from the top left corner of the element
|
162
166
|
# @option options [Integer] y Y coordinate to offset the click location. If {Capybara.configure w3c_click_offset} is `true` the
|
163
167
|
# offset will be from the element center, otherwise it will be from the top left corner of the element
|
168
|
+
# @option options [Float] delay Delay between the mouse down and mouse up events in seconds (0)
|
164
169
|
# @return [Capybara::Node::Element] The element
|
165
170
|
def click(*keys, **options)
|
166
|
-
perform_click_action(keys, options) do |k, opts|
|
167
|
-
base.click(k, opts)
|
171
|
+
perform_click_action(keys, **options) do |k, opts|
|
172
|
+
base.click(k, **opts)
|
168
173
|
end
|
169
174
|
end
|
170
175
|
|
@@ -174,10 +179,11 @@ module Capybara
|
|
174
179
|
#
|
175
180
|
# @macro action_waiting_behavior
|
176
181
|
# @macro click_modifiers
|
182
|
+
# @option options [Float] delay Delay between the mouse down and mouse up events in seconds (0)
|
177
183
|
# @return [Capybara::Node::Element] The element
|
178
184
|
def right_click(*keys, **options)
|
179
|
-
perform_click_action(keys, options) do |k, opts|
|
180
|
-
base.right_click(k, opts)
|
185
|
+
perform_click_action(keys, **options) do |k, opts|
|
186
|
+
base.right_click(k, **opts)
|
181
187
|
end
|
182
188
|
end
|
183
189
|
|
@@ -189,8 +195,8 @@ module Capybara
|
|
189
195
|
# @macro click_modifiers
|
190
196
|
# @return [Capybara::Node::Element] The element
|
191
197
|
def double_click(*keys, **options)
|
192
|
-
perform_click_action(keys, options) do |k, opts|
|
193
|
-
base.double_click(k, opts)
|
198
|
+
perform_click_action(keys, **options) do |k, opts|
|
199
|
+
base.double_click(k, **opts)
|
194
200
|
end
|
195
201
|
end
|
196
202
|
|
@@ -405,6 +411,8 @@ module Capybara
|
|
405
411
|
# @option options [Boolean] :html5 When using Chrome/Firefox with Selenium enables to force the use of HTML5
|
406
412
|
# (true) or legacy (false) dragging. If not specified the driver will attempt to
|
407
413
|
# detect the correct method to use.
|
414
|
+
# @option options [Array<Symbol>,Symbol] :drop_modifiers Modifier keys which should be held while the dragged element is dropped.
|
415
|
+
#
|
408
416
|
#
|
409
417
|
# @return [Capybara::Node::Element] The dragged element
|
410
418
|
def drag_to(node, **options)
|
@@ -543,14 +551,13 @@ module Capybara
|
|
543
551
|
|
544
552
|
# @api private
|
545
553
|
def reload
|
546
|
-
|
547
|
-
begin
|
548
|
-
reloaded = @query.resolve_for(query_scope.reload)&.first
|
554
|
+
return self unless @allow_reload
|
549
555
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
556
|
+
begin
|
557
|
+
reloaded = @query.resolve_for(query_scope.reload)[@query_idx.to_i]
|
558
|
+
@base = reloaded.base if reloaded
|
559
|
+
rescue StandardError => e
|
560
|
+
raise e unless catch_error?(e)
|
554
561
|
end
|
555
562
|
self
|
556
563
|
end
|
@@ -49,7 +49,7 @@ module Capybara
|
|
49
49
|
#
|
50
50
|
def find(*args, **options, &optional_filter_block)
|
51
51
|
options[:session_options] = session_options
|
52
|
-
synced_resolve Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
|
52
|
+
synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
|
53
53
|
end
|
54
54
|
|
55
55
|
##
|
@@ -72,7 +72,7 @@ module Capybara
|
|
72
72
|
#
|
73
73
|
def ancestor(*args, **options, &optional_filter_block)
|
74
74
|
options[:session_options] = session_options
|
75
|
-
synced_resolve Capybara::Queries::AncestorQuery.new(*args, options, &optional_filter_block)
|
75
|
+
synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block)
|
76
76
|
end
|
77
77
|
|
78
78
|
##
|
@@ -95,7 +95,7 @@ module Capybara
|
|
95
95
|
#
|
96
96
|
def sibling(*args, **options, &optional_filter_block)
|
97
97
|
options[:session_options] = session_options
|
98
|
-
synced_resolve Capybara::Queries::SiblingQuery.new(*args, options, &optional_filter_block)
|
98
|
+
synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block)
|
99
99
|
end
|
100
100
|
|
101
101
|
##
|
@@ -125,7 +125,7 @@ module Capybara
|
|
125
125
|
# @return [Capybara::Node::Element] The found element
|
126
126
|
#
|
127
127
|
def find_field(locator = nil, **options, &optional_filter_block)
|
128
|
-
find(:field, locator, options, &optional_filter_block)
|
128
|
+
find(:field, locator, **options, &optional_filter_block)
|
129
129
|
end
|
130
130
|
|
131
131
|
##
|
@@ -145,7 +145,7 @@ module Capybara
|
|
145
145
|
# @return [Capybara::Node::Element] The found element
|
146
146
|
#
|
147
147
|
def find_link(locator = nil, **options, &optional_filter_block)
|
148
|
-
find(:link, locator, options, &optional_filter_block)
|
148
|
+
find(:link, locator, **options, &optional_filter_block)
|
149
149
|
end
|
150
150
|
|
151
151
|
##
|
@@ -172,7 +172,7 @@ module Capybara
|
|
172
172
|
# @return [Capybara::Node::Element] The found element
|
173
173
|
#
|
174
174
|
def find_button(locator = nil, **options, &optional_filter_block)
|
175
|
-
find(:button, locator, options, &optional_filter_block)
|
175
|
+
find(:button, locator, **options, &optional_filter_block)
|
176
176
|
end
|
177
177
|
|
178
178
|
##
|
@@ -186,7 +186,7 @@ module Capybara
|
|
186
186
|
# @return [Capybara::Node::Element] The found element
|
187
187
|
#
|
188
188
|
def find_by_id(id, **options, &optional_filter_block)
|
189
|
-
find(:id, id, options, &optional_filter_block)
|
189
|
+
find(:id, id, **options, &optional_filter_block)
|
190
190
|
end
|
191
191
|
|
192
192
|
##
|
@@ -235,21 +235,25 @@ module Capybara
|
|
235
235
|
# @option options [Integer] maximum Maximum number of matches that are expected to be found
|
236
236
|
# @option options [Integer] minimum Minimum number of matches that are expected to be found
|
237
237
|
# @option options [Range] between Number of matches found must be within the given range
|
238
|
+
# @option options [Boolean] allow_reload Beta feature - May be removed in any version.
|
239
|
+
# When `true` allows elements to be reloaded if they become stale. This is an advanced behavior and should only be used
|
240
|
+
# if you fully understand the potential ramifications. The results can be confusing on dynamic pages. Defaults to `false`
|
238
241
|
# @overload all([kind = Capybara.default_selector], locator = nil, **options)
|
239
242
|
# @overload all([kind = Capybara.default_selector], locator = nil, **options, &filter_block)
|
240
243
|
# @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
|
241
244
|
# @yieldreturn [Boolean] Should the element be considered in the results?
|
242
245
|
# @return [Capybara::Result] A collection of found elements
|
243
246
|
# @raise [Capybara::ExpectationNotMet] The number of elements found doesn't match the specified conditions
|
244
|
-
def all(*args, **options, &optional_filter_block)
|
247
|
+
def all(*args, allow_reload: false, **options, &optional_filter_block)
|
245
248
|
minimum_specified = options_include_minimum?(options)
|
246
249
|
options = { minimum: 1 }.merge(options) unless minimum_specified
|
247
250
|
options[:session_options] = session_options
|
248
|
-
query = Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
|
251
|
+
query = Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
|
249
252
|
result = nil
|
250
253
|
begin
|
251
254
|
synchronize(query.wait) do
|
252
255
|
result = query.resolve_for(self)
|
256
|
+
result.allow_reload! if allow_reload
|
253
257
|
raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
|
254
258
|
|
255
259
|
result
|
@@ -278,7 +282,7 @@ module Capybara
|
|
278
282
|
#
|
279
283
|
def first(*args, **options, &optional_filter_block)
|
280
284
|
options = { minimum: 1 }.merge(options) unless options_include_minimum?(options)
|
281
|
-
all(*args, options, &optional_filter_block).first
|
285
|
+
all(*args, **options, &optional_filter_block).first
|
282
286
|
end
|
283
287
|
|
284
288
|
private
|
@@ -292,7 +296,9 @@ module Capybara
|
|
292
296
|
result = query.resolve_for(self)
|
293
297
|
end
|
294
298
|
|
295
|
-
|
299
|
+
if ambiguous?(query, result)
|
300
|
+
raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.applied_description}"
|
301
|
+
end
|
296
302
|
raise Capybara::ElementNotFound, "Unable to find #{query.applied_description}" if result.empty?
|
297
303
|
|
298
304
|
result.first
|
@@ -61,7 +61,7 @@ module Capybara
|
|
61
61
|
# @return [Boolean] If the styles match
|
62
62
|
#
|
63
63
|
def matches_style?(styles, **options)
|
64
|
-
make_predicate(options) { assert_matches_style(styles, options) }
|
64
|
+
make_predicate(options) { assert_matches_style(styles, **options) }
|
65
65
|
end
|
66
66
|
|
67
67
|
##
|
@@ -107,7 +107,9 @@ module Capybara
|
|
107
107
|
#
|
108
108
|
def assert_selector(*args, &optional_filter_block)
|
109
109
|
_verify_selector_result(args, optional_filter_block) do |result, query|
|
110
|
-
|
110
|
+
unless result.matches_count? && (result.any? || query.expects_none?)
|
111
|
+
raise Capybara::ExpectationNotMet, result.failure_message
|
112
|
+
end
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
@@ -121,8 +123,8 @@ module Capybara
|
|
121
123
|
# @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles
|
122
124
|
#
|
123
125
|
def assert_matches_style(styles, **options)
|
124
|
-
query_args = _set_query_session_options(styles, options)
|
125
|
-
query = Capybara::Queries::StyleQuery.new(*query_args)
|
126
|
+
query_args, query_opts = _set_query_session_options(styles, options)
|
127
|
+
query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)
|
126
128
|
synchronize(query.wait) do
|
127
129
|
raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self)
|
128
130
|
end
|
@@ -153,7 +155,7 @@ module Capybara
|
|
153
155
|
# @overload assert_all_of_selectors([kind = Capybara.default_selector], *locators, **options)
|
154
156
|
#
|
155
157
|
def assert_all_of_selectors(*args, **options, &optional_filter_block)
|
156
|
-
_verify_multiple(*args, options) do |selector, locator, opts|
|
158
|
+
_verify_multiple(*args, **options) do |selector, locator, opts|
|
157
159
|
assert_selector(selector, locator, opts, &optional_filter_block)
|
158
160
|
end
|
159
161
|
end
|
@@ -174,7 +176,7 @@ module Capybara
|
|
174
176
|
# @overload assert_none_of_selectors([kind = Capybara.default_selector], *locators, **options)
|
175
177
|
#
|
176
178
|
def assert_none_of_selectors(*args, **options, &optional_filter_block)
|
177
|
-
_verify_multiple(*args, options) do |selector, locator, opts|
|
179
|
+
_verify_multiple(*args, **options) do |selector, locator, opts|
|
178
180
|
assert_no_selector(selector, locator, opts, &optional_filter_block)
|
179
181
|
end
|
180
182
|
end
|
@@ -199,12 +201,10 @@ module Capybara
|
|
199
201
|
selector = extract_selector(args)
|
200
202
|
synchronize(wait) do
|
201
203
|
res = args.map do |locator|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
e.message
|
207
|
-
end
|
204
|
+
assert_selector(selector, locator, options, &optional_filter_block)
|
205
|
+
break nil
|
206
|
+
rescue Capybara::ExpectationNotMet => e
|
207
|
+
e.message
|
208
208
|
end
|
209
209
|
raise Capybara::ExpectationNotMet, res.join(' or ') if res
|
210
210
|
|
@@ -266,7 +266,7 @@ module Capybara
|
|
266
266
|
# @return [Boolean] If the expression exists
|
267
267
|
#
|
268
268
|
def has_xpath?(path, **options, &optional_filter_block)
|
269
|
-
has_selector?(:xpath, path, options, &optional_filter_block)
|
269
|
+
has_selector?(:xpath, path, **options, &optional_filter_block)
|
270
270
|
end
|
271
271
|
|
272
272
|
##
|
@@ -278,7 +278,7 @@ module Capybara
|
|
278
278
|
# @return [Boolean]
|
279
279
|
#
|
280
280
|
def has_no_xpath?(path, **options, &optional_filter_block)
|
281
|
-
has_no_selector?(:xpath, path, options, &optional_filter_block)
|
281
|
+
has_no_selector?(:xpath, path, **options, &optional_filter_block)
|
282
282
|
end
|
283
283
|
|
284
284
|
##
|
@@ -305,7 +305,7 @@ module Capybara
|
|
305
305
|
# @return [Boolean] If the selector exists
|
306
306
|
#
|
307
307
|
def has_css?(path, **options, &optional_filter_block)
|
308
|
-
has_selector?(:css, path, options, &optional_filter_block)
|
308
|
+
has_selector?(:css, path, **options, &optional_filter_block)
|
309
309
|
end
|
310
310
|
|
311
311
|
##
|
@@ -317,7 +317,7 @@ module Capybara
|
|
317
317
|
# @return [Boolean]
|
318
318
|
#
|
319
319
|
def has_no_css?(path, **options, &optional_filter_block)
|
320
|
-
has_no_selector?(:css, path, options, &optional_filter_block)
|
320
|
+
has_no_selector?(:css, path, **options, &optional_filter_block)
|
321
321
|
end
|
322
322
|
|
323
323
|
##
|
@@ -330,7 +330,7 @@ module Capybara
|
|
330
330
|
# @return [Boolean] Whether it exists
|
331
331
|
#
|
332
332
|
def has_link?(locator = nil, **options, &optional_filter_block)
|
333
|
-
has_selector?(:link, locator, options, &optional_filter_block)
|
333
|
+
has_selector?(:link, locator, **options, &optional_filter_block)
|
334
334
|
end
|
335
335
|
|
336
336
|
##
|
@@ -342,7 +342,7 @@ module Capybara
|
|
342
342
|
# @return [Boolean] Whether it doesn't exist
|
343
343
|
#
|
344
344
|
def has_no_link?(locator = nil, **options, &optional_filter_block)
|
345
|
-
has_no_selector?(:link, locator, options, &optional_filter_block)
|
345
|
+
has_no_selector?(:link, locator, **options, &optional_filter_block)
|
346
346
|
end
|
347
347
|
|
348
348
|
##
|
@@ -354,7 +354,7 @@ module Capybara
|
|
354
354
|
# @return [Boolean] Whether it exists
|
355
355
|
#
|
356
356
|
def has_button?(locator = nil, **options, &optional_filter_block)
|
357
|
-
has_selector?(:button, locator, options, &optional_filter_block)
|
357
|
+
has_selector?(:button, locator, **options, &optional_filter_block)
|
358
358
|
end
|
359
359
|
|
360
360
|
##
|
@@ -366,7 +366,7 @@ module Capybara
|
|
366
366
|
# @return [Boolean] Whether it doesn't exist
|
367
367
|
#
|
368
368
|
def has_no_button?(locator = nil, **options, &optional_filter_block)
|
369
|
-
has_no_selector?(:button, locator, options, &optional_filter_block)
|
369
|
+
has_no_selector?(:button, locator, **options, &optional_filter_block)
|
370
370
|
end
|
371
371
|
|
372
372
|
##
|
@@ -392,7 +392,7 @@ module Capybara
|
|
392
392
|
# @return [Boolean] Whether it exists
|
393
393
|
#
|
394
394
|
def has_field?(locator = nil, **options, &optional_filter_block)
|
395
|
-
has_selector?(:field, locator, options, &optional_filter_block)
|
395
|
+
has_selector?(:field, locator, **options, &optional_filter_block)
|
396
396
|
end
|
397
397
|
|
398
398
|
##
|
@@ -406,7 +406,7 @@ module Capybara
|
|
406
406
|
# @return [Boolean] Whether it doesn't exist
|
407
407
|
#
|
408
408
|
def has_no_field?(locator = nil, **options, &optional_filter_block)
|
409
|
-
has_no_selector?(:field, locator, options, &optional_filter_block)
|
409
|
+
has_no_selector?(:field, locator, **options, &optional_filter_block)
|
410
410
|
end
|
411
411
|
|
412
412
|
##
|
@@ -419,7 +419,7 @@ module Capybara
|
|
419
419
|
# @return [Boolean] Whether it exists
|
420
420
|
#
|
421
421
|
def has_checked_field?(locator = nil, **options, &optional_filter_block)
|
422
|
-
has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
422
|
+
has_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block)
|
423
423
|
end
|
424
424
|
|
425
425
|
##
|
@@ -432,7 +432,7 @@ module Capybara
|
|
432
432
|
# @return [Boolean] Whether it doesn't exist
|
433
433
|
#
|
434
434
|
def has_no_checked_field?(locator = nil, **options, &optional_filter_block)
|
435
|
-
has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
435
|
+
has_no_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block)
|
436
436
|
end
|
437
437
|
|
438
438
|
##
|
@@ -445,7 +445,7 @@ module Capybara
|
|
445
445
|
# @return [Boolean] Whether it exists
|
446
446
|
#
|
447
447
|
def has_unchecked_field?(locator = nil, **options, &optional_filter_block)
|
448
|
-
has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
448
|
+
has_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block)
|
449
449
|
end
|
450
450
|
|
451
451
|
##
|
@@ -458,7 +458,7 @@ module Capybara
|
|
458
458
|
# @return [Boolean] Whether it doesn't exist
|
459
459
|
#
|
460
460
|
def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)
|
461
|
-
has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
461
|
+
has_no_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block)
|
462
462
|
end
|
463
463
|
|
464
464
|
##
|
@@ -491,7 +491,7 @@ module Capybara
|
|
491
491
|
# @return [Boolean] Whether it exists
|
492
492
|
#
|
493
493
|
def has_select?(locator = nil, **options, &optional_filter_block)
|
494
|
-
has_selector?(:select, locator, options, &optional_filter_block)
|
494
|
+
has_selector?(:select, locator, **options, &optional_filter_block)
|
495
495
|
end
|
496
496
|
|
497
497
|
##
|
@@ -503,7 +503,7 @@ module Capybara
|
|
503
503
|
# @return [Boolean] Whether it doesn't exist
|
504
504
|
#
|
505
505
|
def has_no_select?(locator = nil, **options, &optional_filter_block)
|
506
|
-
has_no_selector?(:select, locator, options, &optional_filter_block)
|
506
|
+
has_no_selector?(:select, locator, **options, &optional_filter_block)
|
507
507
|
end
|
508
508
|
|
509
509
|
##
|
@@ -525,7 +525,7 @@ module Capybara
|
|
525
525
|
# @return [Boolean] Whether it exists
|
526
526
|
#
|
527
527
|
def has_table?(locator = nil, **options, &optional_filter_block)
|
528
|
-
has_selector?(:table, locator, options, &optional_filter_block)
|
528
|
+
has_selector?(:table, locator, **options, &optional_filter_block)
|
529
529
|
end
|
530
530
|
|
531
531
|
##
|
@@ -537,7 +537,7 @@ module Capybara
|
|
537
537
|
# @return [Boolean] Whether it doesn't exist
|
538
538
|
#
|
539
539
|
def has_no_table?(locator = nil, **options, &optional_filter_block)
|
540
|
-
has_no_selector?(:table, locator, options, &optional_filter_block)
|
540
|
+
has_no_selector?(:table, locator, **options, &optional_filter_block)
|
541
541
|
end
|
542
542
|
|
543
543
|
##
|
@@ -595,7 +595,7 @@ module Capybara
|
|
595
595
|
# @return [Boolean]
|
596
596
|
#
|
597
597
|
def matches_xpath?(xpath, **options, &optional_filter_block)
|
598
|
-
matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
598
|
+
matches_selector?(:xpath, xpath, **options, &optional_filter_block)
|
599
599
|
end
|
600
600
|
|
601
601
|
##
|
@@ -606,7 +606,7 @@ module Capybara
|
|
606
606
|
# @return [Boolean]
|
607
607
|
#
|
608
608
|
def matches_css?(css, **options, &optional_filter_block)
|
609
|
-
matches_selector?(:css, css, options, &optional_filter_block)
|
609
|
+
matches_selector?(:css, css, **options, &optional_filter_block)
|
610
610
|
end
|
611
611
|
|
612
612
|
##
|
@@ -629,7 +629,7 @@ module Capybara
|
|
629
629
|
# @return [Boolean]
|
630
630
|
#
|
631
631
|
def not_matches_xpath?(xpath, **options, &optional_filter_block)
|
632
|
-
not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
632
|
+
not_matches_selector?(:xpath, xpath, **options, &optional_filter_block)
|
633
633
|
end
|
634
634
|
|
635
635
|
##
|
@@ -640,7 +640,7 @@ module Capybara
|
|
640
640
|
# @return [Boolean]
|
641
641
|
#
|
642
642
|
def not_matches_css?(css, **options, &optional_filter_block)
|
643
|
-
not_matches_selector?(:css, css, options, &optional_filter_block)
|
643
|
+
not_matches_selector?(:css, css, **options, &optional_filter_block)
|
644
644
|
end
|
645
645
|
|
646
646
|
##
|
@@ -670,8 +670,8 @@ module Capybara
|
|
670
670
|
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
|
671
671
|
# @return [true]
|
672
672
|
#
|
673
|
-
def assert_text(*args)
|
674
|
-
_verify_text(args) do |count, query|
|
673
|
+
def assert_text(type_or_text, *args, **opts)
|
674
|
+
_verify_text(type_or_text, *args, **opts) do |count, query|
|
675
675
|
unless query.matches_count?(count) && (count.positive? || query.expects_none?)
|
676
676
|
raise Capybara::ExpectationNotMet, query.failure_message
|
677
677
|
end
|
@@ -686,8 +686,8 @@ module Capybara
|
|
686
686
|
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
|
687
687
|
# @return [true]
|
688
688
|
#
|
689
|
-
def assert_no_text(*args)
|
690
|
-
_verify_text(args) do |count, query|
|
689
|
+
def assert_no_text(type_or_text, *args, **opts)
|
690
|
+
_verify_text(type_or_text, *args, **opts) do |count, query|
|
691
691
|
if query.matches_count?(count) && (count.positive? || query.expects_none?)
|
692
692
|
raise Capybara::ExpectationNotMet, query.negative_failure_message
|
693
693
|
end
|
@@ -709,7 +709,7 @@ module Capybara
|
|
709
709
|
# @return [Boolean] Whether it exists
|
710
710
|
#
|
711
711
|
def has_text?(*args, **options)
|
712
|
-
make_predicate(options) { assert_text(*args, options) }
|
712
|
+
make_predicate(options) { assert_text(*args, **options) }
|
713
713
|
end
|
714
714
|
alias_method :has_content?, :has_text?
|
715
715
|
|
@@ -721,7 +721,7 @@ module Capybara
|
|
721
721
|
# @return [Boolean] Whether it doesn't exist
|
722
722
|
#
|
723
723
|
def has_no_text?(*args, **options)
|
724
|
-
make_predicate(options) { assert_no_text(*args, options) }
|
724
|
+
make_predicate(options) { assert_no_text(*args, **options) }
|
725
725
|
end
|
726
726
|
alias_method :has_no_content?, :has_no_text?
|
727
727
|
|
@@ -738,7 +738,9 @@ module Capybara
|
|
738
738
|
#
|
739
739
|
def assert_ancestor(*args, &optional_filter_block)
|
740
740
|
_verify_selector_result(args, optional_filter_block, Capybara::Queries::AncestorQuery) do |result, query|
|
741
|
-
|
741
|
+
unless result.matches_count? && (result.any? || query.expects_none?)
|
742
|
+
raise Capybara::ExpectationNotMet, result.failure_message
|
743
|
+
end
|
742
744
|
end
|
743
745
|
end
|
744
746
|
|
@@ -779,7 +781,9 @@ module Capybara
|
|
779
781
|
#
|
780
782
|
def assert_sibling(*args, &optional_filter_block)
|
781
783
|
_verify_selector_result(args, optional_filter_block, Capybara::Queries::SiblingQuery) do |result, query|
|
782
|
-
|
784
|
+
unless result.matches_count? && (result.any? || query.expects_none?)
|
785
|
+
raise Capybara::ExpectationNotMet, result.failure_message
|
786
|
+
end
|
783
787
|
end
|
784
788
|
end
|
785
789
|
|
@@ -826,8 +830,14 @@ module Capybara
|
|
826
830
|
end
|
827
831
|
|
828
832
|
def _verify_selector_result(query_args, optional_filter_block, query_type = Capybara::Queries::SelectorQuery)
|
829
|
-
query_args =
|
830
|
-
|
833
|
+
# query_args, query_opts = if query_args[0].is_a? Symbol
|
834
|
+
# a,o = _set_query_session_options(*query_args.slice(2..))
|
835
|
+
# [query_args.slice(0..1).concat(a), o]
|
836
|
+
# else
|
837
|
+
# _set_query_session_options(*query_args)
|
838
|
+
# end
|
839
|
+
query_args, query_opts = _set_query_session_options(*query_args)
|
840
|
+
query = query_type.new(*query_args, **query_opts, &optional_filter_block)
|
831
841
|
synchronize(query.wait) do
|
832
842
|
yield query.resolve_for(self), query
|
833
843
|
end
|
@@ -835,26 +845,29 @@ module Capybara
|
|
835
845
|
end
|
836
846
|
|
837
847
|
def _verify_match_result(query_args, optional_filter_block)
|
838
|
-
query_args = _set_query_session_options(*query_args)
|
839
|
-
query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
|
848
|
+
query_args, query_opts = _set_query_session_options(*query_args)
|
849
|
+
query = Capybara::Queries::MatchQuery.new(*query_args, **query_opts, &optional_filter_block)
|
840
850
|
synchronize(query.wait) do
|
841
851
|
yield query.resolve_for(parent || session&.document || query_scope)
|
842
852
|
end
|
843
853
|
true
|
844
854
|
end
|
845
855
|
|
846
|
-
def _verify_text(
|
847
|
-
|
848
|
-
query = Capybara::Queries::TextQuery.new(
|
856
|
+
def _verify_text(type = nil, expected_text, **query_options) # rubocop:disable Style/OptionalArguments
|
857
|
+
query_options[:session_options] = session_options
|
858
|
+
query = Capybara::Queries::TextQuery.new(type, expected_text, **query_options)
|
849
859
|
synchronize(query.wait) do
|
850
860
|
yield query.resolve_for(self), query
|
851
861
|
end
|
852
862
|
true
|
853
863
|
end
|
854
864
|
|
855
|
-
def _set_query_session_options(*query_args
|
865
|
+
def _set_query_session_options(*query_args)
|
866
|
+
query_args, query_options = query_args.dup, {}
|
867
|
+
# query_options = query_args.pop if query_options.empty? && query_args.last.is_a?(Hash)
|
868
|
+
query_options = query_args.pop if query_args.last.is_a?(Hash)
|
856
869
|
query_options[:session_options] = session_options
|
857
|
-
query_args
|
870
|
+
[query_args, query_options]
|
858
871
|
end
|
859
872
|
|
860
873
|
def make_predicate(options)
|