capybara 3.29.0 → 3.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +203 -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 +1 -1
  8. data/lib/capybara/dsl.rb +10 -2
  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 +24 -21
  17. data/lib/capybara/node/finders.rb +25 -18
  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 +71 -23
  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 +13 -4
  29. data/lib/capybara/rack_test/driver.rb +2 -1
  30. data/lib/capybara/rack_test/form.rb +2 -2
  31. data/lib/capybara/rack_test/node.rb +43 -15
  32. data/lib/capybara/registration_container.rb +44 -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 +14 -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 +13 -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 +79 -16
  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 +110 -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 +17 -6
  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 +9 -3
  99. data/lib/capybara/session/matchers.rb +11 -11
  100. data/lib/capybara/session.rb +73 -37
  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 +62 -9
  105. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  106. data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
  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 +31 -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 +15 -2
  118. data/lib/capybara/spec/session/has_field_spec.rb +40 -0
  119. data/lib/capybara/spec/session/has_link_spec.rb +24 -0
  120. data/lib/capybara/spec/session/has_select_spec.rb +32 -4
  121. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  122. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  123. data/lib/capybara/spec/session/has_text_spec.rb +25 -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 +184 -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/window/switch_to_window_spec.rb +1 -1
  134. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  135. data/lib/capybara/spec/session/window/window_spec.rb +8 -8
  136. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  137. data/lib/capybara/spec/spec_helper.rb +17 -17
  138. data/lib/capybara/spec/test_app.rb +40 -29
  139. data/lib/capybara/spec/views/animated.erb +1 -1
  140. data/lib/capybara/spec/views/form.erb +52 -6
  141. data/lib/capybara/spec/views/frame_child.erb +1 -1
  142. data/lib/capybara/spec/views/frame_one.erb +1 -1
  143. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  144. data/lib/capybara/spec/views/frame_two.erb +1 -1
  145. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  146. data/lib/capybara/spec/views/layout.erb +10 -0
  147. data/lib/capybara/spec/views/obscured.erb +1 -1
  148. data/lib/capybara/spec/views/offset.erb +2 -1
  149. data/lib/capybara/spec/views/path.erb +2 -2
  150. data/lib/capybara/spec/views/popup_one.erb +1 -1
  151. data/lib/capybara/spec/views/popup_two.erb +1 -1
  152. data/lib/capybara/spec/views/react.erb +2 -2
  153. data/lib/capybara/spec/views/scroll.erb +2 -1
  154. data/lib/capybara/spec/views/spatial.erb +1 -1
  155. data/lib/capybara/spec/views/with_animation.erb +10 -3
  156. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  157. data/lib/capybara/spec/views/with_dragula.erb +5 -3
  158. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  159. data/lib/capybara/spec/views/with_hover.erb +2 -2
  160. data/lib/capybara/spec/views/with_html.erb +3 -3
  161. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  162. data/lib/capybara/spec/views/with_js.erb +5 -3
  163. data/lib/capybara/spec/views/with_jstree.erb +1 -1
  164. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  165. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  166. data/lib/capybara/spec/views/with_sortable_js.erb +3 -3
  167. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  168. data/lib/capybara/spec/views/with_windows.erb +1 -1
  169. data/lib/capybara/spec/views/within_frames.erb +1 -1
  170. data/lib/capybara/version.rb +1 -1
  171. data/lib/capybara/window.rb +3 -7
  172. data/lib/capybara.rb +35 -29
  173. data/spec/basic_node_spec.rb +25 -11
  174. data/spec/capybara_spec.rb +1 -1
  175. data/spec/dsl_spec.rb +16 -3
  176. data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
  177. data/spec/minitest_spec.rb +3 -2
  178. data/spec/minitest_spec_spec.rb +46 -46
  179. data/spec/rack_test_spec.rb +37 -11
  180. data/spec/regexp_dissassembler_spec.rb +40 -36
  181. data/spec/result_spec.rb +42 -32
  182. data/spec/rspec/features_spec.rb +5 -2
  183. data/spec/rspec/scenarios_spec.rb +4 -0
  184. data/spec/rspec/shared_spec_matchers.rb +68 -56
  185. data/spec/rspec_spec.rb +8 -4
  186. data/spec/selector_spec.rb +17 -2
  187. data/spec/selenium_spec_chrome.rb +48 -25
  188. data/spec/selenium_spec_chrome_remote.rb +13 -6
  189. data/spec/selenium_spec_firefox.rb +25 -17
  190. data/spec/selenium_spec_firefox_remote.rb +2 -2
  191. data/spec/selenium_spec_ie.rb +3 -6
  192. data/spec/selenium_spec_safari.rb +27 -19
  193. data/spec/server_spec.rb +84 -31
  194. data/spec/session_spec.rb +1 -1
  195. data/spec/shared_selenium_node.rb +21 -7
  196. data/spec/shared_selenium_session.rb +114 -19
  197. data/spec/spec_helper.rb +1 -1
  198. metadata +78 -21
  199. data/lib/capybara/spec/session/source_spec.rb +0 -0
  200. data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -103,19 +103,19 @@ module Capybara
