capybara 3.29.0 → 3.37.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +229 -15
  3. data/README.md +13 -4
  4. data/lib/capybara/config.rb +24 -10
  5. data/lib/capybara/cucumber.rb +1 -1
  6. data/lib/capybara/driver/base.rb +8 -0
  7. data/lib/capybara/driver/node.rb +5 -1
  8. data/lib/capybara/dsl.rb +5 -3
  9. data/lib/capybara/helpers.rb +19 -2
  10. data/lib/capybara/minitest/spec.rb +156 -97
  11. data/lib/capybara/minitest.rb +232 -144
  12. data/lib/capybara/node/actions.rb +41 -37
  13. data/lib/capybara/node/base.rb +6 -6
  14. data/lib/capybara/node/document.rb +2 -2
  15. data/lib/capybara/node/document_matchers.rb +3 -3
  16. data/lib/capybara/node/element.rb +35 -21
  17. data/lib/capybara/node/finders.rb +33 -19
  18. data/lib/capybara/node/matchers.rb +72 -57
  19. data/lib/capybara/node/simple.rb +13 -3
  20. data/lib/capybara/queries/active_element_query.rb +18 -0
  21. data/lib/capybara/queries/ancestor_query.rb +4 -3
  22. data/lib/capybara/queries/base_query.rb +2 -1
  23. data/lib/capybara/queries/current_path_query.rb +14 -4
  24. data/lib/capybara/queries/selector_query.rb +91 -30
  25. data/lib/capybara/queries/sibling_query.rb +4 -3
  26. data/lib/capybara/queries/style_query.rb +1 -1
  27. data/lib/capybara/queries/text_query.rb +7 -1
  28. data/lib/capybara/rack_test/browser.rb +68 -10
  29. data/lib/capybara/rack_test/driver.rb +6 -5
  30. data/lib/capybara/rack_test/form.rb +2 -2
  31. data/lib/capybara/rack_test/node.rb +44 -16
  32. data/lib/capybara/registration_container.rb +41 -0
  33. data/lib/capybara/registrations/drivers.rb +18 -12
  34. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  35. data/lib/capybara/registrations/servers.rb +3 -2
  36. data/lib/capybara/result.rb +35 -15
  37. data/lib/capybara/rspec/matcher_proxies.rb +8 -8
  38. data/lib/capybara/rspec/matchers/base.rb +12 -6
  39. data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
  40. data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
  41. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  42. data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
  43. data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
  44. data/lib/capybara/rspec/matchers/have_text.rb +3 -3
  45. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  46. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  47. data/lib/capybara/rspec/matchers/match_style.rb +7 -2
  48. data/lib/capybara/rspec/matchers/spatial_sugar.rb +2 -1
  49. data/lib/capybara/rspec/matchers.rb +33 -32
  50. data/lib/capybara/rspec.rb +2 -0
  51. data/lib/capybara/selector/builders/css_builder.rb +2 -2
  52. data/lib/capybara/selector/builders/xpath_builder.rb +4 -2
  53. data/lib/capybara/selector/css.rb +2 -2
  54. data/lib/capybara/selector/definition/button.rb +35 -13
  55. data/lib/capybara/selector/definition/checkbox.rb +3 -3
  56. data/lib/capybara/selector/definition/css.rb +3 -1
  57. data/lib/capybara/selector/definition/datalist_input.rb +2 -2
  58. data/lib/capybara/selector/definition/datalist_option.rb +1 -1
  59. data/lib/capybara/selector/definition/element.rb +3 -2
  60. data/lib/capybara/selector/definition/field.rb +1 -1
  61. data/lib/capybara/selector/definition/file_field.rb +2 -2
  62. data/lib/capybara/selector/definition/fillable_field.rb +3 -3
  63. data/lib/capybara/selector/definition/label.rb +5 -3
  64. data/lib/capybara/selector/definition/link.rb +8 -0
  65. data/lib/capybara/selector/definition/radio_button.rb +3 -3
  66. data/lib/capybara/selector/definition/select.rb +33 -14
  67. data/lib/capybara/selector/definition/table.rb +6 -3
  68. data/lib/capybara/selector/definition/table_row.rb +2 -2
  69. data/lib/capybara/selector/definition.rb +15 -11
  70. data/lib/capybara/selector/filter_set.rb +17 -17
  71. data/lib/capybara/selector/filters/base.rb +6 -1
  72. data/lib/capybara/selector/filters/locator_filter.rb +1 -1
  73. data/lib/capybara/selector/selector.rb +17 -3
  74. data/lib/capybara/selector.rb +37 -19
  75. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  76. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  77. data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
  78. data/lib/capybara/selenium/driver.rb +84 -17
  79. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +11 -13
  80. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +10 -12
  81. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +4 -4
  82. data/lib/capybara/selenium/extensions/find.rb +4 -4
  83. data/lib/capybara/selenium/extensions/html5_drag.rb +30 -13
  84. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  85. data/lib/capybara/selenium/logger_suppressor.rb +8 -2
  86. data/lib/capybara/selenium/node.rb +122 -26
  87. data/lib/capybara/selenium/nodes/chrome_node.rb +34 -19
  88. data/lib/capybara/selenium/nodes/edge_node.rb +5 -3
  89. data/lib/capybara/selenium/nodes/firefox_node.rb +11 -6
  90. data/lib/capybara/selenium/nodes/safari_node.rb +3 -3
  91. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  92. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  93. data/lib/capybara/selenium/patches/logs.rb +7 -9
  94. data/lib/capybara/server/animation_disabler.rb +38 -15
  95. data/lib/capybara/server/checker.rb +1 -1
  96. data/lib/capybara/server/middleware.rb +22 -10
  97. data/lib/capybara/server.rb +15 -3
  98. data/lib/capybara/session/config.rb +10 -4
  99. data/lib/capybara/session/matchers.rb +11 -11
  100. data/lib/capybara/session.rb +62 -39
  101. data/lib/capybara/spec/public/test.js +75 -7
  102. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  103. data/lib/capybara/spec/session/active_element_spec.rb +31 -0
  104. data/lib/capybara/spec/session/all_spec.rb +63 -12
  105. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  106. data/lib/capybara/spec/session/assert_text_spec.rb +26 -22
  107. data/lib/capybara/spec/session/check_spec.rb +15 -0
  108. data/lib/capybara/spec/session/choose_spec.rb +6 -0
  109. data/lib/capybara/spec/session/click_button_spec.rb +16 -0
  110. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  111. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  112. data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
  113. data/lib/capybara/spec/session/find_spec.rb +37 -8
  114. data/lib/capybara/spec/session/has_any_selectors_spec.rb +4 -0
  115. data/lib/capybara/spec/session/has_button_spec.rb +75 -0
  116. data/lib/capybara/spec/session/has_css_spec.rb +14 -10
  117. data/lib/capybara/spec/session/has_current_path_spec.rb +17 -4
  118. data/lib/capybara/spec/session/has_field_spec.rb +41 -1
  119. data/lib/capybara/spec/session/has_link_spec.rb +30 -0
  120. data/lib/capybara/spec/session/has_select_spec.rb +36 -8
  121. data/lib/capybara/spec/session/has_selector_spec.rb +19 -4
  122. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  123. data/lib/capybara/spec/session/has_text_spec.rb +21 -1
  124. data/lib/capybara/spec/session/html_spec.rb +1 -1
  125. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  126. data/lib/capybara/spec/session/node_spec.rb +226 -33
  127. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  128. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  129. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  130. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  131. data/lib/capybara/spec/session/scroll_spec.rb +4 -4
  132. data/lib/capybara/spec/session/selectors_spec.rb +15 -2
  133. data/lib/capybara/spec/session/visit_spec.rb +20 -0
  134. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  135. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  136. data/lib/capybara/spec/session/window/window_spec.rb +9 -9
  137. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  138. data/lib/capybara/spec/spec_helper.rb +17 -17
  139. data/lib/capybara/spec/test_app.rb +89 -29
  140. data/lib/capybara/spec/views/animated.erb +1 -1
  141. data/lib/capybara/spec/views/form.erb +52 -6
  142. data/lib/capybara/spec/views/frame_child.erb +1 -1
  143. data/lib/capybara/spec/views/frame_one.erb +1 -1
  144. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  145. data/lib/capybara/spec/views/frame_two.erb +1 -1
  146. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  147. data/lib/capybara/spec/views/layout.erb +10 -0
  148. data/lib/capybara/spec/views/obscured.erb +1 -1
  149. data/lib/capybara/spec/views/offset.erb +2 -1
  150. data/lib/capybara/spec/views/path.erb +2 -2
  151. data/lib/capybara/spec/views/popup_one.erb +1 -1
  152. data/lib/capybara/spec/views/popup_two.erb +1 -1
  153. data/lib/capybara/spec/views/react.erb +2 -2
  154. data/lib/capybara/spec/views/scroll.erb +2 -1
  155. data/lib/capybara/spec/views/spatial.erb +1 -1
  156. data/lib/capybara/spec/views/with_animation.erb +10 -3
  157. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  158. data/lib/capybara/spec/views/with_dragula.erb +5 -3
  159. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  160. data/lib/capybara/spec/views/with_hover.erb +2 -2
  161. data/lib/capybara/spec/views/with_html.erb +3 -3
  162. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  163. data/lib/capybara/spec/views/with_js.erb +5 -3
  164. data/lib/capybara/spec/views/with_jstree.erb +1 -1
  165. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  166. data/lib/capybara/spec/views/with_shadow.erb +31 -0
  167. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  168. data/lib/capybara/spec/views/with_sortable_js.erb +3 -3
  169. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  170. data/lib/capybara/spec/views/with_windows.erb +1 -1
  171. data/lib/capybara/spec/views/within_frames.erb +1 -1
  172. data/lib/capybara/version.rb +1 -1
  173. data/lib/capybara/window.rb +4 -8
  174. data/lib/capybara.rb +36 -29
  175. data/spec/basic_node_spec.rb +25 -11
  176. data/spec/capybara_spec.rb +1 -1
  177. data/spec/dsl_spec.rb +18 -5
  178. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
  179. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -3
  180. data/spec/minitest_spec.rb +3 -2
  181. data/spec/minitest_spec_spec.rb +46 -46
  182. data/spec/rack_test_spec.rb +43 -11
  183. data/spec/regexp_dissassembler_spec.rb +40 -36
  184. data/spec/result_spec.rb +53 -45
  185. data/spec/rspec/features_spec.rb +7 -4
  186. data/spec/rspec/scenarios_spec.rb +5 -1
  187. data/spec/rspec/shared_spec_matchers.rb +68 -56
  188. data/spec/rspec_spec.rb +8 -4
  189. data/spec/sauce_spec_chrome.rb +3 -3
  190. data/spec/selector_spec.rb +19 -4
  191. data/spec/selenium_spec_chrome.rb +49 -26
  192. data/spec/selenium_spec_chrome_remote.rb +13 -6
  193. data/spec/selenium_spec_firefox.rb +29 -17
  194. data/spec/selenium_spec_firefox_remote.rb +2 -2
  195. data/spec/selenium_spec_ie.rb +3 -6
  196. data/spec/selenium_spec_safari.rb +31 -19
  197. data/spec/server_spec.rb +88 -35
  198. data/spec/session_spec.rb +1 -1
  199. data/spec/shared_selenium_node.rb +21 -7
  200. data/spec/shared_selenium_session.rb +123 -21
  201. data/spec/spec_helper.rb +2 -2
  202. metadata +80 -21
  203. data/lib/capybara/spec/session/source_spec.rb +0 -0
  204. data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -60,15 +60,16 @@ module Capybara
