capybara 3.31.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +51 -0
  3. data/README.md +10 -3
  4. data/lib/capybara.rb +17 -7
  5. data/lib/capybara/cucumber.rb +1 -1
  6. data/lib/capybara/minitest.rb +215 -141
  7. data/lib/capybara/minitest/spec.rb +153 -97
  8. data/lib/capybara/node/actions.rb +16 -20
  9. data/lib/capybara/node/element.rb +2 -0
  10. data/lib/capybara/node/matchers.rb +4 -6
  11. data/lib/capybara/queries/selector_query.rb +8 -1
  12. data/lib/capybara/queries/style_query.rb +1 -1
  13. data/lib/capybara/queries/text_query.rb +6 -0
  14. data/lib/capybara/rack_test/browser.rb +3 -1
  15. data/lib/capybara/registration_container.rb +44 -0
  16. data/lib/capybara/registrations/servers.rb +1 -1
  17. data/lib/capybara/result.rb +5 -1
  18. data/lib/capybara/rspec/matcher_proxies.rb +4 -4
  19. data/lib/capybara/rspec/matchers/have_text.rb +1 -1
  20. data/lib/capybara/selector.rb +10 -1
  21. data/lib/capybara/selector/definition.rb +5 -4
  22. data/lib/capybara/selector/definition/button.rb +1 -0
  23. data/lib/capybara/selector/definition/fillable_field.rb +1 -1
  24. data/lib/capybara/selector/definition/link.rb +8 -0
  25. data/lib/capybara/selector/definition/table.rb +1 -1
  26. data/lib/capybara/selector/selector.rb +4 -0
  27. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  28. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  29. data/lib/capybara/selenium/driver.rb +7 -4
  30. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +7 -9
  31. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +7 -9
  32. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -2
  33. data/lib/capybara/selenium/node.rb +69 -9
  34. data/lib/capybara/selenium/nodes/chrome_node.rb +0 -9
  35. data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
  36. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  37. data/lib/capybara/selenium/patches/logs.rb +3 -5
  38. data/lib/capybara/session.rb +3 -3
  39. data/lib/capybara/session/config.rb +3 -1
  40. data/lib/capybara/spec/public/test.js +18 -0
  41. data/lib/capybara/spec/session/click_button_spec.rb +11 -0
  42. data/lib/capybara/spec/session/fill_in_spec.rb +9 -0
  43. data/lib/capybara/spec/session/find_spec.rb +11 -8
  44. data/lib/capybara/spec/session/has_button_spec.rb +16 -0
  45. data/lib/capybara/spec/session/has_css_spec.rb +9 -6
  46. data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
  47. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  48. data/lib/capybara/spec/session/has_select_spec.rb +4 -4
  49. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  50. data/lib/capybara/spec/session/node_spec.rb +54 -27
  51. data/lib/capybara/spec/session/window/window_spec.rb +7 -7
  52. data/lib/capybara/spec/spec_helper.rb +2 -2
  53. data/lib/capybara/spec/test_app.rb +14 -18
  54. data/lib/capybara/spec/views/form.erb +7 -1
  55. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  56. data/lib/capybara/spec/views/with_html.erb +2 -2
  57. data/lib/capybara/spec/views/with_js.erb +1 -0
  58. data/lib/capybara/version.rb +1 -1
  59. data/spec/capybara_spec.rb +1 -1
  60. data/spec/dsl_spec.rb +14 -1
  61. data/spec/minitest_spec.rb +1 -1
  62. data/spec/rack_test_spec.rb +13 -0
  63. data/spec/regexp_dissassembler_spec.rb +0 -4
  64. data/spec/result_spec.rb +38 -31
  65. data/spec/rspec/shared_spec_matchers.rb +65 -53
  66. data/spec/selector_spec.rb +1 -1
  67. data/spec/selenium_spec_chrome.rb +4 -2
  68. data/spec/selenium_spec_chrome_remote.rb +2 -0
  69. data/spec/server_spec.rb +41 -49
  70. data/spec/shared_selenium_node.rb +18 -0
  71. data/spec/shared_selenium_session.rb +25 -7
  72. data/spec/spec_helper.rb +1 -1
  73. metadata +5 -3
@@ -5,192 +5,248 @@ require 'minitest/spec'
5
5
  module Capybara
6
6
  module Minitest
7
7
  module Expectations
8
- %w[text content title current_path].each do |assertion|
9
- infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
10
- infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
11
- end
8
+ ##
9
+ # Expectation that there is an ancestor
10
+ #
11
+ # @!method must_have_ancestor
12
+ # See {Capybara::Node::Matchers#has_ancestor?}
12
13
 