103
103
 
104
104
  # @api private
105
105
  def find_css(css, **options)
106
- if base.method(:find_css).arity != 1
107
- base.find_css(css, **options)
108
- else
106
+ if base.method(:find_css).arity == 1
109
107
  base.find_css(css)
108
+ else
109
+ base.find_css(css, **options)
110
110
  end
111
111
  end
112
112
 
113
113
  # @api private
114
114
  def find_xpath(xpath, **options)
115
- if base.method(:find_xpath).arity != 1
116
- base.find_xpath(xpath, **options)
117
- else
115
+ if base.method(:find_xpath).arity == 1
118
116
  base.find_xpath(xpath)
117
+ else
118
+ base.find_xpath(xpath, **options)
119
119
  end
120
120
  end
121
121
 
@@ -40,8 +40,8 @@ module Capybara
40
40
  find(:xpath, '/html').evaluate_script(*args)
41
41
  end
42
42
 
43
- def scroll_to(*args)
44
- find(:xpath, '//body').scroll_to(*args)
43
+ def scroll_to(*args, quirks: false, **options)
44
+ find(:xpath, quirks ? '//body' : '/html').scroll_to(*args, **options)
45
45
  end
46
46
  end
47
47
  end
@@ -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
- raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}" if ENV['CAPYBARA_THOROUGH'] && readonly?
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)
@@ -427,11 +435,7 @@ module Capybara
427
435
  #
428
436
  # @return [Capybara::Node::Element] The element
429
437
  def drop(*args)
430
- options = args.map do |arg|
431
- return arg.to_path if arg.respond_to?(:to_path)
432
-
433
- arg
434
- end
438
+ options = args.map { |arg| arg.respond_to?(:to_path) ? arg.to_path : arg }
435
439
  synchronize { base.drop(*options) }
436
440
  self
437
441
  end
@@ -543,14 +547,13 @@ module Capybara
543
547
 
544
548
  # @api private
545
549
  def reload
546
- if @allow_reload
547
- begin
548
- reloaded = @query.resolve_for(query_scope.reload)&.first
550
+ return self unless @allow_reload
549
551
 
550
- @base = reloaded.base if reloaded
551
- rescue StandardError => e
552
- raise e unless catch_error?(e)
553
- end
552
+ begin
553
+ reloaded = @query.resolve_for(query_scope ? query_scope.reload : session)[@query_idx.to_i]
554
+ @base = reloaded.base if reloaded
555
+ rescue StandardError => e
556
+ raise e unless catch_error?(e)
554
557
  end
555
558
  self
556
559
  end
@@ -22,14 +22,15 @@ module Capybara
22
22
  # When String the elements contained text must match exactly, when Boolean controls whether the `text` option must match exactly.
23
23
  # Defaults to {Capybara.configure exact_text}.
24
24
  # @option options [Boolean] normalize_ws
25
- # Whether the `text`/`exact_text` options are compared against elment text with whitespace normalized or as returned by the driver.
25
+ # Whether the `text`/`exact_text` options are compared against element text with whitespace normalized or as returned by the driver.
26
26
  # Defaults to {Capybara.configure default_normalize_ws}.
27
- # @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
28
- # * true - only finds visible elements.
29
- # * false - finds invisible _and_ visible elements.
30
- # * :all - same as false; finds visible and invisible elements.
31
- # * :hidden - only finds invisible elements.
32
- # * :visible - same as true; only finds visible elements.
27
+ # @option options [Boolean, Symbol] visible
28
+ # Only find elements with the specified visibility. Defaults to behavior indicated by {Capybara.configure ignore_hidden_elements}.
29
+ # * true - only finds visible elements.
30
+ # * false - finds invisible _and_ visible elements.
31
+ # * :all - same as false; finds visible and invisible elements.
32
+ # * :hidden - only finds invisible elements.
33
+ # * :visible - same as true; only finds visible elements.
33
34
  # @option options [Boolean] obscured Only find elements with the specified obscured state:
34
35
  # * true - only find elements whose centerpoint is not in the viewport or is obscured by another non-descendant element.
35
36
  # * false - only find elements whose centerpoint is in the viewport and is not obscured by other non-descendant elements.
@@ -49,7 +50,7 @@ module Capybara
49
50
  #
50
51
  def find(*args, **options, &optional_filter_block)
51
52
  options[:session_options] = session_options
52
- synced_resolve Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
53
+ synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
53
54
  end