60
60
  # @param styles [Hash]
61
61
  # @return [Boolean] If the styles match
62
62
  #
63
- def matches_style?(styles, **options)
64
- make_predicate(options) { assert_matches_style(styles, options) }
63
+ def matches_style?(styles = nil, **options)
64
+ styles, options = options, {} if styles.nil?
65
+ make_predicate(options) { assert_matches_style(styles, **options) }
65
66
  end
66
67
 
67
68
  ##
68
69
  # @deprecated Use {#matches_style?} instead.
69
70
  #
70
- def has_style?(styles, **options)
71
- warn 'DEPRECATED: has_style? is deprecated, please use matches_style?'
71
+ def has_style?(styles = nil, **options)
72
+ Capybara::Helpers.warn "DEPRECATED: has_style? is deprecated, please use matches_style? : #{Capybara::Helpers.filter_backtrace(caller)}"
72
73
  matches_style?(styles, **options)
73
74
  end
74
75
 
@@ -107,7 +108,9 @@ module Capybara
107
108
  #
108
109
  def assert_selector(*args, &optional_filter_block)
109
110
  _verify_selector_result(args, optional_filter_block) do |result, query|
110
- raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count? && (result.any? || query.expects_none?)
111
+ unless result.matches_count? && (result.any? || query.expects_none?)
112
+ raise Capybara::ExpectationNotMet, result.failure_message
113
+ end
111
114
  end
