capybara 2.18.0 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +26 -1
- data/README.md +12 -12
- data/lib/capybara.rb +13 -25
- data/lib/capybara/config.rb +11 -57
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +5 -16
- data/lib/capybara/driver/node.rb +5 -4
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +16 -28
- data/lib/capybara/minitest.rb +139 -138
- data/lib/capybara/minitest/spec.rb +15 -14
- data/lib/capybara/node/actions.rb +59 -81
- data/lib/capybara/node/base.rb +11 -18
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +8 -8
- data/lib/capybara/node/element.rb +30 -40
- data/lib/capybara/node/finders.rb +62 -70
- data/lib/capybara/node/matchers.rb +48 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +4 -6
- data/lib/capybara/queries/base_query.rb +18 -17
- data/lib/capybara/queries/current_path_query.rb +8 -24
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +92 -95
- data/lib/capybara/queries/sibling_query.rb +4 -4
- data/lib/capybara/queries/text_query.rb +37 -34
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +15 -18
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +6 -10
- data/lib/capybara/rack_test/form.rb +50 -40
- data/lib/capybara/rack_test/node.rb +70 -56
- data/lib/capybara/rails.rb +2 -6
- data/lib/capybara/result.rb +22 -22
- data/lib/capybara/rspec.rb +5 -10
- data/lib/capybara/rspec/compound.rb +5 -10
- data/lib/capybara/rspec/features.rb +17 -48
- data/lib/capybara/rspec/matcher_proxies.rb +31 -15
- data/lib/capybara/rspec/matchers.rb +70 -60
- data/lib/capybara/selector.rb +129 -117
- data/lib/capybara/selector/css.rb +6 -11
- data/lib/capybara/selector/filter.rb +1 -17
- data/lib/capybara/selector/filter_set.rb +17 -14
- data/lib/capybara/selector/filters/base.rb +7 -6
- data/lib/capybara/selector/filters/expression_filter.rb +6 -23
- data/lib/capybara/selector/filters/node_filter.rb +2 -12
- data/lib/capybara/selector/selector.rb +27 -33
- data/lib/capybara/selenium/driver.rb +113 -127
- data/lib/capybara/selenium/node.rb +148 -113
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session.rb +137 -223
- data/lib/capybara/session/config.rb +47 -67
- data/lib/capybara/session/matchers.rb +8 -7
- data/lib/capybara/spec/public/test.js +26 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/all_spec.rb +31 -18
- data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
- data/lib/capybara/spec/session/assert_current_path.rb +12 -11
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +18 -17
- data/lib/capybara/spec/session/assert_title.rb +1 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +7 -6
- data/lib/capybara/spec/session/choose_spec.rb +5 -4
- data/lib/capybara/spec/session/click_button_spec.rb +20 -28
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
- data/lib/capybara/spec/session/click_link_spec.rb +8 -7
- data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
- data/lib/capybara/spec/session/current_url_spec.rb +7 -6
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
- data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -5
- data/lib/capybara/spec/session/find_button_spec.rb +4 -3
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
- data/lib/capybara/spec/session/find_field_spec.rb +8 -14
- data/lib/capybara/spec/session/find_link_spec.rb +6 -5
- data/lib/capybara/spec/session/find_spec.rb +37 -31
- data/lib/capybara/spec/session/first_spec.rb +60 -33
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
- data/lib/capybara/spec/session/has_button_spec.rb +2 -1
- data/lib/capybara/spec/session/has_css_spec.rb +3 -2
- data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +1 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_select_spec.rb +30 -29
- data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
- data/lib/capybara/spec/session/has_table_spec.rb +2 -1
- data/lib/capybara/spec/session/has_text_spec.rb +6 -5
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +91 -56
- data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
- data/lib/capybara/spec/session/refresh_spec.rb +4 -2
- data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
- data/lib/capybara/spec/session/response_code.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
- data/lib/capybara/spec/session/save_page_spec.rb +1 -17
- data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +20 -20
- data/lib/capybara/spec/session/selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/sibling_spec.rb +1 -1
- data/lib/capybara/spec/session/text_spec.rb +1 -0
- data/lib/capybara/spec/session/title_spec.rb +1 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
- data/lib/capybara/spec/session/unselect_spec.rb +6 -5
- data/lib/capybara/spec/session/visit_spec.rb +9 -3
- data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +12 -12
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
- data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +26 -18
- data/lib/capybara/spec/test_app.rb +8 -9
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +3 -1
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +6 -10
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +9 -32
- data/spec/dsl_spec.rb +5 -13
- data/spec/filter_set_spec.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
- data/spec/minitest_spec.rb +4 -3
- data/spec/minitest_spec_spec.rb +3 -2
- data/spec/per_session_config_spec.rb +9 -8
- data/spec/rack_test_spec.rb +21 -20
- data/spec/result_spec.rb +17 -16
- data/spec/rspec/features_spec.rb +17 -14
- data/spec/rspec/scenarios_spec.rb +5 -7
- data/spec/rspec/shared_spec_matchers.rb +96 -99
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_matchers_spec.rb +19 -2
- data/spec/rspec_spec.rb +11 -15
- data/spec/selector_spec.rb +5 -6
- data/spec/selenium_spec_chrome.rb +7 -4
- data/spec/selenium_spec_marionette.rb +26 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +27 -21
- data/spec/spec_helper.rb +2 -5
- metadata +66 -87
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Capybara
|
3
4
|
module Node
|
4
5
|
module Finders
|
5
|
-
|
6
6
|
##
|
7
7
|
#
|
8
8
|
# Find an {Capybara::Node::Element} based on the given arguments. +find+ will raise an error if the element
|
@@ -28,13 +28,9 @@ module Capybara
|
|
28
28
|
# @return [Capybara::Node::Element] The found element
|
29
29
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
30
30
|
#
|
31
|
-
def find(*args, &optional_filter_block)
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
args.push(session_options: session_options)
|
36
|
-
end
|
37
|
-
synced_resolve Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
|
31
|
+
def find(*args, **options, &optional_filter_block)
|
32
|
+
options[:session_options] = session_options
|
33
|
+
synced_resolve Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
|
38
34
|
end
|
39
35
|
|
40
36
|
##
|
@@ -57,13 +53,9 @@ module Capybara
|
|
57
53
|
# @return [Capybara::Node::Element] The found element
|
58
54
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
59
55
|
#
|
60
|
-
def ancestor(*args, &optional_filter_block)
|
61
|
-
|
62
|
-
|
63
|
-
else
|
64
|
-
args.push(session_options: session_options)
|
65
|
-
end
|
66
|
-
synced_resolve Capybara::Queries::AncestorQuery.new(*args, &optional_filter_block)
|
56
|
+
def ancestor(*args, **options, &optional_filter_block)
|
57
|
+
options[:session_options] = session_options
|
58
|
+
synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block)
|
67
59
|
end
|
68
60
|
|
69
61
|
##
|
@@ -87,13 +79,9 @@ module Capybara
|
|
87
79
|
# @return [Capybara::Node::Element] The found element
|
88
80
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
89
81
|
#
|
90
|
-
def sibling(*args, &optional_filter_block)
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
args.push(session_options: session_options)
|
95
|
-
end
|
96
|
-
synced_resolve Capybara::Queries::SiblingQuery.new(*args, &optional_filter_block)
|
82
|
+
def sibling(*args, **options, &optional_filter_block)
|
83
|
+
options[:session_options] = session_options
|
84
|
+
synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block)
|
97
85
|
end
|
98
86
|
|
99
87
|
##
|
@@ -123,11 +111,9 @@ module Capybara
|
|
123
111
|
# @return [Capybara::Node::Element] The found element
|
124
112
|
#
|
125
113
|
|
126
|
-
def find_field(locator=nil, options
|
127
|
-
locator, options = nil, locator if locator.is_a? Hash
|
114
|
+
def find_field(locator = nil, **options, &optional_filter_block)
|
128
115
|
find(:field, locator, options, &optional_filter_block)
|
129
116
|
end
|
130
|
-
alias_method :field_labeled, :find_field
|
131
117
|
|
132
118
|
##
|
133
119
|
#
|
@@ -145,8 +131,7 @@ module Capybara
|
|
145
131
|
# @option options [String, Array<String>] class Match links that match the class(es) provided
|
146
132
|
# @return [Capybara::Node::Element] The found element
|
147
133
|
#
|
148
|
-
def find_link(locator=nil, options
|
149
|
-
locator, options = nil, locator if locator.is_a? Hash
|
134
|
+
def find_link(locator = nil, **options, &optional_filter_block)
|
150
135
|
find(:link, locator, options, &optional_filter_block)
|
151
136
|
end
|
152
137
|
|
@@ -174,8 +159,7 @@ module Capybara
|
|
174
159
|
# @option options [String, Array<String>] class Match buttons that match the class(es) provided
|
175
160
|
# @return [Capybara::Node::Element] The found element
|
176
161
|
#
|
177
|
-
def find_button(locator=nil, options
|
178
|
-
locator, options = nil, locator if locator.is_a? Hash
|
162
|
+
def find_button(locator = nil, **options, &optional_filter_block)
|
179
163
|
find(:button, locator, options, &optional_filter_block)
|
180
164
|
end
|
181
165
|
|
@@ -189,7 +173,7 @@ module Capybara
|
|
189
173
|
#
|
190
174
|
# @return [Capybara::Node::Element] The found element
|
191
175
|
#
|
192
|
-
def find_by_id(id, options
|
176
|
+
def find_by_id(id, **options, &optional_filter_block)
|
193
177
|
find(:id, id, options, &optional_filter_block)
|
194
178
|
end
|
195
179
|
|
@@ -221,10 +205,11 @@ module Capybara
|
|
221
205
|
# page.all('a', text: 'Home')
|
222
206
|
# page.all('#menu li', visible: true)
|
223
207
|
#
|
224
|
-
# By default
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
208
|
+
# By default Capybara's waiting behavior will wait up to `Capybara.default_max_wait_time`
|
209
|
+
# seconds for matching elements to be available and then return an empty result if none
|
210
|
+
# are available. It is possible to set expectations on the number of results located and
|
211
|
+
# Capybara will raise an exception if the number of elements located don't satisfy the
|
212
|
+
# specified conditions. The expectations can be set using
|
228
213
|
#
|
229
214
|
# page.assert_selector('p#foo', count: 4)
|
230
215
|
# page.assert_selector('p#foo', maximum: 10)
|
@@ -235,9 +220,9 @@ module Capybara
|
|
235
220
|
# count matching.
|
236
221
|
#
|
237
222
|
# @param [Symbol] kind Optional selector type (:css, :xpath, :field, etc.) - Defaults to Capybara.default_selector
|
238
|
-
# @param [String] locator The selector
|
223
|
+
# @param [String] locator The locator for the specified selector
|
239
224
|
# @option options [String, Regexp] text Only find elements which contain this text or match this regexp
|
240
|
-
# @option options [String, Boolean] exact_text (Capybara.exact_text) When String the
|
225
|
+
# @option options [String, Boolean] exact_text (Capybara.exact_text) When String the elements contained text must match exactly, when Boolean controls whether the :text option must match exactly
|
241
226
|
# @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
|
242
227
|
# * true - only finds visible elements.
|
243
228
|
# * false - finds invisible _and_ visible elements.
|
@@ -249,24 +234,28 @@ module Capybara
|
|
249
234
|
# @option options [Integer] minimum Minimum number of matches that are expected to be found
|
250
235
|
# @option options [Range] between Number of matches found must be within the given range
|
251
236
|
# @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially
|
252
|
-
# @option options [Integer] wait (Capybara.default_max_wait_time) The time to wait for
|
237
|
+
# @option options [Integer, false] wait (Capybara.default_max_wait_time) The time to wait for matching elements to become available
|
253
238
|
# @overload all([kind = Capybara.default_selector], locator = nil, options = {})
|
254
239
|
# @overload all([kind = Capybara.default_selector], locator = nil, options = {}, &filter_block)
|
255
240
|
# @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
|
256
241
|
# @yieldreturn [Boolean] Should the element be considered in the results?
|
257
242
|
# @return [Capybara::Result] A collection of found elements
|
258
|
-
#
|
259
|
-
def all(*args, &optional_filter_block)
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
243
|
+
# @raise [Capybara::ExpectationNotMet] The number of elements found doesn't match the specified conditions
|
244
|
+
def all(*args, **options, &optional_filter_block)
|
245
|
+
minimum_specified = options_include_minimum?(options)
|
246
|
+
options = { minimum: 1 }.merge(options) unless minimum_specified
|
247
|
+
options[:session_options] = session_options
|
248
|
+
query = Capybara::Queries::SelectorQuery.new(*args.push(options), &optional_filter_block)
|
249
|
+
result = nil
|
250
|
+
begin
|
251
|
+
synchronize(query.wait) do
|
252
|
+
result = query.resolve_for(self)
|
253
|
+
raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
|
254
|
+
result
|
255
|
+
end
|
256
|
+
rescue Capybara::ExpectationNotMet
|
257
|
+
raise if minimum_specified || (result.compare_count == 1)
|
258
|
+
Result.new([], nil)
|
270
259
|
end
|
271
260
|
end
|
272
261
|
alias_method :find_all, :all
|
@@ -274,48 +263,51 @@ module Capybara
|
|
274
263
|
##
|
275
264
|
#
|
276
265
|
# Find the first element on the page matching the given selector
|
277
|
-
# and options
|
278
|
-
#
|
279
|
-
#
|
280
|
-
# return the first. Waiting behavior can also be triggered by passing in any of the count
|
281
|
-
# expectation options.
|
266
|
+
# and options. By default `first` will wait up to `Capybara.default_max_wait_time`
|
267
|
+
# seconds for matching elements to appear and then raise an error if no matching
|
268
|
+
# element is found, or `nil` if the provided count options allow for empty results.
|
282
269
|
#
|
283
270
|
# @overload first([kind], locator, options)
|
284
271
|
# @param [:css, :xpath] kind The type of selector
|
285
272
|
# @param [String] locator The selector
|
286
273
|
# @param [Hash] options Additional options; see {#all}
|
287
274
|
# @return [Capybara::Node::Element] The found element or nil
|
275
|
+
# @raise [Capybara::ElementNotFound] If element(s) matching the provided options can't be found before time expires
|
288
276
|
#
|
289
|
-
def first(*args, &optional_filter_block)
|
290
|
-
|
291
|
-
|
292
|
-
args.push({minimum: 1}.merge(options))
|
293
|
-
end
|
294
|
-
all(*args, &optional_filter_block).first
|
295
|
-
rescue Capybara::ExpectationNotMet
|
296
|
-
nil
|
277
|
+
def first(*args, **options, &optional_filter_block)
|
278
|
+
options = { minimum: 1 }.merge(options) unless options_include_minimum?(options)
|
279
|
+
all(*args, **options, &optional_filter_block).first
|
297
280
|
end
|
298
281
|
|
299
|
-
|
282
|
+
private
|
300
283
|
|
301
284
|
def synced_resolve(query)
|
302
285
|
synchronize(query.wait) do
|
303
|
-
if (query
|
286
|
+
if prefer_exact?(query)
|
304
287
|
result = query.resolve_for(self, true)
|
305
288
|
result = query.resolve_for(self, false) if result.empty? && query.supports_exact? && !query.exact?
|
306
289
|
else
|
307
290
|
result = query.resolve_for(self)
|
308
291
|
end
|
309
292
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
if result.empty?
|
314
|
-
raise Capybara::ElementNotFound.new("Unable to find #{query.description}")
|
315
|
-
end
|
293
|
+
raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.description}" if ambiguous?(query, result)
|
294
|
+
raise Capybara::ElementNotFound, "Unable to find #{query.description}" if result.empty?
|
295
|
+
|
316
296
|
result.first
|
317
297
|
end.tap(&:allow_reload!)
|
318
298
|
end
|
299
|
+
|
300
|
+
def ambiguous?(query, result)
|
301
|
+
query.match == :one or query.match == :smart and result.size > 1
|
302
|
+
end
|
303
|
+
|
304
|
+
def prefer_exact?(query)
|
305
|
+
query.match == :smart or query.match == :prefer_exact
|
306
|
+
end
|
307
|
+
|
308
|
+
def options_include_minimum?(opts)
|
309
|
+
%i[count minimum between].any? { |k| opts.key?(k) }
|
310
|
+
end
|
319
311
|
end
|
320
312
|
end
|
321
313
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Capybara
|
3
4
|
module Node
|
4
5
|
module Matchers
|
5
|
-
|
6
6
|
##
|
7
7
|
#
|
8
8
|
# Checks if a given selector is on the page or a descendant of the current node.
|
@@ -39,7 +39,7 @@ module Capybara
|
|
39
39
|
def has_selector?(*args, &optional_filter_block)
|
40
40
|
assert_selector(*args, &optional_filter_block)
|
41
41
|
rescue Capybara::ExpectationNotMet
|
42
|
-
|
42
|
+
false
|
43
43
|
end
|
44
44
|
|
45
45
|
##
|
@@ -53,7 +53,7 @@ module Capybara
|
|
53
53
|
def has_no_selector?(*args, &optional_filter_block)
|
54
54
|
assert_no_selector(*args, &optional_filter_block)
|
55
55
|
rescue Capybara::ExpectationNotMet
|
56
|
-
|
56
|
+
false
|
57
57
|
end
|
58
58
|
|
59
59
|
##
|
@@ -91,7 +91,7 @@ module Capybara
|
|
91
91
|
#
|
92
92
|
def assert_selector(*args, &optional_filter_block)
|
93
93
|
_verify_selector_result(args, optional_filter_block) do |result, query|
|
94
|
-
unless result.matches_count? && (
|
94
|
+
unless result.matches_count? && (!result.empty? || query.expects_none?)
|
95
95
|
raise Capybara::ExpectationNotMet, result.failure_message
|
96
96
|
end
|
97
97
|
end
|
@@ -112,10 +112,8 @@ module Capybara
|
|
112
112
|
#
|
113
113
|
# @overload assert_all_of_selectors([kind = Capybara.default_selector], *locators, options = {})
|
114
114
|
#
|
115
|
-
def assert_all_of_selectors(*args, &optional_filter_block)
|
116
|
-
|
117
|
-
selector = if args.first.is_a?(Symbol) then args.shift else session_options.default_selector end
|
118
|
-
wait = options.fetch(:wait, session_options.default_max_wait_time)
|
115
|
+
def assert_all_of_selectors(*args, wait: session_options.default_max_wait_time, **options, &optional_filter_block)
|
116
|
+
selector = args.first.is_a?(Symbol) ? args.shift : session_options.default_selector
|
119
117
|
synchronize(wait) do
|
120
118
|
args.each do |locator|
|
121
119
|
assert_selector(selector, locator, options, &optional_filter_block)
|
@@ -138,10 +136,8 @@ module Capybara
|
|
138
136
|
#
|
139
137
|
# @overload assert_none_of_selectors([kind = Capybara.default_selector], *locators, options = {})
|
140
138
|
#
|
141
|
-
def assert_none_of_selectors(*args, &optional_filter_block)
|
142
|
-
|
143
|
-
selector = if args.first.is_a?(Symbol) then args.shift else session_options.default_selector end
|
144
|
-
wait = options.fetch(:wait, session_options.default_max_wait_time)
|
139
|
+
def assert_none_of_selectors(*args, wait: session_options.default_max_wait_time, **options, &optional_filter_block)
|
140
|
+
selector = args.first.is_a?(Symbol) ? args.shift : session_options.default_selector
|
145
141
|
synchronize(wait) do
|
146
142
|
args.each do |locator|
|
147
143
|
assert_no_selector(selector, locator, options, &optional_filter_block)
|
@@ -167,7 +163,7 @@ module Capybara
|
|
167
163
|
#
|
168
164
|
def assert_no_selector(*args, &optional_filter_block)
|
169
165
|
_verify_selector_result(args, optional_filter_block) do |result, query|
|
170
|
-
if result.matches_count? && (
|
166
|
+
if result.matches_count? && (!result.empty? || query.expects_none?)
|
171
167
|
raise Capybara::ExpectationNotMet, result.negative_failure_message
|
172
168
|
end
|
173
169
|
end
|
@@ -203,7 +199,7 @@ module Capybara
|
|
203
199
|
# @option options [Integer] :count (nil) Number of times the expression should occur
|
204
200
|
# @return [Boolean] If the expression exists
|
205
201
|
#
|
206
|
-
def has_xpath?(path, options
|
202
|
+
def has_xpath?(path, **options, &optional_filter_block)
|
207
203
|
has_selector?(:xpath, path, options, &optional_filter_block)
|
208
204
|
end
|
209
205
|
|
@@ -215,7 +211,7 @@ module Capybara
|
|
215
211
|
# @param (see Capybara::Node::Finders#has_xpath?)
|
216
212
|
# @return [Boolean]
|
217
213
|
#
|
218
|
-
def has_no_xpath?(path, options
|
214
|
+
def has_no_xpath?(path, **options, &optional_filter_block)
|
219
215
|
has_no_selector?(:xpath, path, options, &optional_filter_block)
|
220
216
|
end
|
221
217
|
|
@@ -242,7 +238,7 @@ module Capybara
|
|
242
238
|
# @option options [Integer] :count (nil) Number of times the selector should occur
|
243
239
|
# @return [Boolean] If the selector exists
|
244
240
|
#
|
245
|
-
def has_css?(path, options
|
241
|
+
def has_css?(path, **options, &optional_filter_block)
|
246
242
|
has_selector?(:css, path, options, &optional_filter_block)
|
247
243
|
end
|
248
244
|
|
@@ -254,7 +250,7 @@ module Capybara
|
|
254
250
|
# @param (see Capybara::Node::Finders#has_css?)
|
255
251
|
# @return [Boolean]
|
256
252
|
#
|
257
|
-
def has_no_css?(path, options
|
253
|
+
def has_no_css?(path, **options, &optional_filter_block)
|
258
254
|
has_no_selector?(:css, path, options, &optional_filter_block)
|
259
255
|
end
|
260
256
|
|
@@ -268,8 +264,7 @@ module Capybara
|
|
268
264
|
# @option options [String, Regexp] :href The value the href attribute must be
|
269
265
|
# @return [Boolean] Whether it exists
|
270
266
|
#
|
271
|
-
def has_link?(locator=nil, options
|
272
|
-
locator, options = nil, locator if locator.is_a? Hash
|
267
|
+
def has_link?(locator = nil, **options, &optional_filter_block)
|
273
268
|
has_selector?(:link, locator, options, &optional_filter_block)
|
274
269
|
end
|
275
270
|
|
@@ -281,8 +276,7 @@ module Capybara
|
|
281
276
|
# @param (see Capybara::Node::Finders#has_link?)
|
282
277
|
# @return [Boolean] Whether it doesn't exist
|
283
278
|
#
|
284
|
-
def has_no_link?(locator=nil, options
|
285
|
-
locator, options = nil, locator if locator.is_a? Hash
|
279
|
+
def has_no_link?(locator = nil, **options, &optional_filter_block)
|
286
280
|
has_no_selector?(:link, locator, options, &optional_filter_block)
|
287
281
|
end
|
288
282
|
|
@@ -294,8 +288,7 @@ module Capybara
|
|
294
288
|
# @param [String] locator The text, value or id of a button to check for
|
295
289
|
# @return [Boolean] Whether it exists
|
296
290
|
#
|
297
|
-
def has_button?(locator=nil, options
|
298
|
-
locator, options = nil, locator if locator.is_a? Hash
|
291
|
+
def has_button?(locator = nil, **options, &optional_filter_block)
|
299
292
|
has_selector?(:button, locator, options, &optional_filter_block)
|
300
293
|
end
|
301
294
|
|
@@ -307,8 +300,7 @@ module Capybara
|
|
307
300
|
# @param [String] locator The text, value or id of a button to check for
|
308
301
|
# @return [Boolean] Whether it doesn't exist
|
309
302
|
#
|
310
|
-
def has_no_button?(locator=nil, options
|
311
|
-
locator, options = nil, locator if locator.is_a? Hash
|
303
|
+
def has_no_button?(locator = nil, **options, &optional_filter_block)
|
312
304
|
has_no_selector?(:button, locator, options, &optional_filter_block)
|
313
305
|
end
|
314
306
|
|
@@ -334,8 +326,7 @@ module Capybara
|
|
334
326
|
# @option options [String] :type The type attribute of the field
|
335
327
|
# @return [Boolean] Whether it exists
|
336
328
|
#
|
337
|
-
def has_field?(locator=nil, options
|
338
|
-
locator, options = nil, locator if locator.is_a? Hash
|
329
|
+
def has_field?(locator = nil, **options, &optional_filter_block)
|
339
330
|
has_selector?(:field, locator, options, &optional_filter_block)
|
340
331
|
end
|
341
332
|
|
@@ -349,8 +340,7 @@ module Capybara
|
|
349
340
|
# @option options [String] :type The type attribute of the field
|
350
341
|
# @return [Boolean] Whether it doesn't exist
|
351
342
|
#
|
352
|
-
def has_no_field?(locator=nil, options
|
353
|
-
locator, options = nil, locator if locator.is_a? Hash
|
343
|
+
def has_no_field?(locator = nil, **options, &optional_filter_block)
|
354
344
|
has_no_selector?(:field, locator, options, &optional_filter_block)
|
355
345
|
end
|
356
346
|
|
@@ -363,8 +353,7 @@ module Capybara
|
|
363
353
|
# @param [String] locator The label, name or id of a checked field
|
364
354
|
# @return [Boolean] Whether it exists
|
365
355
|
#
|
366
|
-
def has_checked_field?(locator=nil, options
|
367
|
-
locator, options = nil, locator if locator.is_a? Hash
|
356
|
+
def has_checked_field?(locator = nil, **options, &optional_filter_block)
|
368
357
|
has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
369
358
|
end
|
370
359
|
|
@@ -377,8 +366,7 @@ module Capybara
|
|
377
366
|
# @param [String] locator The label, name or id of a checked field
|
378
367
|
# @return [Boolean] Whether it doesn't exist
|
379
368
|
#
|
380
|
-
def has_no_checked_field?(locator=nil, options
|
381
|
-
locator, options = nil, locator if locator.is_a? Hash
|
369
|
+
def has_no_checked_field?(locator = nil, **options, &optional_filter_block)
|
382
370
|
has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
383
371
|
end
|
384
372
|
|
@@ -391,8 +379,7 @@ module Capybara
|
|
391
379
|
# @param [String] locator The label, name or id of an unchecked field
|
392
380
|
# @return [Boolean] Whether it exists
|
393
381
|
#
|
394
|
-
def has_unchecked_field?(locator=nil, options
|
395
|
-
locator, options = nil, locator if locator.is_a? Hash
|
382
|
+
def has_unchecked_field?(locator = nil, **options, &optional_filter_block)
|
396
383
|
has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
397
384
|
end
|
398
385
|
|
@@ -405,8 +392,7 @@ module Capybara
|
|
405
392
|
# @param [String] locator The label, name or id of an unchecked field
|
406
393
|
# @return [Boolean] Whether it doesn't exist
|
407
394
|
#
|
408
|
-
def has_no_unchecked_field?(locator=nil, options
|
409
|
-
locator, options = nil, locator if locator.is_a? Hash
|
395
|
+
def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)
|
410
396
|
has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
411
397
|
end
|
412
398
|
|
@@ -439,8 +425,7 @@ module Capybara
|
|
439
425
|
# @option options [String, Array] :with_selected Partial set of options which should minimally be selected
|
440
426
|
# @return [Boolean] Whether it exists
|
441
427
|
#
|
442
|
-
def has_select?(locator=nil, options
|
443
|
-
locator, options = nil, locator if locator.is_a? Hash
|
428
|
+
def has_select?(locator = nil, **options, &optional_filter_block)
|
444
429
|
has_selector?(:select, locator, options, &optional_filter_block)
|
445
430
|
end
|
446
431
|
|
@@ -452,8 +437,7 @@ module Capybara
|
|
452
437
|
# @param (see Capybara::Node::Matchers#has_select?)
|
453
438
|
# @return [Boolean] Whether it doesn't exist
|
454
439
|
#
|
455
|
-
def has_no_select?(locator=nil, options
|
456
|
-
locator, options = nil, locator if locator.is_a? Hash
|
440
|
+
def has_no_select?(locator = nil, **options, &optional_filter_block)
|
457
441
|
has_no_selector?(:select, locator, options, &optional_filter_block)
|
458
442
|
end
|
459
443
|
|
@@ -467,8 +451,7 @@ module Capybara
|
|
467
451
|
# @param [String] locator The id or caption of a table
|
468
452
|
# @return [Boolean] Whether it exist
|
469
453
|
#
|
470
|
-
def has_table?(locator=nil, options
|
471
|
-
locator, options = nil, locator if locator.is_a? Hash
|
454
|
+
def has_table?(locator = nil, **options, &optional_filter_block)
|
472
455
|
has_selector?(:table, locator, options, &optional_filter_block)
|
473
456
|
end
|
474
457
|
|
@@ -480,8 +463,7 @@ module Capybara
|
|
480
463
|
# @param (see Capybara::Node::Matchers#has_table?)
|
481
464
|
# @return [Boolean] Whether it doesn't exist
|
482
465
|
#
|
483
|
-
def has_no_table?(locator=nil, options
|
484
|
-
locator, options = nil, locator if locator.is_a? Hash
|
466
|
+
def has_no_table?(locator = nil, **options, &optional_filter_block)
|
485
467
|
has_no_selector?(:table, locator, options, &optional_filter_block)
|
486
468
|
end
|
487
469
|
|
@@ -534,7 +516,7 @@ module Capybara
|
|
534
516
|
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
535
517
|
# @return [Boolean]
|
536
518
|
#
|
537
|
-
def matches_xpath?(xpath, options
|
519
|
+
def matches_xpath?(xpath, **options, &optional_filter_block)
|
538
520
|
matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
539
521
|
end
|
540
522
|
|
@@ -545,7 +527,7 @@ module Capybara
|
|
545
527
|
# @param [String] css The CSS selector to match against the current code
|
546
528
|
# @return [Boolean]
|
547
529
|
#
|
548
|
-
def matches_css?(css, options
|
530
|
+
def matches_css?(css, **options, &optional_filter_block)
|
549
531
|
matches_selector?(:css, css, options, &optional_filter_block)
|
550
532
|
end
|
551
533
|
|
@@ -570,7 +552,7 @@ module Capybara
|
|
570
552
|
# @param [String, XPath::Expression] xpath The XPath expression to match against the current code
|
571
553
|
# @return [Boolean]
|
572
554
|
#
|
573
|
-
def not_matches_xpath?(xpath, options
|
555
|
+
def not_matches_xpath?(xpath, **options, &optional_filter_block)
|
574
556
|
not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
|
575
557
|
end
|
576
558
|
|
@@ -581,11 +563,10 @@ module Capybara
|
|
581
563
|
# @param [String] css The CSS selector to match against the current code
|
582
564
|
# @return [Boolean]
|
583
565
|
#
|
584
|
-
def not_matches_css?(css, options
|
566
|
+
def not_matches_css?(css, **options, &optional_filter_block)
|
585
567
|
not_matches_selector?(:css, css, options, &optional_filter_block)
|
586
568
|
end
|
587
569
|
|
588
|
-
|
589
570
|
##
|
590
571
|
# Asserts that the page or current node has the given text content,
|
591
572
|
# ignoring any HTML tags.
|
@@ -656,7 +637,7 @@ module Capybara
|
|
656
637
|
def has_text?(*args)
|
657
638
|
assert_text(*args)
|
658
639
|
rescue Capybara::ExpectationNotMet
|
659
|
-
|
640
|
+
false
|
660
641
|
end
|
661
642
|
alias_method :has_content?, :has_text?
|
662
643
|
|
@@ -670,53 +651,49 @@ module Capybara
|
|
670
651
|
def has_no_text?(*args)
|
671
652
|
assert_no_text(*args)
|
672
653
|
rescue Capybara::ExpectationNotMet
|
673
|
-
|
654
|
+
false
|
674
655
|
end
|
675
656
|
alias_method :has_no_content?, :has_no_text?
|
676
657
|
|
677
658
|
def ==(other)
|
678
|
-
|
659
|
+
eql?(other) || (other.respond_to?(:base) && base == other.base)
|
679
660
|
end
|
680
661
|
|
681
662
|
private
|
682
663
|
|
683
|
-
def _verify_selector_result(query_args, optional_filter_block
|
684
|
-
_set_query_session_options(query_args)
|
664
|
+
def _verify_selector_result(query_args, optional_filter_block)
|
665
|
+
query_args = _set_query_session_options(*query_args)
|
685
666
|
query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block)
|
686
667
|
synchronize(query.wait) do
|
687
668
|
result = query.resolve_for(self)
|
688
|
-
|
669
|
+
yield result, query
|
689
670
|
end
|
690
|
-
|
671
|
+
true
|
691
672
|
end
|
692
673
|
|
693
|
-
def _verify_match_result(query_args, optional_filter_block
|
694
|
-
_set_query_session_options(query_args)
|
674
|
+
def _verify_match_result(query_args, optional_filter_block)
|
675
|
+
query_args = _set_query_session_options(*query_args)
|
695
676
|
query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
|
696
677
|
synchronize(query.wait) do
|
697
|
-
result = query.resolve_for(
|
698
|
-
|
678
|
+
result = query.resolve_for(query_scope)
|
679
|
+
yield result
|
699
680
|
end
|
700
|
-
|
681
|
+
true
|
701
682
|
end
|
702
683
|
|
703
684
|
def _verify_text(query_args)
|
704
|
-
_set_query_session_options(query_args)
|
685
|
+
query_args = _set_query_session_options(*query_args)
|
705
686
|
query = Capybara::Queries::TextQuery.new(*query_args)
|
706
687
|
synchronize(query.wait) do
|
707
688
|
count = query.resolve_for(self)
|
708
689
|
yield(count, query)
|
709
690
|
end
|
710
|
-
|
691
|
+
true
|
711
692
|
end
|
712
693
|
|
713
|
-
def _set_query_session_options(query_args)
|
714
|
-
|
715
|
-
|
716
|
-
else
|
717
|
-
query_args.push(session_options: session_options)
|
718
|
-
end
|
719
|
-
query_args
|
694
|
+
def _set_query_session_options(*query_args, **query_options)
|
695
|
+
query_options[:session_options] = session_options
|
696
|
+
query_args.push(query_options)
|
720
697
|
end
|
721
698
|
end
|
722
699
|
end
|