13
- # rubocop:disable Style/MultilineBlockChain
14
- (%w[selector xpath css link button field select table checked_field unchecked_field
15
- ancestor sibling].flat_map do |assertion|
16
- [%W[assert_#{assertion} must_have_#{assertion}],
17
- %W[refute_#{assertion} wont_have_#{assertion}]]
18
- end + [%w[assert_all_of_selectors must_have_all_of_selectors],
19
- %w[assert_none_of_selectors must_have_none_of_selectors],
20
- %w[assert_any_of_selectors must_have_any_of_selectors],
21
- %w[assert_matches_style must_match_style]] +
22
- %w[selector xpath css].flat_map do |assertion|
23
- [%W[assert_matches_#{assertion} must_match_#{assertion}],
24
- %W[refute_matches_#{assertion} wont_match_#{assertion}]]
25
- end).each do |(meth, new_name)|
26
- class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
27
- def #{new_name} *args, &block
28
- ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
29
- end
30
- ASSERTION
14
+ ##
15
+ # Expectation that there is button
16
+ #
17
+ # @!method must_have_button
18
+ # See {Capybara::Node::Matchers#has_button?}
31
19
 
32
- ::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
33
- def #{new_name} *args, &block
34
- ctx.#{meth}(target, *args, &block)
35
- end
36
- ASSERTION
37
- end
38
- # rubocop:enable Style/MultilineBlockChain
20
+ ##
21
+ # Expectation that there is no button
22
+ #
23
+ # @!method wont_have_button
24
+ # See {Capybara::Node::Matchers#has_no_button?}
39
25
 
40
26
  ##
41
- # @deprecated
42
- def must_have_style(*args, &block)
43
- warn 'must_have_style is deprecated, please use must_match_style'
44
- must_match_style(*args, &block)
45
- end
27
+ # Expectation that there is checked_field
28
+ #
29
+ # @!method must_have_checked_field
30
+ # See {Capybara::Node::Matchers#has_checked_field?}
46
31
 
47
32
  ##
48
- # Expectation that there is xpath
33
+ # Expectation that there is no checked_field
49
34
  #
50
- # @!method must_have_xpath
51
- # see Capybara::Node::Matchers#has_xpath?
35
+ # @!method wont_have_checked_field
36
+ # See {Capybara::Node::Matchers#has_no_checked_field?}
52
37
 
53
38
  ##
54
- # Expectation that there is no xpath
39
+ # Expectation that there is unchecked_field
55
40
  #
56
- # @!method wont_have_xpath
57
- # see Capybara::Node::Matchers#has_no_xpath?
41
+ # @!method must_have_unchecked_field
42
+ # See {Capybara::Node::Matchers#has_unchecked_field?}
58
43
 
59
44
  ##
60
- # Expectation that there is css
45
+ # Expectation that there is no unchecked_field
61
46
  #
62
- # @!method must_have_css
63
- # see Capybara::Node::Matchers#has_css?
47
+ # @!method wont_have_unchecked_field
48
+ # See {Capybara::Node::Matchers#has_no_unchecked_field?}
64
49
 
65
50
  ##
66
- # Expectation that there is no css
51
+ # Expectation that page content does match
67
52
  #
68
- # @!method wont_have_css
69
- # see Capybara::Node::Matchers#has_no_css?
53
+ # @!method must_have_content
54
+ # See {Capybara::Node::Matchers#has_content?}
70
55
 
71
56
  ##
72
- # Expectation that there is link
57
+ # Expectation that page content does not match
73
58
  #
74
- # @!method must_have_link
75
- # see {Capybara::Node::Matchers#has_link?}
59
+ # @!method wont_have_content
60
+ # See {Capybara::Node::Matchers#has_no_content?}
76
61
 
77
62
  ##
78
- # Expectation that there is no link
63
+ # Expectation that there is css
79
64
  #
80
- # @!method wont_have_link
81
- # see {Capybara::Node::Matchers#has_no_link?}
65
+ # @!method must_have_css
66
+ # See {Capybara::Node::Matchers#has_css?}
82
67
 
83
68
  ##
84
- # Expectation that there is button
69
+ # Expectation that there is no css
85
70
  #
86
- # @!method must_have_button
87
- # see {Capybara::Node::Matchers#has_button?}
71
+ # @!method wont_have_css
72
+ # See {Capybara::Node::Matchers#has_no_css?}
88
73
 
89
74
  ##
90
- # Expectation that there is no button
75
+ # Expectation that current path matches
91
76
  #
92
- # @!method wont_have_button
93
- # see {Capybara::Node::Matchers#has_no_button?}
77
+ # @!method must_have_current_path
78
+ # See {Capybara::SessionMatchers#has_current_path?}
79
+
80
+ ##
81
+ # Expectation that current page does not match
82
+ #
83
+ # @!method wont_have_current_path
84
+ # See {Capybara::SessionMatchers#has_no_current_path?}
94
85
 
95
86
  ##
96
87
  # Expectation that there is field
97
88
  #
98
89
  # @!method must_have_field
99
- # see {Capybara::Node::Matchers#has_field?}
90
+ # See {Capybara::Node::Matchers#has_field?}
100
91
 
101
92
  ##
102
93
  # Expectation that there is no field
103
94
  #
104
95
  # @!method wont_have_field
105
- # see {Capybara::Node::Matchers#has_no_field?}
96
+ # See {Capybara::Node::Matchers#has_no_field?}
106
97
 
107
98
  ##
108
- # Expectation that there is checked_field
99
+ # Expectation that there is link
109
100
  #
110
- # @!method must_have_checked_field
111
- # see {Capybara::Node::Matchers#has_checked_field?}
101
+ # @!method must_have_link
102
+ # See {Capybara::Node::Matchers#has_link?}
112
103
 
113
104
  ##
114
- # Expectation that there is no checked_field
105
+ # Expectation that there is no link
115
106
  #
116
- # @!method wont_have_chceked_field
107
+ # @!method wont_have_link
108
+ # See {Capybara::Node::Matchers#has_no_link?}
117
109
 
118
110
  ##
119
- # Expectation that there is unchecked_field
111
+ # Expectation that page text does match
120
112
  #
121
- # @!method must_have_unchecked_field
122
- # see {Capybara::Node::Matchers#has_unchecked_field?}
113
+ # @!method must_have_text
114
+ # See {Capybara::Node::Matchers#has_text?}
123
115
 
124
116
  ##
125
- # Expectation that there is no unchecked_field
117
+ # Expectation that page text does not match
118
+ #
119
+ # @!method wont_have_text
120
+ # See {Capybara::Node::Matchers#has_no_text?}
121
+
122
+ ##
123
+ # Expectation that page title does match
124
+ #
125
+ # @!method must_have_title
126
+ # See {Capybara::Node::DocumentMatchers#has_title?}
127
+
128
+ ##
129
+ # Expectation that page title does not match
126
130
  #
127
- # @!method wont_have_unchceked_field
131
+ # @!method wont_have_title
132
+ # See {Capybara::Node::DocumentMatchers#has_no_title?}
128
133
 
129
134
  ##
130
135
  # Expectation that there is select
131
136
  #
132
137
  # @!method must_have_select
133
- # see {Capybara::Node::Matchers#has_select?}
138
+ # See {Capybara::Node::Matchers#has_select?}
134
139
 
135
140
  ##
136
141
  # Expectation that there is no select
137
142
  #
138
143
  # @!method wont_have_select
139
- # see {Capybara::Node::Matchers#has_no_select?}
144
+ # See {Capybara::Node::Matchers#has_no_select?}
140
145
 
141
146
  ##
142
- # Expectation that there is table
147
+ # Expectation that there is a selector
143
148
  #
144
- # @!method must_have_table
145
- # see {Capybara::Node::Matchers#has_table?}
149
+ # @!method must_have_selector
150
+ # See {Capybara::Node::Matchers#has_selector?}
146
151
 
147
152
  ##
148
- # Expectation that there is no table
153
+ # Expectation that there is no selector
149
154
  #
150
- # @!method wont_have_table
151
- # see {Capybara::Node::Matchers#has_no_table?}
155
+ # @!method wont_have_selector
156
+ # See {Capybara::Node::Matchers#has_no_selector?}
152
157
 
153
158
  ##
154
- # Expectation that page title does match
159
+ # Expectation that all of the provided selectors are present
155
160
  #
156
- # @!method must_have_title
157
- # see {Capybara::Node::DocumentMatchers#assert_title}
161
+ # @!method must_have_all_of_selectors
162
+ # See {Capybara::Node::Matchers#assert_all_of_selectors}
158
163
 
159
164
  ##
160
- # Expectation that page title does not match
165
+ # Expectation that none of the provided selectors are present
161
166
  #
162
- # @!method wont_have_title
163
- # see {Capybara::Node::DocumentMatchers#assert_no_title}
167
+ # @!method must_have_none_of_selectors
168
+ # See {Capybara::Node::Matchers#assert_none_of_selectors}
164
169
 
165
170
  ##
166
- # Expectation that current path matches
171
+ # Expectation that any of the provided selectors are present
167
172
  #
168
- # @!method must_have_current_path
169
- # see {Capybara::SessionMatchers#assert_current_path}
173
+ # @!method must_have_any_of_selectors
174
+ # See {Capybara::Node::Matchers#assert_any_of_selectors}
170
175
 
171
176
  ##
172
- # Expectation that current page does not match
177
+ # Expectation that there is a sibling
173
178
  #
174
- # @!method wont_have_current_path
175
- # see {Capybara::SessionMatchers#assert_no_current_path}
179
+ # @!method must_have_sibling
180
+ # See {Capybara::Node::Matchers#has_sibling?}
176
181
 
177
182
  ##
178
183
  # Expectation that element has style
179
184
  #
180
185
  # @!method must_match_style
181
- # see {Capybara::Node::Matchers#assert_matches_style}
186
+ # See {Capybara::Node::Matchers#matches_style?}
182
187
 
183
188
  ##
184
- # Expectation that there is an ancestor
189
+ # Expectation that there is table
185
190
  #
186
- # @!method must_have_ancestor
187
- # see Capybara::Node::Matchers#has_ancestor?
191
+ # @!method must_have_table
192
+ # See {Capybara::Node::Matchers#has_table?}
188
193
 
189
194
  ##
190
- # Expectation that there is a sibling
195
+ # Expectation that there is no table
191
196
  #
192
- # @!method must_have_sibling
193
- # see Capybara::Node::Matchers#has_sibling?
197
+ # @!method wont_have_table
198
+ # See {Capybara::Node::Matchers#has_no_table?}
199
+
200
+ ##
201
+ # Expectation that there is xpath
202
+ #
203
+ # @!method must_have_xpath
204
+ # See {Capybara::Node::Matchers#has_xpath?}
205
+
206
+ ##
207
+ # Expectation that there is no xpath
208
+ #
209
+ # @!method wont_have_xpath
210
+ # See {Capybara::Node::Matchers#has_no_xpath?}
211
+
212
+ %w[text content title current_path].each do |assertion|
213
+ infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
214
+ infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
215
+ end
216
+
217
+ # rubocop:disable Style/MultilineBlockChain
218
+ (%w[selector xpath css link button field select table checked_field unchecked_field
219
+ ancestor sibling].flat_map do |assertion|
220
+ [%W[assert_#{assertion} must_have_#{assertion}],
221
+ %W[refute_#{assertion} wont_have_#{assertion}]]
222
+ end + [%w[assert_all_of_selectors must_have_all_of_selectors],
223
+ %w[assert_none_of_selectors must_have_none_of_selectors],
224
+ %w[assert_any_of_selectors must_have_any_of_selectors],
225
+ %w[assert_matches_style must_match_style]] +
226
+ %w[selector xpath css].flat_map do |assertion|
227
+ [%W[assert_matches_#{assertion} must_match_#{assertion}],
228
+ %W[refute_matches_#{assertion} wont_match_#{assertion}]]
229
+ end).each do |(meth, new_name)|
230
+ class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
231
+ def #{new_name} *args, &block
232
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
233
+ end
234
+ ASSERTION
235
+
236
+ ::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
237
+ def #{new_name} *args, &block
238
+ ctx.#{meth}(target, *args, &block)
239
+ end
240
+ ASSERTION
241
+ end
242
+ # rubocop:enable Style/MultilineBlockChain
243
+
244
+ ##
245
+ # @deprecated
246
+ def must_have_style(*args, &block)
247
+ warn 'must_have_style is deprecated, please use must_match_style'
248
+ must_match_style(*args, &block)
249
+ end
194
250
  end
195
251
  end
196
252
  end
@@ -308,16 +308,14 @@ module Capybara
308
308
 
309
309
  def find_select_or_datalist_input(from, options)
310
310
  synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
311
+ find(:select, from, **options)
312
+ rescue Capybara::ElementNotFound => select_error # rubocop:disable Naming/RescuedExceptionsVariableName
313
+ raise if %i[selected with_selected multiple].any? { |option| options.key?(option) }
314
+
311
315
  begin
312
- find(:select, from, **options)
313
- rescue Capybara::ElementNotFound => select_error # rubocop:disable Naming/RescuedExceptionsVariableName
314
- raise if %i[selected with_selected multiple].any? { |option| options.key?(option) }
315
-
316
- begin
317
- find(:datalist_input, from, **options)
318
- rescue Capybara::ElementNotFound => dlinput_error # rubocop:disable Naming/RescuedExceptionsVariableName
319
- raise Capybara::ElementNotFound, "#{select_error.message} and #{dlinput_error.message}"
320
- end
316
+ find(:datalist_input, from, **options)
317
+ rescue Capybara::ElementNotFound => dlinput_error # rubocop:disable Naming/RescuedExceptionsVariableName
318
+ raise Capybara::ElementNotFound, "#{select_error.message} and #{dlinput_error.message}"
321
319
  end
322
320
  end
323
321
  end
@@ -367,18 +365,16 @@ module Capybara
367
365
  options[:allow_self] = true if locator.nil?
368
366
 
369
367
  synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
368
+ el = find(selector, locator, **options)
369
+ el.set(checked)
370
+ rescue StandardError => e
371
+ raise unless allow_label_click && catch_error?(e)
372
+
370
373
  begin
371
- el = find(selector, locator, **options)
372
- el.set(checked)
373
- rescue StandardError => e
374
- raise unless allow_label_click && catch_error?(e)
375
-
376
- begin
377
- el ||= find(selector, locator, **options.merge(visible: :all))
378
- el.session.find(:label, for: el, visible: true).click unless el.checked? == checked
379
- rescue StandardError # swallow extra errors - raise original
380
- raise e
381
- end
374
+ el ||= find(selector, locator, **options.merge(visible: :all))
375
+ el.session.find(:label, for: el, visible: true).click unless el.checked? == checked
376
+ rescue StandardError # swallow extra errors - raise original
377
+ raise e
382
378
  end
383
379
  end
384
380
  end
@@ -165,6 +165,7 @@ module Capybara
165
165
  # offset will be from the element center, otherwise it will be from the top left corner of the element
166
166
  # @option options [Integer] y Y coordinate to offset the click location. If {Capybara.configure w3c_click_offset} is `true` the
167
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)
168
169
  # @return [Capybara::Node::Element] The element
169
170
  def click(*keys, **options)
170
171
  perform_click_action(keys, **options) do |k, opts|
@@ -178,6 +179,7 @@ module Capybara
178
179
  #
179
180
  # @macro action_waiting_behavior
180
181
  # @macro click_modifiers
182
+ # @option options [Float] delay Delay between the mouse down and mouse up events in seconds (0)
181
183
  # @return [Capybara::Node::Element] The element
182
184
  def right_click(*keys, **options)
183
185
  perform_click_action(keys, **options) do |k, opts|
@@ -201,12 +201,10 @@ module Capybara
201
201
  selector = extract_selector(args)
202
202
  synchronize(wait) do
203
203
  res = args.map do |locator|
204
- begin
205
- assert_selector(selector, locator, options, &optional_filter_block)
206
- break nil
207
- rescue Capybara::ExpectationNotMet => e
208
- e.message
209
- end
204
+ assert_selector(selector, locator, options, &optional_filter_block)
205
+ break nil
206
+ rescue Capybara::ExpectationNotMet => e
207
+ e.message
210
208
  end
211
209
  raise Capybara::ExpectationNotMet, res.join(' or ') if res
212
210
 
@@ -6,6 +6,7 @@ module Capybara
6
6
  module Queries
7
7
  class SelectorQuery < Queries::BaseQuery
8
8
  attr_reader :expression, :selector, :locator, :options
9
+
9
10
  SPATIAL_KEYS = %i[above below left_of right_of near].freeze
10
11
  VALID_KEYS = SPATIAL_KEYS + COUNT_KEYS +
11
12
  %i[text id class style visible obscured exact exact_text normalize_ws match wait filter_set]
@@ -14,6 +15,7 @@ module Capybara
14
15
  def initialize(*args,
15
16
  session_options:,
16
17
  enable_aria_label: session_options.enable_aria_label,
18
+ enable_aria_role: session_options.enable_aria_role,
17
19
  test_id: session_options.test_id,
18
20
  selector_format: nil,
19
21
  order: nil,
@@ -30,7 +32,11 @@ module Capybara
30
32
 
31
33
  @selector = Selector.new(
32
34
  find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]),
33
- config: { enable_aria_label: enable_aria_label, test_id: test_id },
35
+ config: {
36
+ enable_aria_label: enable_aria_label,
37
+ enable_aria_role: enable_aria_role,
38
+ test_id: test_id
39
+ },
34
40
  format: selector_format
35
41
  )
36
42
 
@@ -575,6 +581,7 @@ module Capybara
575
581
 
576
582
  class Rectangle
577
583
  attr_reader :top, :bottom, :left, :right
584
+
578
585
  def initialize(position)
579
586
  # rubocop:disable Style/RescueModifier
580
587
  @top = position['top'] rescue position['y']