112
115
  end
113
116
 
@@ -120,9 +123,10 @@ module Capybara
120
123
  # @param styles [Hash]
121
124
  # @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles
122
125
  #
123
- def assert_matches_style(styles, **options)
124
- query_args = _set_query_session_options(styles, options)
125
- query = Capybara::Queries::StyleQuery.new(*query_args)
126
+ def assert_matches_style(styles = nil, **options)
127
+ styles, options = options, {} if styles.nil?
128
+ query_args, query_opts = _set_query_session_options(styles, options)
129
+ query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)
126
130
  synchronize(query.wait) do
127
131
  raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self)
128
132
  end
@@ -132,7 +136,7 @@ module Capybara
132
136
  ##
133
137
  # @deprecated Use {#assert_matches_style} instead.
134
138
  #
135
- def assert_style(styles, **options)
139
+ def assert_style(styles = nil, **options)
136
140
  warn 'assert_style is deprecated, please use assert_matches_style instead'
137
141
  assert_matches_style(styles, **options)
138
142
  end
@@ -153,7 +157,7 @@ module Capybara
153
157
  # @overload assert_all_of_selectors([kind = Capybara.default_selector], *locators, **options)
154
158
  #
155
159
  def assert_all_of_selectors(*args, **options, &optional_filter_block)