54
55
 
55
56
  ##
@@ -72,7 +73,7 @@ module Capybara
72
73
  #
73
74
  def ancestor(*args, **options, &optional_filter_block)
74
75
  options[:session_options] = session_options
75
- synced_resolve Capybara::Queries::AncestorQuery.new(*args, options, &optional_filter_block)
76
+ synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block)
76
77
  end
77
78
 
78
79
  ##
@@ -95,7 +96,7 @@ module Capybara
95
96
  #
96
97
  def sibling(*args, **options, &optional_filter_block)
97
98
  options[:session_options] = session_options
98
- synced_resolve Capybara::Queries::SiblingQuery.new(*args, options, &optional_filter_block)
99
+ synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block)
99
100
  end
100
101
 
101
102
  ##
@@ -125,7 +126,7 @@ module Capybara
125
126
  # @return [Capybara::Node::Element] The found element
126
127
  #
127
128
  def find_field(locator = nil, **options, &optional_filter_block)
128
- find(:field, locator, options, &optional_filter_block)
129
+ find(:field, locator, **options, &optional_filter_block)
129
130
  end
130
131
 
131
132
  ##
@@ -145,7 +146,7 @@ module Capybara
145
146
  # @return [Capybara::Node::Element] The found element
146
147
  #
147
148
  def find_link(locator = nil, **options, &optional_filter_block)
148
- find(:link, locator, options, &optional_filter_block)
149
+ find(:link, locator, **options, &optional_filter_block)
149
150
  end
150
151
 
151
152
  ##
@@ -172,7 +173,7 @@ module Capybara
172
173
  # @return [Capybara::Node::Element] The found element
173
174
  #
174
175
  def find_button(locator = nil, **options, &optional_filter_block)
175
- find(:button, locator, options, &optional_filter_block)
176
+ find(:button, locator, **options, &optional_filter_block)
176
177
  end
177
178
 
178
179
  ##
@@ -186,7 +187,7 @@ module Capybara
186
187
  # @return [Capybara::Node::Element] The found element
187
188
  #
188
189
  def find_by_id(id, **options, &optional_filter_block)
189
- find(:id, id, options, &optional_filter_block)
190
+ find(:id, id, **options, &optional_filter_block)
190
191
  end
191
192
 
192
193
  ##
@@ -235,21 +236,25 @@ module Capybara
235
236
  # @option options [Integer] maximum Maximum number of matches that are expected to be found
236
237
  # @option options [Integer] minimum Minimum number of matches that are expected to be found
237
238
  # @option options [Range] between Number of matches found must be within the given range
239
+ # @option options [Boolean] allow_reload Beta feature - May be removed in any version.
240
+ # When `true` allows elements to be reloaded if they become stale. This is an advanced behavior and should only be used
241
+ # if you fully understand the potential ramifications. The results can be confusing on dynamic pages. Defaults to `false`
238
242
  # @overload all([kind = Capybara.default_selector], locator = nil, **options)
239
243
  # @overload all([kind = Capybara.default_selector], locator = nil, **options, &filter_block)
240
244
  # @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
241
245
  # @yieldreturn [Boolean] Should the element be considered in the results?
242
246
  # @return [Capybara::Result] A collection of found elements
243
247
  # @raise [Capybara::ExpectationNotMet] The number of elements found doesn't match the specified conditions
244
- def all(*args, **options, &optional_filter_block)
248
+ def all(*args, allow_reload: false, **options, &optional_filter_block)
245
249
  minimum_specified = options_include_minimum?(options)
246
250
  options = { minimum: 1 }.merge(options) unless minimum_specified
247
251
  options[:session_options] = session_options
248
- query = Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block)
252
+ query = Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
249
253
  result = nil
250
254
  begin
251
255
  synchronize(query.wait) do
252
256
  result = query.resolve_for(self)
257
+ result.allow_reload! if allow_reload
253
258
  raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
254
259
 
255
260
  result
@@ -278,7 +283,7 @@ module Capybara
278
283
  #
279
284
  def first(*args, **options, &optional_filter_block)
280
285
  options = { minimum: 1 }.merge(options) unless options_include_minimum?(options)
281
- all(*args, options, &optional_filter_block).first
286
+ all(*args, **options, &optional_filter_block).first
282
287
  end
283
288
 
284
289
  private
@@ -292,7 +297,9 @@ module Capybara
292
297
  result = query.resolve_for(self)
293
298
  end
294
299
 
295
- raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.applied_description}" if ambiguous?(query, result)
300
+ if ambiguous?(query, result)
301
+ raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.applied_description}"
302
+ end
296
303
  raise Capybara::ElementNotFound, "Unable to find #{query.applied_description}" if result.empty?
297
304
 
298
305
  result.first