capybara 3.20.1 → 3.22.0
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/.yardopts +1 -0
- data/History.md +35 -0
- data/README.md +16 -11
- data/lib/capybara/driver/node.rb +6 -2
- data/lib/capybara/helpers.rb +1 -1
- data/lib/capybara/minitest/spec.rb +20 -7
- data/lib/capybara/minitest.rb +18 -5
- data/lib/capybara/node/actions.rb +36 -29
- data/lib/capybara/node/element.rb +123 -82
- data/lib/capybara/node/finders.rb +42 -53
- data/lib/capybara/node/matchers.rb +161 -72
- data/lib/capybara/queries/ancestor_query.rb +9 -7
- data/lib/capybara/queries/sibling_query.rb +11 -4
- data/lib/capybara/result.rb +2 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +30 -0
- data/lib/capybara/rspec/matchers/have_sibling.rb +30 -0
- data/lib/capybara/rspec/matchers.rb +16 -1
- data/lib/capybara/selector/definition/checkbox.rb +8 -5
- data/lib/capybara/selector/definition/css.rb +4 -1
- data/lib/capybara/selector/definition/radio_button.rb +8 -5
- data/lib/capybara/selector/filter_set.rb +4 -2
- data/lib/capybara/selector/regexp_disassembler.rb +2 -2
- data/lib/capybara/selector.rb +153 -171
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +35 -1
- data/lib/capybara/selenium/extensions/html5_drag.rb +63 -0
- data/lib/capybara/selenium/node.rb +4 -0
- data/lib/capybara/selenium/nodes/chrome_node.rb +4 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +4 -13
- data/lib/capybara/selenium/nodes/ie_node.rb +14 -3
- data/lib/capybara/selenium/nodes/safari_node.rb +0 -13
- data/lib/capybara/session/config.rb +1 -1
- data/lib/capybara/session.rb +74 -71
- data/lib/capybara/spec/public/test.js +29 -3
- data/lib/capybara/spec/session/attach_file_spec.rb +13 -5
- data/lib/capybara/spec/session/check_spec.rb +6 -0
- data/lib/capybara/spec/session/choose_spec.rb +6 -0
- data/lib/capybara/spec/session/has_ancestor_spec.rb +44 -0
- data/lib/capybara/spec/session/has_css_spec.rb +4 -3
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/node_spec.rb +85 -0
- data/lib/capybara/spec/session/select_spec.rb +5 -5
- data/lib/capybara/spec/spec_helper.rb +4 -0
- data/lib/capybara/spec/views/form.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +10 -10
- data/lib/capybara.rb +42 -36
- data/spec/minitest_spec.rb +11 -1
- data/spec/minitest_spec_spec.rb +11 -1
- data/spec/regexp_dissassembler_spec.rb +1 -1
- data/spec/selenium_spec_firefox.rb +2 -0
- data/spec/selenium_spec_ie.rb +13 -7
- data/spec/selenium_spec_safari.rb +2 -0
- data/spec/shared_selenium_session.rb +1 -51
- metadata +23 -18
|
@@ -43,7 +43,7 @@ module Capybara
|
|
|
43
43
|
|
|
44
44
|
##
|
|
45
45
|
#
|
|
46
|
-
# Retrieve the text of the element. If
|
|
46
|
+
# Retrieve the text of the element. If {Capybara.configure ignore_hidden_elements}
|
|
47
47
|
# is `true`, which it is by default, then this will return only text
|
|
48
48
|
# which is visible. The exact semantics of this may differ between
|
|
49
49
|
# drivers, but generally any text within elements with `display:none` is
|
|
@@ -61,7 +61,7 @@ module Capybara
|
|
|
61
61
|
|
|
62
62
|
##
|
|
63
63
|
#
|
|
64
|
-
# Retrieve the given attribute
|
|
64
|
+
# Retrieve the given attribute.
|
|
65
65
|
#
|
|
66
66
|
# element[:title] # => HTML title attribute
|
|
67
67
|
#
|
|
@@ -74,7 +74,7 @@ module Capybara
|
|
|
74
74
|
|
|
75
75
|
##
|
|
76
76
|
#
|
|
77
|
-
# Retrieve the given CSS styles
|
|
77
|
+
# Retrieve the given CSS styles.
|
|
78
78
|
#
|
|
79
79
|
# element.style('color', 'font-size') # => Computed values of CSS 'color' and 'font-size' styles
|
|
80
80
|
#
|
|
@@ -109,7 +109,7 @@ module Capybara
|
|
|
109
109
|
# Set the value of the form element to the given value.
|
|
110
110
|
#
|
|
111
111
|
# @param [String] value The new value
|
|
112
|
-
# @param [Hash
|
|
112
|
+
# @param [Hash] options Driver specific options for how to set the value. Take default values from {Capybara.configure default_set_options}.
|
|
113
113
|
#
|
|
114
114
|
# @return [Capybara::Node::Element] The element
|
|
115
115
|
def set(value, **options)
|
|
@@ -122,8 +122,15 @@ module Capybara
|
|
|
122
122
|
|
|
123
123
|
##
|
|
124
124
|
#
|
|
125
|
-
# Select this node if is an option element inside a select tag
|
|
125
|
+
# Select this node if it is an option element inside a select tag.
|
|
126
126
|
#
|
|
127
|
+
# @!macro action_waiting_behavior
|
|
128
|
+
# If the driver dynamic pages (JS) and the element is currently non-interactable, this method will
|
|
129
|
+
# continuously retry the action until either the element becomes interactable or the maximum
|
|
130
|
+
# wait time expires.
|
|
131
|
+
#
|
|
132
|
+
# @param [false, Numeric] wait
|
|
133
|
+
# Maximum time to wait for the action to succeed. Defaults to {Capybara.configure default_max_wait_time}.
|
|
127
134
|
# @return [Capybara::Node::Element] The element
|
|
128
135
|
def select_option(wait: nil)
|
|
129
136
|
synchronize(wait) { base.select_option }
|
|
@@ -132,8 +139,9 @@ module Capybara
|
|
|
132
139
|
|
|
133
140
|
##
|
|
134
141
|
#
|
|
135
|
-
# Unselect this node if is an option element inside a multiple select tag
|
|
142
|
+
# Unselect this node if it is an option element inside a multiple select tag.
|
|
136
143
|
#
|
|
144
|
+
# @macro action_waiting_behavior
|
|
137
145
|
# @return [Capybara::Node::Element] The element
|
|
138
146
|
def unselect_option(wait: nil)
|
|
139
147
|
synchronize(wait) { base.unselect_option }
|
|
@@ -142,11 +150,12 @@ module Capybara
|
|
|
142
150
|
|
|
143
151
|
##
|
|
144
152
|
#
|
|
145
|
-
# Click the Element
|
|
153
|
+
# Click the Element.
|
|
146
154
|
#
|
|
155
|
+
# @macro action_waiting_behavior
|
|
147
156
|
# @!macro click_modifiers
|
|
148
|
-
# Both x: and y: must be specified if an offset is wanted, if not specified the click will occur at the middle of the element
|
|
149
|
-
# @overload $0(*modifier_keys, **offset)
|
|
157
|
+
# Both x: and y: must be specified if an offset is wanted, if not specified the click will occur at the middle of the element.
|
|
158
|
+
# @overload $0(*modifier_keys, wait: nil, **offset)
|
|
150
159
|
# @param *modifier_keys [:alt, :control, :meta, :shift] ([]) Keys to be held down when clicking
|
|
151
160
|
# @option offset [Integer] x X coordinate to offset the click location from the top left corner of the element
|
|
152
161
|
# @option offset [Integer] y Y coordinate to offset the click location from the top left corner of the element
|
|
@@ -160,8 +169,9 @@ module Capybara
|
|
|
160
169
|
|
|
161
170
|
##
|
|
162
171
|
#
|
|
163
|
-
# Right Click the Element
|
|
172
|
+
# Right Click the Element.
|
|
164
173
|
#
|
|
174
|
+
# @macro action_waiting_behavior
|
|
165
175
|
# @macro click_modifiers
|
|
166
176
|
# @return [Capybara::Node::Element] The element
|
|
167
177
|
def right_click(*keys, wait: nil, **offset)
|
|
@@ -173,8 +183,9 @@ module Capybara
|
|
|
173
183
|
|
|
174
184
|
##
|
|
175
185
|
#
|
|
176
|
-
# Double Click the Element
|
|
186
|
+
# Double Click the Element.
|
|
177
187
|
#
|
|
188
|
+
# @macro action_waiting_behavior
|
|
178
189
|
# @macro click_modifiers
|
|
179
190
|
# @return [Capybara::Node::Element] The element
|
|
180
191
|
def double_click(*keys, wait: nil, **offset)
|
|
@@ -186,7 +197,7 @@ module Capybara
|
|
|
186
197
|
|
|
187
198
|
##
|
|
188
199
|
#
|
|
189
|
-
# Send Keystrokes to the Element
|
|
200
|
+
# Send Keystrokes to the Element.
|
|
190
201
|
#
|
|
191
202
|
# @overload send_keys(keys, ...)
|
|
192
203
|
# @param keys [String, Symbol, Array<String,Symbol>]
|
|
@@ -194,65 +205,65 @@ module Capybara
|
|
|
194
205
|
# Examples:
|
|
195
206
|
#
|
|
196
207
|
# element.send_keys "foo" #=> value: 'foo'
|
|
197
|
-
# element.send_keys "tet", :left, "s"
|
|
208
|
+
# element.send_keys "tet", :left, "s" #=> value: 'test'
|
|
198
209
|
# element.send_keys [:control, 'a'], :space #=> value: ' ' - assuming ctrl-a selects all contents
|
|
199
210
|
#
|
|
200
|
-
# Symbols supported for keys
|
|
201
|
-
# :cancel
|
|
202
|
-
# :help
|
|
203
|
-
# :backspace
|
|
204
|
-
# :tab
|
|
205
|
-
# :clear
|
|
206
|
-
# :return
|
|
207
|
-
# :enter
|
|
208
|
-
# :shift
|
|
209
|
-
# :control
|
|
210
|
-
# :alt
|
|
211
|
-
# :pause
|
|
212
|
-
# :escape
|
|
213
|
-
# :space
|
|
214
|
-
# :page_up
|
|
215
|
-
# :page_down
|
|
216
|
-
# :end
|
|
217
|
-
# :home
|
|
218
|
-
# :left
|
|
219
|
-
# :up
|
|
220
|
-
# :right
|
|
221
|
-
# :down
|
|
222
|
-
# :insert
|
|
223
|
-
# :delete
|
|
224
|
-
# :semicolon
|
|
225
|
-
# :equals
|
|
226
|
-
# :numpad0
|
|
227
|
-
# :numpad1
|
|
228
|
-
# :numpad2
|
|
229
|
-
# :numpad3
|
|
230
|
-
# :numpad4
|
|
231
|
-
# :numpad5
|
|
232
|
-
# :numpad6
|
|
233
|
-
# :numpad7
|
|
234
|
-
# :numpad8
|
|
235
|
-
# :numpad9
|
|
236
|
-
# :multiply - numeric keypad *
|
|
237
|
-
# :add - numeric keypad +
|
|
238
|
-
# :separator - numeric keypad 'separator' key ??
|
|
239
|
-
# :subtract - numeric keypad -
|
|
240
|
-
# :decimal - numeric keypad .
|
|
241
|
-
# :divide - numeric keypad /
|
|
242
|
-
# :f1
|
|
243
|
-
# :f2
|
|
244
|
-
# :f3
|
|
245
|
-
# :f4
|
|
246
|
-
# :f5
|
|
247
|
-
# :f6
|
|
248
|
-
# :f7
|
|
249
|
-
# :f8
|
|
250
|
-
# :f9
|
|
251
|
-
# :f10
|
|
252
|
-
# :f11
|
|
253
|
-
# :f12
|
|
254
|
-
# :meta
|
|
255
|
-
# :command - alias of :meta
|
|
211
|
+
# Symbols supported for keys:
|
|
212
|
+
# * :cancel
|
|
213
|
+
# * :help
|
|
214
|
+
# * :backspace
|
|
215
|
+
# * :tab
|
|
216
|
+
# * :clear
|
|
217
|
+
# * :return
|
|
218
|
+
# * :enter
|
|
219
|
+
# * :shift
|
|
220
|
+
# * :control
|
|
221
|
+
# * :alt
|
|
222
|
+
# * :pause
|
|
223
|
+
# * :escape
|
|
224
|
+
# * :space
|
|
225
|
+
# * :page_up
|
|
226
|
+
# * :page_down
|
|
227
|
+
# * :end
|
|
228
|
+
# * :home
|
|
229
|
+
# * :left
|
|
230
|
+
# * :up
|
|
231
|
+
# * :right
|
|
232
|
+
# * :down
|
|
233
|
+
# * :insert
|
|
234
|
+
# * :delete
|
|
235
|
+
# * :semicolon
|
|
236
|
+
# * :equals
|
|
237
|
+
# * :numpad0
|
|
238
|
+
# * :numpad1
|
|
239
|
+
# * :numpad2
|
|
240
|
+
# * :numpad3
|
|
241
|
+
# * :numpad4
|
|
242
|
+
# * :numpad5
|
|
243
|
+
# * :numpad6
|
|
244
|
+
# * :numpad7
|
|
245
|
+
# * :numpad8
|
|
246
|
+
# * :numpad9
|
|
247
|
+
# * :multiply - numeric keypad *
|
|
248
|
+
# * :add - numeric keypad +
|
|
249
|
+
# * :separator - numeric keypad 'separator' key ??
|
|
250
|
+
# * :subtract - numeric keypad -
|
|
251
|
+
# * :decimal - numeric keypad .
|
|
252
|
+
# * :divide - numeric keypad /
|
|
253
|
+
# * :f1
|
|
254
|
+
# * :f2
|
|
255
|
+
# * :f3
|
|
256
|
+
# * :f4
|
|
257
|
+
# * :f5
|
|
258
|
+
# * :f6
|
|
259
|
+
# * :f7
|
|
260
|
+
# * :f8
|
|
261
|
+
# * :f9
|
|
262
|
+
# * :f10
|
|
263
|
+
# * :f11
|
|
264
|
+
# * :f12
|
|
265
|
+
# * :meta
|
|
266
|
+
# * :command - alias of :meta
|
|
256
267
|
#
|
|
257
268
|
# @return [Capybara::Node::Element] The element
|
|
258
269
|
def send_keys(*args)
|
|
@@ -262,7 +273,7 @@ module Capybara
|
|
|
262
273
|
|
|
263
274
|
##
|
|
264
275
|
#
|
|
265
|
-
# Hover on the Element
|
|
276
|
+
# Hover on the Element.
|
|
266
277
|
#
|
|
267
278
|
# @return [Capybara::Node::Element] The element
|
|
268
279
|
def hover
|
|
@@ -276,7 +287,7 @@ module Capybara
|
|
|
276
287
|
#
|
|
277
288
|
def tag_name
|
|
278
289
|
# Element type is immutable so cache it
|
|
279
|
-
@tag_name ||= synchronize { base.tag_name }
|
|
290
|
+
@tag_name ||= initial_cache[:tag_name] || synchronize { base.tag_name }
|
|
280
291
|
end
|
|
281
292
|
|
|
282
293
|
##
|
|
@@ -353,7 +364,7 @@ module Capybara
|
|
|
353
364
|
|
|
354
365
|
##
|
|
355
366
|
#
|
|
356
|
-
# An XPath expression describing where on the page the element can be found
|
|
367
|
+
# An XPath expression describing where on the page the element can be found.
|
|
357
368
|
#
|
|
358
369
|
# @return [String] An XPath expression
|
|
359
370
|
#
|
|
@@ -394,17 +405,41 @@ module Capybara
|
|
|
394
405
|
|
|
395
406
|
##
|
|
396
407
|
#
|
|
397
|
-
#
|
|
408
|
+
# Drop items on the current element.
|
|
409
|
+
#
|
|
410
|
+
# target = page.find('#foo')
|
|
411
|
+
# target.drop('/some/path/file.csv')
|
|
412
|
+
#
|
|
413
|
+
# @overload drop(path, ...)
|
|
414
|
+
# @param [String, #to_path] path Location of the file to drop on the element
|
|
415
|
+
#
|
|
416
|
+
# @overload drop(strings, ...)
|
|
417
|
+
# @param [Hash] strings A hash of type to data to be dropped - `{ "text/url" => "https://www.google.com" }`
|
|
418
|
+
#
|
|
419
|
+
# @return [Capybara::Node::Element] The element
|
|
420
|
+
def drop(*args)
|
|
421
|
+
options = args.map do |arg|
|
|
422
|
+
return arg.to_path if arg.respond_to?(:to_path)
|
|
423
|
+
|
|
424
|
+
arg
|
|
425
|
+
end
|
|
426
|
+
synchronize { base.drop(*options) }
|
|
427
|
+
self
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
##
|
|
431
|
+
#
|
|
432
|
+
# Scroll the page or element.
|
|
398
433
|
#
|
|
399
|
-
# Scroll the page or element to its top, bottom or middle
|
|
400
434
|
# @overload scroll_to(position, offset: [0,0])
|
|
435
|
+
# Scroll the page or element to its top, bottom or middle.
|
|
401
436
|
# @param [:top, :bottom, :center, :current] position
|
|
402
|
-
# @param
|
|
437
|
+
# @param [[Integer, Integer]] offset
|
|
403
438
|
#
|
|
404
|
-
# Scroll the page or current element until the given element is aligned at the top, bottom, or center of it
|
|
405
439
|
# @overload scroll_to(element, align: :top)
|
|
440
|
+
# Scroll the page or current element until the given element is aligned at the top, bottom, or center of it.
|
|
406
441
|
# @param [Capybara::Node::Element] element The element to be scrolled into view
|
|
407
|
-
# @param [:top, :bottom, :center]
|
|
442
|
+
# @param [:top, :bottom, :center] align Where to align the element being scrolled into view with relation to the current page/element if possible
|
|
408
443
|
#
|
|
409
444
|
# @overload scroll_to(x,y)
|
|
410
445
|
# @param [Integer] x Horizontal scroll offset
|
|
@@ -427,11 +462,11 @@ module Capybara
|
|
|
427
462
|
##
|
|
428
463
|
#
|
|
429
464
|
# Execute the given JS in the context of the element not returning a result. This is useful for scripts that return
|
|
430
|
-
# complex objects, such as jQuery statements.
|
|
431
|
-
#
|
|
465
|
+
# complex objects, such as jQuery statements. {#execute_script} should be used over
|
|
466
|
+
# {#evaluate_script} whenever a result is not expected or needed. `this` in the script will refer to the element this is called on.
|
|
432
467
|
#
|
|
433
468
|
# @param [String] script A string of JavaScript to execute
|
|
434
|
-
# @param args Optional arguments that will be passed to the script.
|
|
469
|
+
# @param args Optional arguments that will be passed to the script. Driver support for this is optional and types of objects supported may differ between drivers
|
|
435
470
|
#
|
|
436
471
|
def execute_script(script, *args)
|
|
437
472
|
session.execute_script(<<~JS, self, *args)
|
|
@@ -444,7 +479,7 @@ module Capybara
|
|
|
444
479
|
##
|
|
445
480
|
#
|
|
446
481
|
# Evaluate the given JS in the context of the element and return the result. Be careful when using this with
|
|
447
|
-
# scripts that return complex objects, such as jQuery statements.
|
|
482
|
+
# scripts that return complex objects, such as jQuery statements. {#execute_script} might
|
|
448
483
|
# be a better alternative. `this` in the script will refer to the element this is called on.
|
|
449
484
|
#
|
|
450
485
|
# @param [String] script A string of JavaScript to evaluate
|
|
@@ -462,7 +497,7 @@ module Capybara
|
|
|
462
497
|
#
|
|
463
498
|
# Evaluate the given JavaScript in the context of the element and obtain the result from a
|
|
464
499
|
# callback function which will be passed as the last argument to the script. `this` in the
|
|
465
|
-
# script will refer to the element this is called on
|
|
500
|
+
# script will refer to the element this is called on.
|
|
466
501
|
#
|
|
467
502
|
# @param [String] script A string of JavaScript to evaluate
|
|
468
503
|
# @return [Object] The result of the evaluated JavaScript (may be driver specific)
|
|
@@ -475,6 +510,7 @@ module Capybara
|
|
|
475
510
|
JS
|
|
476
511
|
end
|
|
477
512
|
|
|
513
|
+
# @api private
|
|
478
514
|
def reload
|
|
479
515
|
if @allow_reload
|
|
480
516
|
begin
|
|
@@ -487,6 +523,11 @@ module Capybara
|
|
|
487
523
|
self
|
|
488
524
|
end
|
|
489
525
|
|
|
526
|
+
##
|
|
527
|
+
#
|
|
528
|
+
# A human-readable representation of the element.
|
|
529
|
+
#
|
|
530
|
+
# @return [String] A string representation
|
|
490
531
|
def inspect
|
|
491
532
|
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
|
492
533
|
rescue NotSupportedByDriverError
|
|
@@ -5,26 +5,25 @@ module Capybara
|
|
|
5
5
|
module Finders
|
|
6
6
|
##
|
|
7
7
|
#
|
|
8
|
-
# Find an {Capybara::Node::Element} based on the given arguments.
|
|
8
|
+
# Find an {Capybara::Node::Element} based on the given arguments. {#find} will raise an error if the element
|
|
9
9
|
# is not found.
|
|
10
10
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# expires. The length of time +find+ will wait is controlled through {Capybara.default_max_wait_time}
|
|
15
|
-
# and defaults to 2 seconds.
|
|
16
|
-
# @option options [false, true, Numeric] wait (Capybara.default_max_wait_time) Maximum time to wait for matching element to appear.
|
|
11
|
+
# page.find('#foo').find('.bar')
|
|
12
|
+
# page.find(:xpath, './/div[contains(., "bar")]')
|
|
13
|
+
# page.find('li', text: 'Quox').click_link('Delete')
|
|
17
14
|
#
|
|
18
|
-
#
|
|
19
|
-
# page.find(:xpath, './/div[contains(., "bar")]')
|
|
20
|
-
# page.find('li', text: 'Quox').click_link('Delete')
|
|
15
|
+
# @param (see #all)
|
|
21
16
|
#
|
|
22
|
-
# @
|
|
17
|
+
# @macro waiting_behavior
|
|
23
18
|
#
|
|
24
19
|
# @!macro system_filters
|
|
25
20
|
# @option options [String, Regexp] text Only find elements which contain this text or match this regexp
|
|
26
|
-
# @option options [String, Boolean] exact_text
|
|
27
|
-
#
|
|
21
|
+
# @option options [String, Boolean] exact_text
|
|
22
|
+
# When String the elements contained text must match exactly, when Boolean controls whether the `text` option must match exactly.
|
|
23
|
+
# Defaults to {Capybara.configure exact_text}.
|
|
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.
|
|
26
|
+
# Defaults to {Capybara.configure default_normalize_ws}.
|
|
28
27
|
# @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
|
|
29
28
|
# * true - only finds visible elements.
|
|
30
29
|
# * false - finds invisible _and_ visible elements.
|
|
@@ -36,12 +35,14 @@ module Capybara
|
|
|
36
35
|
# * false - only find elements whose centerpoint is in the viewport and is not obscured by other non-descendant elements.
|
|
37
36
|
# @option options [String, Regexp] id Only find elements with an id that matches the value passed
|
|
38
37
|
# @option options [String, Array<String>, Regexp] class Only find elements with matching class/classes.
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
38
|
+
# * Absence of a class can be checked by prefixing the class name with `!`
|
|
39
|
+
# * If you need to check for existence of a class name that starts with `!` then prefix with `!!`
|
|
40
|
+
#
|
|
41
|
+
# class:['a', '!b', '!!!c'] # limit to elements with class 'a' and '!c' but not class 'b'
|
|
42
|
+
#
|
|
42
43
|
# @option options [String, Regexp, Hash] style Only find elements with matching style. String and Regexp will be checked against text of the elements `style` attribute, while a Hash will be compared against the elements full style
|
|
43
|
-
# @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially
|
|
44
|
-
#
|
|
44
|
+
# @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially. Defaults to {Capybara.configure exact}.
|
|
45
|
+
# @option options [Symbol] match The matching strategy to use. Defaults to {Capybara.configure match}.
|
|
45
46
|
#
|
|
46
47
|
# @return [Capybara::Node::Element] The found element
|
|
47
48
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
|
@@ -53,21 +54,19 @@ module Capybara
|
|
|
53
54
|
|
|
54
55
|
##
|
|
55
56
|
#
|
|
56
|
-
# Find an {Capybara::Node::Element} based on the given arguments that is also an ancestor of the element called on.
|
|
57
|
-
# is not found.
|
|
57
|
+
# Find an {Capybara::Node::Element} based on the given arguments that is also an ancestor of the element called on.
|
|
58
|
+
# {#ancestor} will raise an error if the element is not found.
|
|
58
59
|
#
|
|
59
|
-
#
|
|
60
|
+
# {#ancestor} takes the same options as {#find}.
|
|
60
61
|
#
|
|
61
62
|
# element.ancestor('#foo').find('.bar')
|
|
62
63
|
# element.ancestor(:xpath, './/div[contains(., "bar")]')
|
|
63
64
|
# element.ancestor('ul', text: 'Quox').click_link('Delete')
|
|
64
65
|
#
|
|
65
|
-
# @param (see
|
|
66
|
+
# @param (see #find)
|
|
66
67
|
#
|
|
67
68
|
# @macro waiting_behavior
|
|
68
69
|
#
|
|
69
|
-
# @option options [Symbol] match The matching strategy to use.
|
|
70
|
-
#
|
|
71
70
|
# @return [Capybara::Node::Element] The found element
|
|
72
71
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
|
73
72
|
#
|
|
@@ -78,22 +77,19 @@ module Capybara
|
|
|
78
77
|
|
|
79
78
|
##
|
|
80
79
|
#
|
|
81
|
-
# Find an {Capybara::Node::Element} based on the given arguments that is also a sibling of the element called on.
|
|
82
|
-
# is not found.
|
|
83
|
-
#
|
|
80
|
+
# Find an {Capybara::Node::Element} based on the given arguments that is also a sibling of the element called on.
|
|
81
|
+
# {#sibling} will raise an error if the element is not found.
|
|
84
82
|
#
|
|
85
|
-
#
|
|
83
|
+
# {#sibling} takes the same options as {#find}.
|
|
86
84
|
#
|
|
87
85
|
# element.sibling('#foo').find('.bar')
|
|
88
86
|
# element.sibling(:xpath, './/div[contains(., "bar")]')
|
|
89
87
|
# element.sibling('ul', text: 'Quox').click_link('Delete')
|
|
90
88
|
#
|
|
91
|
-
# @param (see
|
|
89
|
+
# @param (see #find)
|
|
92
90
|
#
|
|
93
91
|
# @macro waiting_behavior
|
|
94
92
|
#
|
|
95
|
-
# @option options [Symbol] match The matching strategy to use.
|
|
96
|
-
#
|
|
97
93
|
# @return [Capybara::Node::Element] The found element
|
|
98
94
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
|
99
95
|
#
|
|
@@ -107,7 +103,7 @@ module Capybara
|
|
|
107
103
|
# Find a form field on the page. The field can be found by its name, id or label text.
|
|
108
104
|
#
|
|
109
105
|
# @overload find_field([locator], **options)
|
|
110
|
-
# @param [String] locator name, id, Capybara.test_id attribute, placeholder or text of associated label element
|
|
106
|
+
# @param [String] locator name, id, {Capybara.configure test_id} attribute, placeholder or text of associated label element
|
|
111
107
|
#
|
|
112
108
|
# @macro waiting_behavior
|
|
113
109
|
#
|
|
@@ -122,13 +118,12 @@ module Capybara
|
|
|
122
118
|
# @option options [String, Regexp] with Value of field to match on
|
|
123
119
|
# @option options [String] type Type of field to match on
|
|
124
120
|
# @option options [Boolean] multiple Match fields that can have multiple values?
|
|
125
|
-
# @option options [String, Regexp] id
|
|
121
|
+
# @option options [String, Regexp] id Match fields that match the id attribute
|
|
126
122
|
# @option options [String] name Match fields that match the name attribute
|
|
127
123
|
# @option options [String] placeholder Match fields that match the placeholder attribute
|
|
128
124
|
# @option options [String, Array<String>, Regexp] class Match fields that match the class(es) passed
|
|
129
125
|
# @return [Capybara::Node::Element] The found element
|
|
130
126
|
#
|
|
131
|
-
|
|
132
127
|
def find_field(locator = nil, **options, &optional_filter_block)
|
|
133
128
|
find(:field, locator, options, &optional_filter_block)
|
|
134
129
|
end
|
|
@@ -138,12 +133,12 @@ module Capybara
|
|
|
138
133
|
# Find a link on the page. The link can be found by its id or text.
|
|
139
134
|
#
|
|
140
135
|
# @overload find_link([locator], **options)
|
|
141
|
-
# @param [String] locator id, Capybara.test_id attribute, title, text, or alt of enclosed img element
|
|
136
|
+
# @param [String] locator id, {Capybara.configure test_id} attribute, title, text, or alt of enclosed img element
|
|
142
137
|
#
|
|
143
138
|
# @macro waiting_behavior
|
|
144
139
|
#
|
|
145
|
-
# @option options [String,Regexp,nil] href
|
|
146
|
-
# @option options [String, Regexp] id
|
|
140
|
+
# @option options [String,Regexp,nil] href Value to match against the links href, if `nil` finds link placeholders (`<a>` elements with no href attribute), if `false` ignores the href
|
|
141
|
+
# @option options [String, Regexp] id Match links with the id provided
|
|
147
142
|
# @option options [String] title Match links with the title provided
|
|
148
143
|
# @option options [String] alt Match links with a contained img element whose alt matches
|
|
149
144
|
# @option options [String, Array<String>, Regexp] class Match links that match the class(es) provided
|
|
@@ -156,14 +151,12 @@ module Capybara
|
|
|
156
151
|
##
|
|
157
152
|
#
|
|
158
153
|
# Find a button on the page.
|
|
159
|
-
# This can be any
|
|
160
|
-
#
|
|
161
|
-
# by their text content, and image
|
|
154
|
+
# This can be any `<input>` element of type submit, reset, image, button or it can be a
|
|
155
|
+
# `<button>` element. All buttons can be found by their id, name, {Capybara.configure test_id} attribute, value, or title.
|
|
156
|
+
# `<button>` elements can also be found by their text content, and image `<input>` elements by their alt attribute.
|
|
162
157
|
#
|
|
163
158
|
# @overload find_button([locator], **options)
|
|
164
|
-
# @param [String] locator id, name, Capybara.test_id attribute, value, title, text content, alt of image
|
|
165
|
-
#
|
|
166
|
-
# @overload find_button(**options)
|
|
159
|
+
# @param [String] locator id, name, {Capybara.configure test_id} attribute, value, title, text content, alt of image
|
|
167
160
|
#
|
|
168
161
|
# @macro waiting_behavior
|
|
169
162
|
#
|
|
@@ -209,9 +202,8 @@ module Capybara
|
|
|
209
202
|
# page.all(:css, 'a#person_123')
|
|
210
203
|
# page.all(:xpath, './/a[@id="person_123"]')
|
|
211
204
|
#
|
|
212
|
-
#
|
|
213
205
|
# If the type of selector is left out, Capybara uses
|
|
214
|
-
# {Capybara.default_selector}. It's set to
|
|
206
|
+
# {Capybara.configure default_selector}. It's set to `:css` by default.
|
|
215
207
|
#
|
|
216
208
|
# page.all("a#person_123")
|
|
217
209
|
#
|
|
@@ -224,28 +216,25 @@ module Capybara
|
|
|
224
216
|
# page.all('a', text: 'Home')
|
|
225
217
|
# page.all('#menu li', visible: true)
|
|
226
218
|
#
|
|
227
|
-
# By default Capybara's waiting behavior will wait up to
|
|
219
|
+
# By default Capybara's waiting behavior will wait up to {Capybara.configure default_max_wait_time}
|
|
228
220
|
# seconds for matching elements to be available and then return an empty result if none
|
|
229
221
|
# are available. It is possible to set expectations on the number of results located and
|
|
230
222
|
# Capybara will raise an exception if the number of elements located don't satisfy the
|
|
231
|
-
# specified conditions.
|
|
223
|
+
# specified conditions. The expectations can be set using:
|
|
232
224
|
#
|
|
233
225
|
# page.assert_selector('p#foo', count: 4)
|
|
234
226
|
# page.assert_selector('p#foo', maximum: 10)
|
|
235
227
|
# page.assert_selector('p#foo', minimum: 1)
|
|
236
228
|
# page.assert_selector('p#foo', between: 1..10)
|
|
237
229
|
#
|
|
238
|
-
#
|
|
239
|
-
# count matching.
|
|
240
|
-
#
|
|
241
|
-
# @param [Symbol] kind Optional selector type (:css, :xpath, :field, etc.) - Defaults to Capybara.default_selector
|
|
230
|
+
# @param [Symbol] kind Optional selector type (:css, :xpath, :field, etc.). Defaults to {Capybara.configure default_selector}.
|
|
242
231
|
# @param [String] locator The locator for the specified selector
|
|
243
232
|
# @macro system_filters
|
|
233
|
+
# @macro waiting_behavior
|
|
244
234
|
# @option options [Integer] count Exact number of matches that are expected to be found
|
|
245
235
|
# @option options [Integer] maximum Maximum number of matches that are expected to be found
|
|
246
236
|
# @option options [Integer] minimum Minimum number of matches that are expected to be found
|
|
247
237
|
# @option options [Range] between Number of matches found must be within the given range
|
|
248
|
-
# @option options [false, true, Numeric] wait (Capybara.default_max_wait_time) Maximum time to wait for matching element to appear.
|
|
249
238
|
# @overload all([kind = Capybara.default_selector], locator = nil, **options)
|
|
250
239
|
# @overload all([kind = Capybara.default_selector], locator = nil, **options, &filter_block)
|
|
251
240
|
# @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
|
|
@@ -276,7 +265,7 @@ module Capybara
|
|
|
276
265
|
##
|
|
277
266
|
#
|
|
278
267
|
# Find the first element on the page matching the given selector
|
|
279
|
-
# and options. By default
|
|
268
|
+
# and options. By default {#first} will wait up to {Capybara.configure default_max_wait_time}
|
|
280
269
|
# seconds for matching elements to appear and then raise an error if no matching
|
|
281
270
|
# element is found, or `nil` if the provided count options allow for empty results.
|
|
282
271
|
#
|