156
- _verify_multiple(*args, options) do |selector, locator, opts|
160
+ _verify_multiple(*args, **options) do |selector, locator, opts|
157
161
  assert_selector(selector, locator, opts, &optional_filter_block)
158
162
  end
159
163
  end
@@ -174,7 +178,7 @@ module Capybara
174
178
  # @overload assert_none_of_selectors([kind = Capybara.default_selector], *locators, **options)
175
179
  #
176
180
  def assert_none_of_selectors(*args, **options, &optional_filter_block)
177
- _verify_multiple(*args, options) do |selector, locator, opts|
181
+ _verify_multiple(*args, **options) do |selector, locator, opts|
178
182
  assert_no_selector(selector, locator, opts, &optional_filter_block)
179
183
  end
180
184
  end
@@ -199,12 +203,10 @@ module Capybara
199
203
  selector = extract_selector(args)
200
204
  synchronize(wait) do
201
205
  res = args.map do |locator|
202
- begin
203
- assert_selector(selector, locator, options, &optional_filter_block)
204
- break nil
205
- rescue Capybara::ExpectationNotMet => e
206
- e.message
207
- end
206
+ assert_selector(selector, locator, options, &optional_filter_block)
207
+ break nil
208
+ rescue Capybara::ExpectationNotMet => e
209
+ e.message
208
210
  end
209
211
  raise Capybara::ExpectationNotMet, res.join(' or ') if res
210
212
 
@@ -266,7 +268,7 @@ module Capybara
266
268
  # @return [Boolean] If the expression exists
267
269
  #
268
270
  def has_xpath?(path, **options, &optional_filter_block)
269
- has_selector?(:xpath, path, options, &optional_filter_block)
271
+ has_selector?(:xpath, path, **options, &optional_filter_block)
270
272
  end
271
273
 
272
274
  ##
@@ -278,7 +280,7 @@ module Capybara
278
280
  # @return [Boolean]
279
281
  #
280
282
  def has_no_xpath?(path, **options, &optional_filter_block)
281
- has_no_selector?(:xpath, path, options, &optional_filter_block)
283
+ has_no_selector?(:xpath, path, **options, &optional_filter_block)
282
284
  end
283
285
 
284
286
  ##
@@ -305,7 +307,7 @@ module Capybara
305
307
  # @return [Boolean] If the selector exists
306
308
  #
307
309
  def has_css?(path, **options, &optional_filter_block)
308
- has_selector?(:css, path, options, &optional_filter_block)
310
+ has_selector?(:css, path, **options, &optional_filter_block)
309
311
  end
310
312
 
311
313
  ##
@@ -317,7 +319,7 @@ module Capybara
317
319
  # @return [Boolean]
318
320
  #
319
321
  def has_no_css?(path, **options, &optional_filter_block)
320
- has_no_selector?(:css, path, options, &optional_filter_block)
322
+ has_no_selector?(:css, path, **options, &optional_filter_block)
321
323
  end
322
324
 
323
325
  ##
@@ -330,7 +332,7 @@ module Capybara
330
332
  # @return [Boolean] Whether it exists
331
333
  #
332
334
  def has_link?(locator = nil, **options, &optional_filter_block)
333
- has_selector?(:link, locator, options, &optional_filter_block)
335
+ has_selector?(:link, locator, **options, &optional_filter_block)
334
336
  end
335
337
 
336
338
  ##
@@ -342,7 +344,7 @@ module Capybara
342
344
  # @return [Boolean] Whether it doesn't exist
343
345
  #
344
346
  def has_no_link?(locator = nil, **options, &optional_filter_block)
345
- has_no_selector?(:link, locator, options, &optional_filter_block)
347
+ has_no_selector?(:link, locator, **options, &optional_filter_block)
346
348
  end
347
349
 
348
350
  ##
@@ -354,7 +356,7 @@ module Capybara
354
356
  # @return [Boolean] Whether it exists
355
357
  #
356
358
  def has_button?(locator = nil, **options, &optional_filter_block)
357
- has_selector?(:button, locator, options, &optional_filter_block)
359
+ has_selector?(:button, locator, **options, &optional_filter_block)
358
360
  end
359
361
 
360
362
  ##
@@ -366,7 +368,7 @@ module Capybara
366
368
  # @return [Boolean] Whether it doesn't exist
367
369
  #
368
370
  def has_no_button?(locator = nil, **options, &optional_filter_block)
369
- has_no_selector?(:button, locator, options, &optional_filter_block)
371
+ has_no_selector?(:button, locator, **options, &optional_filter_block)
370
372
  end
371
373
 
372
374
  ##
@@ -384,7 +386,7 @@ module Capybara
384
386
  #
385
387
  # page.has_field?('Email', type: 'email')
386
388
  #
387
- # Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
389
+ # NOTE: 'textarea' and 'select' are valid type values, matching the associated tag names.
388
390
  #
389
391
  # @param [String] locator The label, name or id of a field to check for
390
392
  # @option options [String, Regexp] :with The text content of the field or a Regexp to match
@@ -392,7 +394,7 @@ module Capybara
392
394
  # @return [Boolean] Whether it exists
393
395
  #
394
396
  def has_field?(locator = nil, **options, &optional_filter_block)
395
- has_selector?(:field, locator, options, &optional_filter_block)
397
+ has_selector?(:field, locator, **options, &optional_filter_block)
396
398
  end
397
399
 
398
400
  ##
@@ -406,7 +408,7 @@ module Capybara
406
408
  # @return [Boolean] Whether it doesn't exist
407
409
  #
408
410
  def has_no_field?(locator = nil, **options, &optional_filter_block)
409
- has_no_selector?(:field, locator, options, &optional_filter_block)
411
+ has_no_selector?(:field, locator, **options, &optional_filter_block)
410
412
  end
411
413
 
412
414
  ##
@@ -419,7 +421,7 @@ module Capybara
419
421
  # @return [Boolean] Whether it exists
420
422
  #
421
423
  def has_checked_field?(locator = nil, **options, &optional_filter_block)
422
- has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
424
+ has_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block)
423
425
  end
424
426
 
425
427
  ##
@@ -432,7 +434,7 @@ module Capybara
432
434
  # @return [Boolean] Whether it doesn't exist
433
435
  #
434
436
  def has_no_checked_field?(locator = nil, **options, &optional_filter_block)
435
- has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
437
+ has_no_selector?(:field, locator, **options.merge(checked: true), &optional_filter_block)
436
438
  end
437
439
 
438
440
  ##
@@ -445,7 +447,7 @@ module Capybara
445
447
  # @return [Boolean] Whether it exists
446
448
  #
447
449
  def has_unchecked_field?(locator = nil, **options, &optional_filter_block)
448
- has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
450
+ has_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block)
449
451
  end
450
452
 
451
453
  ##
@@ -458,7 +460,7 @@ module Capybara
458
460
  # @return [Boolean] Whether it doesn't exist
459
461
  #
460
462
  def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)
461
- has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
463
+ has_no_selector?(:field, locator, **options.merge(unchecked: true), &optional_filter_block)
462
464
  end
463
465
 
464
466
  ##
@@ -491,7 +493,7 @@ module Capybara
491
493
  # @return [Boolean] Whether it exists
492
494
  #
493
495
  def has_select?(locator = nil, **options, &optional_filter_block)
494
- has_selector?(:select, locator, options, &optional_filter_block)
496
+ has_selector?(:select, locator, **options, &optional_filter_block)
495
497
  end
496
498
 
497
499
  ##
@@ -503,7 +505,7 @@ module Capybara
503
505
  # @return [Boolean] Whether it doesn't exist
504
506
  #
505
507
  def has_no_select?(locator = nil, **options, &optional_filter_block)
506
- has_no_selector?(:select, locator, options, &optional_filter_block)
508
+ has_no_selector?(:select, locator, **options, &optional_filter_block)
507
509
  end
508
510
 
509
511
  ##
@@ -525,7 +527,7 @@ module Capybara
525
527
  # @return [Boolean] Whether it exists
526
528
  #
527
529
  def has_table?(locator = nil, **options, &optional_filter_block)
528
- has_selector?(:table, locator, options, &optional_filter_block)
530
+ has_selector?(:table, locator, **options, &optional_filter_block)
529
531
  end
530
532
 
531
533
  ##
@@ -537,7 +539,7 @@ module Capybara
537
539
  # @return [Boolean] Whether it doesn't exist
538
540
  #
539
541
  def has_no_table?(locator = nil, **options, &optional_filter_block)
540
- has_no_selector?(:table, locator, options, &optional_filter_block)
542
+ has_no_selector?(:table, locator, **options, &optional_filter_block)
541
543
  end
542
544
 
543
545
  ##
@@ -595,7 +597,7 @@ module Capybara
595
597
  # @return [Boolean]
596
598
  #
597
599
  def matches_xpath?(xpath, **options, &optional_filter_block)
598
- matches_selector?(:xpath, xpath, options, &optional_filter_block)
600
+ matches_selector?(:xpath, xpath, **options, &optional_filter_block)
599
601
  end
600
602
 
601
603
  ##
@@ -606,7 +608,7 @@ module Capybara
606
608
  # @return [Boolean]
607
609
  #
608
610
  def matches_css?(css, **options, &optional_filter_block)
609
- matches_selector?(:css, css, options, &optional_filter_block)
611
+ matches_selector?(:css, css, **options, &optional_filter_block)
610
612
  end
611
613
 
612
614
  ##
@@ -629,7 +631,7 @@ module Capybara
629
631
  # @return [Boolean]
630
632
  #
631
633
  def not_matches_xpath?(xpath, **options, &optional_filter_block)
632
- not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
634
+ not_matches_selector?(:xpath, xpath, **options, &optional_filter_block)
633
635
  end
634
636
 
635
637
  ##
@@ -640,7 +642,7 @@ module Capybara
640
642
  # @return [Boolean]
641
643
  #
642
644
  def not_matches_css?(css, **options, &optional_filter_block)
643
- not_matches_selector?(:css, css, options, &optional_filter_block)
645
+ not_matches_selector?(:css, css, **options, &optional_filter_block)
644
646
  end
645
647
 
646
648
  ##
@@ -670,8 +672,8 @@ module Capybara
670
672
  # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
671
673
  # @return [true]
672
674
  #
673
- def assert_text(*args)
674
- _verify_text(args) do |count, query|
675
+ def assert_text(type_or_text, *args, **opts)
676
+ _verify_text(type_or_text, *args, **opts) do |count, query|
675
677
  unless query.matches_count?(count) && (count.positive? || query.expects_none?)
676
678
  raise Capybara::ExpectationNotMet, query.failure_message
677
679
  end
@@ -686,8 +688,8 @@ module Capybara
686
688
  # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
687
689
  # @return [true]
688
690
  #
689
- def assert_no_text(*args)
690
- _verify_text(args) do |count, query|
691
+ def assert_no_text(type_or_text, *args, **opts)
692
+ _verify_text(type_or_text, *args, **opts) do |count, query|
691
693
  if query.matches_count?(count) && (count.positive? || query.expects_none?)
692
694
  raise Capybara::ExpectationNotMet, query.negative_failure_message
693
695
  end
@@ -709,7 +711,7 @@ module Capybara
709
711
  # @return [Boolean] Whether it exists
710
712
  #
711
713
  def has_text?(*args, **options)
712
- make_predicate(options) { assert_text(*args, options) }
714
+ make_predicate(options) { assert_text(*args, **options) }
713
715
  end
714
716
  alias_method :has_content?, :has_text?
715
717
 
@@ -721,7 +723,7 @@ module Capybara
721
723
  # @return [Boolean] Whether it doesn't exist
722
724
  #
723
725
  def has_no_text?(*args, **options)
724
- make_predicate(options) { assert_no_text(*args, options) }
726
+ make_predicate(options) { assert_no_text(*args, **options) }
725
727
  end
726
728
  alias_method :has_no_content?, :has_no_text?
727
729
 
@@ -738,7 +740,9 @@ module Capybara
738
740
  #
739
741
  def assert_ancestor(*args, &optional_filter_block)
740
742
  _verify_selector_result(args, optional_filter_block, Capybara::Queries::AncestorQuery) do |result, query|
741
- raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count? && (result.any? || query.expects_none?)
743
+ unless result.matches_count? && (result.any? || query.expects_none?)
744
+ raise Capybara::ExpectationNotMet, result.failure_message
745
+ end
742
746
  end
743
747
  end
744
748
 
@@ -779,7 +783,9 @@ module Capybara
779
783
  #
780
784
  def assert_sibling(*args, &optional_filter_block)
781
785
  _verify_selector_result(args, optional_filter_block, Capybara::Queries::SiblingQuery) do |result, query|
782
- raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count? && (result.any? || query.expects_none?)
786
+ unless result.matches_count? && (result.any? || query.expects_none?)
787
+ raise Capybara::ExpectationNotMet, result.failure_message
788
+ end
783
789
  end
784
790
  end
785
791
 
@@ -826,8 +832,14 @@ module Capybara
826
832
  end
827
833
 
828
834
  def _verify_selector_result(query_args, optional_filter_block, query_type = Capybara::Queries::SelectorQuery)
829
- query_args = _set_query_session_options(*query_args)
830
- query = query_type.new(*query_args, &optional_filter_block)
835
+ # query_args, query_opts = if query_args[0].is_a? Symbol
836
+ # a,o = _set_query_session_options(*query_args.slice(2..))
837
+ # [query_args.slice(0..1).concat(a), o]
838
+ # else
839
+ # _set_query_session_options(*query_args)
840
+ # end
841
+ query_args, query_opts = _set_query_session_options(*query_args)
842
+ query = query_type.new(*query_args, **query_opts, &optional_filter_block)
831
843
  synchronize(query.wait) do
832
844
  yield query.resolve_for(self), query
833
845
  end
@@ -835,26 +847,29 @@ module Capybara
835
847
  end
836
848
 
837
849
  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)
850
+ query_args, query_opts = _set_query_session_options(*query_args)
851
+ query = Capybara::Queries::MatchQuery.new(*query_args, **query_opts, &optional_filter_block)
840
852
  synchronize(query.wait) do
841
853
  yield query.resolve_for(parent || session&.document || query_scope)
842
854
  end
843
855
  true
844
856
  end
845
857
 
846
- def _verify_text(query_args)
847
- query_args = _set_query_session_options(*query_args)
848
- query = Capybara::Queries::TextQuery.new(*query_args)
858
+ def _verify_text(type = nil, expected_text, **query_options) # rubocop:disable Style/OptionalArguments
859
+ query_options[:session_options] = session_options
860
+ query = Capybara::Queries::TextQuery.new(type, expected_text, **query_options)
849
861
  synchronize(query.wait) do
850
862
  yield query.resolve_for(self), query
851
863
  end
852
864
  true
853
865
  end
854
866
 
855
- def _set_query_session_options(*query_args, **query_options)
867
+ def _set_query_session_options(*query_args)
868
+ query_args, query_options = query_args.dup, {}
869
+ # query_options = query_args.pop if query_options.empty? && query_args.last.is_a?(Hash)
870
+ query_options = query_args.pop if query_args.last.is_a?(Hash)
856
871
  query_options[:session_options] = session_options
857
- query_args.push(query_options)
872
+ [query_args, query_options]
858
873
  end
859
874
 
860
875
  def make_predicate(options)
@@ -100,7 +100,7 @@ module Capybara
100
100
  # @param [Boolean] check_ancestors Whether to inherit visibility from ancestors
101
101
  # @return [Boolean] Whether the element is visible
102
102
  #
103
- def visible?(check_ancestors = true)
103
+ def visible?(check_ancestors = true) # rubocop:disable Style/OptionalBooleanParameter
104
104
  return false if (tag_name == 'input') && (native[:type] == 'hidden')
105
105
  return false if tag_name == 'template'
106
106
 
@@ -108,7 +108,9 @@ module Capybara
108
108
  !find_xpath(VISIBILITY_XPATH)
109
109
  else
110
110
  # No need for an xpath if only checking the current element
111
- !(native.key?('hidden') || (/display:\s?none/.match? native[:style]) || %w[script head].include?(tag_name))
111
+ !(native.key?('hidden') ||
112
+ /display:\s?none/.match?(native[:style] || '') ||
113
+ %w[script head style].include?(tag_name))
112
114
  end
113
115
  end
114
116
 
@@ -146,11 +148,15 @@ module Capybara
146
148
  native.has_attribute?('multiple')
147
149
  end
148
150
 
151
+ def readonly?
152
+ native.has_attribute?('readonly')
153
+ end
154
+
149
155
  def synchronize(_seconds = nil)
150
156
  yield # simple nodes don't need to wait
151
157
  end
152
158
 
153
- def allow_reload!
159
+ def allow_reload!(*)
154
160
  # no op
155
161
  end
156
162
 
@@ -185,6 +191,10 @@ module Capybara
185
191
  {}
186
192
  end
187
193
 
194
+ def ==(other)
195
+ eql?(other) || (other.respond_to?(:native) && native == other.native)
196
+ end
197
+
188
198
  private
189
199
 
190
200
  def option_value(option)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ # @api private
5
+ module Queries
6
+ class ActiveElementQuery < BaseQuery
7
+ def initialize(**options)
8
+ @options = options
9
+ super(@options)
10
+ end
11
+
12
+ def resolve_for(session)
13
+ node = session.driver.active_element
14
+ [Capybara::Node::Element.new(session, node, nil, self)]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,15 +8,16 @@ module Capybara
8
8
  @child_node = node
9
9
 
10
10
  node.synchronize do
11
- match_results = super(node.session.current_scope, exact)
11
+ scope = node.respond_to?(:session) ? node.session.current_scope : node.find(:xpath, '/*')
12
+ match_results = super(scope, exact)
12
13
  ancestors = node.find_xpath(XPath.ancestor.to_s)
13
14
  .map(&method(:to_element))
14
15
  .select { |el| match_results.include?(el) }
15
- Capybara::Result.new(ancestors, self)
16
+ Capybara::Result.new(ordered_results(ancestors), self)
16
17
  end
17
18
  end
18
19
 
19
- def description(applied = false)
20
+ def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
20
21
  child_query = @child_node&.instance_variable_get(:@query)
21
22
  desc = super
22
23
  desc += " that is an ancestor of #{child_query.description}" if child_query
@@ -79,7 +79,8 @@ module Capybara
79
79
  if count
80
80
  message << " #{occurrences count}"
81
81
  elsif between
82
- message << " between #{between.first} and #{between.end ? between.last : 'infinite'} times"
82
+ message << " between #{between.begin ? between.first : 1} and" \
83
+ " #{between.end ? between.last : 'infinite'} times"
83
84
  elsif maximum
84
85
  message << " at most #{occurrences maximum}"
85
86
  elsif minimum
@@ -6,26 +6,30 @@ module Capybara
6
6
  # @api private
7
7
  module Queries
8
8
  class CurrentPathQuery < BaseQuery
9
- def initialize(expected_path, **options)
9
+ def initialize(expected_path, **options, &optional_filter_block)
10
10
  super(options)
11
11
  @expected_path = expected_path
12
12
  @options = {
13
13
  url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || '').hostname.nil?,
14
14
  ignore_query: false
15
15
  }.merge(options)
16
+ @filter_block = optional_filter_block
16
17
  assert_valid_keys
17
18
  end
18
19
 
19
20
  def resolves_for?(session)
20
21
  uri = ::Addressable::URI.parse(session.current_url)
21
- uri&.query = nil if options[:ignore_query]
22
- @actual_path = options[:url] ? uri&.to_s : uri&.request_uri
22
+ @actual_path = (options[:ignore_query] ? uri&.omit(:query) : uri).then do |u|
23
+ options[:url] ? u&.to_s : u&.request_uri
24
+ end
23
25
 
24
- if @expected_path.is_a? Regexp
26
+ res = if @expected_path.is_a? Regexp
25
27
  @actual_path.to_s.match?(@expected_path)
26
28
  else
27
29
  ::Addressable::URI.parse(@expected_path) == ::Addressable::URI.parse(@actual_path)
28
30
  end
31
+
32
+ res && matches_filter_block?(uri)
29
33
  end
30
34
 
31
35
  def failure_message
@@ -38,6 +42,12 @@ module Capybara
38
42
 
39
43
  private
40
44
 
45
+ def matches_filter_block?(url)
46
+ return true unless @filter_block
47
+
48
+ @filter_block.call(url)
49
+ end
50
+
41
51
  def failure_message_helper(negated = '')
42
52
  verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
43
53
  "expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"