capybara 3.20.2 → 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c90b3d75d32ab14dc3dba7f6617938c7b6c716c7709cd8c36c40c5e72ccc7ec
4
- data.tar.gz: c14e027664dba55e9c697f13aad46406250e39f67dcc5372b1b73370683b63ff
3
+ metadata.gz: 260a1571a7fde6676b4d901b75e17035cd5c1b32b92f6c647e9d8ceadc78ae2a
4
+ data.tar.gz: d05339eac382154edea4059cf658c7cd828a75bd8b4570b9e85819f1641fad38
5
5
  SHA512:
6
- metadata.gz: 6ce927bbbb10d21cb51c4393775e8245b845ce819868963c8930f5f03d00655399036e1ae344df4e942102a690a98b57fcdecb95e05c14b22018818bcf7e2050
7
- data.tar.gz: 332ac0bb550bdca14abe803b318cefff6b1df15eb021a67d3eff790c975be5f581ab9d19b1ebb501c98be3528c523ea6ee8e7df7e3fda2f85bf98b910520604e
6
+ metadata.gz: ffb2ebe0f747c4519d50138f4575f07c4171b1d2bfaa978dab3f471cac9cf839e0e570b8c25b76185530960d6da42dcdb9a6f45c9ed50ebd605c5cf4da2a4da4
7
+ data.tar.gz: 24c034c08f20d051256444c46bb86e0ab8c8468c34e45e27bf95408074ffe1c305603d0034348582d6b719af36a08f3f88365ddcd0336ba14e8216de854034ef
data/History.md CHANGED
@@ -1,3 +1,17 @@
1
+ # Version 3.21.0
2
+ Release date: 2019-05-24
3
+
4
+ ### Added
5
+
6
+ * Element#drop - Chrome and Firefox, via the selenium driver, support dropping files/data on elements
7
+ * Default CSS used for `attach_file` `make_visible: true` now includes auto for
8
+ height and width to handle more ways of hiding the file input element
9
+ * Documentation Updates and Fixes - Many thanks to Masafumi Koba! [Masafumi Koba]
10
+
11
+ ### Changed
12
+
13
+ * Deprecate support for CSS locator being a Symbol
14
+
1
15
  # Version 3.20.2
2
16
  Release date: 2019-05-19
3
17
 
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jnicklas/capybara?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=capybara&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=capybara&package-manager=bundler&version-scheme=semver)
9
9
 
10
- **Note** You are viewing the README for the 3.20.x version of Capybara.
10
+ **Note** You are viewing the README for the 3.21.x version of Capybara.
11
11
 
12
12
 
13
13
  Capybara helps you test web applications by simulating how a real user would
@@ -38,8 +38,6 @@ GitHub): http://groups.google.com/group/ruby-capybara
38
38
  - [RackTest](#racktest)
39
39
  - [Selenium](#selenium)
40
40
  - [Apparition](#apparition)
41
- - [Capybara-webkit](#capybara-webkit)
42
- - [Poltergeist](#poltergeist)
43
41
  - [The DSL](#the-dsl)
44
42
  - [Navigating](#navigating)
45
43
  - [Clicking links and buttons](#clicking-links-and-buttons)
@@ -59,11 +57,13 @@ GitHub): http://groups.google.com/group/ruby-capybara
59
57
  - [Using the DSL elsewhere](#using-the-dsl-elsewhere)
60
58
  - [Calling remote servers](#calling-remote-servers)
61
59
  - [Using sessions](#using-sessions)
60
+ - [Named sessions](#named-sessions)
61
+ - [Using sessions manually](#using-sessions-manually)
62
62
  - [XPath, CSS and selectors](#xpath-css-and-selectors)
63
63
  - [Beware the XPath // trap](#beware-the-xpath--trap)
64
64
  - [Configuring and adding drivers](#configuring-and-adding-drivers)
65
65
  - [Gotchas:](#gotchas)
66
- - ["Threadsafe" mode](#threadsafe)
66
+ - ["Threadsafe" mode](#threadsafe-mode)
67
67
  - [Development](#development)
68
68
 
69
69
  ## <a name="key-benefits"></a>Key benefits
@@ -73,22 +73,24 @@ module Capybara
73
73
  # [asset_host = String] Where dynamic assets are hosted - will be prepended to relative asset locations if present (Default: nil)
74
74
  # [run_server = Boolean] Whether to start a Rack server for the given Rack app (Default: true)
75
75
  # [raise_server_errors = Boolean] Should errors raised in the server be raised in the tests? (Default: true)
76
- # [server_errors = Array\<Class\>] Error classes that should be raised in the tests if they are raised in the server and Capybara.raise_server_errors is true (Default: [Exception])
76
+ # [server_errors = Array\<Class\>] Error classes that should be raised in the tests if they are raised in the server and {configure raise_server_errors} is true (Default: [Exception])
77
77
  # [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: :css)
78
78
  # [default_max_wait_time = Numeric] The maximum number of seconds to wait for asynchronous processes to finish (Default: 2)
79
79
  # [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: true)
80
80
  # [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
81
81
  # [save_path = String] Where to put pages saved through save_(page|screenshot), save_and_open_(page|screenshot) (Default: Dir.pwd)
82
- # [automatic_label_click = Boolean] Whether Node#choose, Node#check, Node#uncheck will attempt to click the associated label element if the checkbox/radio button are non-visible (Default: false)
82
+ # [automatic_label_click = Boolean] Whether {Capybara::Node::Element#choose Element#choose}, {Capybara::Node::Element#check Element#check}, {Capybara::Node::Element#uncheck Element#uncheck} will attempt to click the associated label element if the checkbox/radio button are non-visible (Default: false)
83
83
  # [enable_aria_label = Boolean] Whether fields, links, and buttons will match against aria-label attribute (Default: false)
84
84
  # [reuse_server = Boolean] Reuse the server thread between multiple sessions using the same app object (Default: true)
85
85
  # [threadsafe = Boolean] Whether sessions can be configured individually (Default: false)
86
- # [server = Symbol] The name of the registered server to use when running the app under test (Default: :webrick)
87
- # [default_set_options = Hash] The default options passed to Node::set (Default: {})
86
+ # [server = Symbol] The name of the registered server to use when running the app under test (Default: :default which uses puma)
87
+ # [default_set_options = Hash] The default options passed to {Capybara::Node::Element#set Element#set} (Default: {})
88
88
  # [test_id = Symbol/String/nil] Optional attribute to match locator aginst with builtin selectors along with id (Default: nil)
89
- # [predicates_wait = Boolean] Whether Capybaras predicate matchers use waiting behavior by default (Default: true)
89
+ # [predicates_wait = Boolean] Whether Capybara's predicate matchers use waiting behavior by default (Default: true)
90
90
  # [default_normalize_ws = Boolean] Whether text predicates and matchers use normalize whitespace behaviour (Default: false)
91
91
  # [allow_gumbo = Boolean] When `nokogumbo` is available, whether it will be used to parse HTML strings (Default: false)
92
+ # [match = :one/:first/:prefer_exact/:smart] The matching strategy to find nodes (Default: :smart)
93
+ # [exact_text = Boolean] Whether the text matchers and `:text` filter match exactly or on substrings (Default: false)
92
94
  #
93
95
  # === DSL Options
94
96
  #
@@ -201,15 +203,13 @@ module Capybara
201
203
  # any string containing HTML in the exact same way you would query the current document in a Capybara
202
204
  # session.
203
205
  #
204
- # Example: A single element
205
- #
206
+ # @example A single element
206
207
  # node = Capybara.string('<a href="foo">bar</a>')
207
208
  # anchor = node.first('a')
208
209
  # anchor[:href] #=> 'foo'
209
210
  # anchor.text #=> 'bar'
210
211
  #
211
- # Example: Multiple elements
212
- #
212
+ # @example Multiple elements
213
213
  # node = Capybara.string <<-HTML
214
214
  # <ul>
215
215
  # <li id="home">Home</li>
@@ -297,7 +297,7 @@ module Capybara
297
297
 
298
298
  ##
299
299
  #
300
- # The current Capybara::Session based on what is set as Capybara.app and Capybara.current_driver
300
+ # The current {Capybara::Session} based on what is set as {app} and {current_driver}.
301
301
  #
302
302
  # @return [Capybara::Session] The currently used session
303
303
  #
@@ -340,7 +340,7 @@ module Capybara
340
340
 
341
341
  ##
342
342
  #
343
- # Yield a block using a specific session name or Capybara::Session instance.
343
+ # Yield a block using a specific session name or {Capybara::Session} instance.
344
344
  #
345
345
  def using_session(name_or_session)
346
346
  previous_session_info = {
@@ -69,6 +69,10 @@ module Capybara
69
69
  raise NotImplementedError
70
70
  end
71
71
 
72
+ def drop(*args)
73
+ raise NotImplementedError
74
+ end
75
+
72
76
  def scroll_by(x, y)
73
77
  raise NotImplementedError
74
78
  end
@@ -41,7 +41,7 @@ module Capybara
41
41
  ##
42
42
  #
43
43
  # Injects a `<base>` tag into the given HTML code, pointing to
44
- # `Capybara.asset_host`.
44
+ # {Capybara.configure asset_host}.
45
45
  #
46
46
  # @param [String] html HTML code to inject into
47
47
  # @param [URL] host (Capybara.asset_host) The host from which assets should be loaded
@@ -150,27 +150,27 @@ module Capybara
150
150
  # Assertion that there is xpath
151
151
  #
152
152
  # @!method assert_xpath
153
- # see Capybara::Node::Matchers#has_xpath?
153
+ # see {Capybara::Node::Matchers#has_xpath?}
154
154
 
155
155
  ##
156
156
  # Assertion that there is no xpath
157
157
  #
158
158
  # @!method refute_xpath
159
159
  # @!method assert_no_xpath
160
- # see Capybara::Node::Matchers#has_no_xpath?
160
+ # see {Capybara::Node::Matchers#has_no_xpath?}
161
161
 
162
162
  ##
163
163
  # Assertion that there is css
164
164
  #
165
165
  # @!method assert_css
166
- # see Capybara::Node::Matchers#has_css?
166
+ # see {Capybara::Node::Matchers#has_css?}
167
167
 
168
168
  ##
169
169
  # Assertion that there is no css
170
170
  #
171
171
  # @!method refute_css
172
172
  # @!method assert_no_css
173
- # see Capybara::Node::Matchers#has_no_css?
173
+ # see {Capybara::Node::Matchers#has_no_css?}
174
174
 
175
175
  ##
176
176
  # Assertion that there is link
@@ -6,18 +6,19 @@ module Capybara
6
6
  # @!macro waiting_behavior
7
7
  # If the driver is capable of executing JavaScript, this method will wait for a set amount of time
8
8
  # and continuously retry finding the element until either the element is found or the time
9
- # expires. The length of time +find+ will wait is controlled through {Capybara.default_max_wait_time}
9
+ # expires. The length of time this method will wait is controlled through {Capybara.configure default_max_wait_time}.
10
10
  #
11
- # @option options [false, true, Numeric] wait (Capybara.default_max_wait_time) Maximum time to wait for matching element to appear.
11
+ # @option options [false, true, Numeric] wait
12
+ # Maximum time to wait for matching element to appear. Defaults to {Capybara.configure default_max_wait_time}.
12
13
 
13
14
  ##
14
15
  #
15
- # Finds a button or link and clicks it. See {Capybara::Node::Actions#click_button} and
16
- # {Capybara::Node::Actions#click_link} for what locator will match against for each type of element
16
+ # Finds a button or link and clicks it. See {#click_button} and
17
+ # {#click_link} for what locator will match against for each type of element.
17
18
  #
18
19
  # @overload click_link_or_button([locator], **options)
19
20
  # @macro waiting_behavior
20
- # @param [String] locator See {Capybara::Node::Actions#click_button} and {Capybara::Node::Actions#click_link}
21
+ # @param [String] locator See {#click_button} and {#click_link}
21
22
  #
22
23
  # @return [Capybara::Node::Element] The element clicked
23
24
  #
@@ -28,13 +29,13 @@ module Capybara
28
29
 
29
30
  ##
30
31
  #
31
- # Finds a link by id, Capybara.test_id attribute, text or title and clicks it. Also looks at image
32
+ # Finds a link by id, {Capybara.configure test_id} attribute, text or title and clicks it. Also looks at image
32
33
  # alt text inside the link.
33
34
  #
34
35
  # @overload click_link([locator], **options)
35
36
  # @macro waiting_behavior
36
- # @param [String] locator text, id, Capybara.test_id attribute, title or nested image's alt attribute
37
- # @param options See {Capybara::Node::Finders#find_link}
37
+ # @param [String] locator text, id, {Capybara.configure test_id} attribute, title or nested image's alt attribute
38
+ # @param [Hash] options See {Capybara::Node::Finders#find_link}
38
39
  #
39
40
  # @return [Capybara::Node::Element] The element clicked
40
41
  def click_link(locator = nil, **options)
@@ -44,14 +45,14 @@ module Capybara
44
45
  ##
45
46
  #
46
47
  # Finds a button on the page and clicks it.
47
- # This can be any \<input> element of type submit, reset, image, button or it can be a
48
- # \<button> element. All buttons can be found by their id, name, Capybara.test_id attribute, value, or title. \<button> elements can also be found
49
- # by their text content, and image \<input> elements by their alt attribute
48
+ # This can be any `<input>` element of type submit, reset, image, button or it can be a
49
+ # `<button>` element. All buttons can be found by their id, name, {Capybara.configure test_id} attribute, value, or title. `<button>` elements can also be found
50
+ # by their text content, and image `<input>` elements by their alt attribute.
50
51
  #
51
52
  # @overload click_button([locator], **options)
52
53
  # @macro waiting_behavior
53
54
  # @param [String] locator Which button to find
54
- # @param options See {Capybara::Node::Finders#find_button}
55
+ # @param [Hash] options See {Capybara::Node::Finders#find_button}
55
56
  # @return [Capybara::Node::Element] The element clicked
56
57
  def click_button(locator = nil, **options)
57
58
  find(:button, locator, options).click
@@ -59,9 +60,9 @@ module Capybara
59
60
 
60
61
  ##
61
62
  #
62
- # Locate a text field or text area and fill it in with the given text
63
- # The field can be found via its name, id, Capybara.test_id attribute, or label text.
64
- # If no locator is provided will operate on self or a descendant
63
+ # Locate a text field or text area and fill it in with the given text.
64
+ # The field can be found via its name, id, {Capybara.configure test_id} attribute, or label text.
65
+ # If no locator is provided this will operate on self or a descendant.
65
66
  #
66
67
  # # will fill in a descendant fillable field with name, id, or label text matching 'Name'
67
68
  # page.fill_in 'Name', with: 'Bob'
@@ -73,7 +74,7 @@ module Capybara
73
74
  # @overload fill_in([locator], with:, **options)
74
75
  # @param [String] locator Which field to fill in
75
76
  # @param [Hash] options
76
- # @param with: [String] The value to fill_in
77
+ # @param with: [String] The value to fill in
77
78
  # @macro waiting_behavior
78
79
  # @option options [String] currently_with The current value property of the field to fill in
79
80
  # @option options [Boolean] multiple Match fields that can have multiple values?
@@ -81,9 +82,9 @@ module Capybara
81
82
  # @option options [String] name Match fields that match the name attribute
82
83
  # @option options [String] placeholder Match fields that match the placeholder attribute
83
84
  # @option options [String, Array<String>, Regexp] class Match fields that match the class(es) provided
84
- # @option options [Hash] fill_options Driver specific options regarding how to fill fields (Defaults come from Capybara.default_set_options)
85
+ # @option options [Hash] fill_options Driver specific options regarding how to fill fields (Defaults come from {Capybara.configure default_set_options})
85
86
  #
86
- # @return [Capybara::Node::Element] The element filled_in
87
+ # @return [Capybara::Node::Element] The element filled in
87
88
  def fill_in(locator = nil, with:, currently_with: nil, fill_options: {}, **find_options)
88
89
  find_options[:with] = currently_with if currently_with
89
90
  find_options[:allow_self] = true if locator.nil?
@@ -91,7 +92,8 @@ module Capybara
91
92
  end
92
93
 
93
94
  # @!macro label_click
94
- # @option options [Boolean] allow_label_click (Capybara.automatic_label_click) Attempt to click the label to toggle state if element is non-visible.
95
+ # @option options [Boolean] allow_label_click
96
+ # Attempt to click the label to toggle state if element is non-visible. Defaults to {Capybara.configure automatic_label_click}.
95
97
 
96
98
  ##
97
99
  #
@@ -178,10 +180,10 @@ module Capybara
178
180
 
179
181
  ##
180
182
  #
181
- # If `:from` option is present, `select` finds a select box, or text input with associated datalist,
183
+ # If `from` option is present, {#select} finds a select box, or text input with associated datalist,
182
184
  # on the page and selects a particular option from it.
183
185
  # Otherwise it finds an option inside current scope and selects it.
184
- # If the select box is a multiple select, +select+ can be called multiple times to select more than
186
+ # If the select box is a multiple select, {#select} can be called multiple times to select more than
185
187
  # one option.
186
188
  # The select box can be found via its name, id or label text. The option can be found by its text.
187
189
  #
@@ -191,7 +193,7 @@ module Capybara
191
193
  # @macro waiting_behavior
192
194
  #
193
195
  # @param value [String] Which option to select
194
- # @param from [String] The id, Capybara.test_id attribute, name or label of the select box
196
+ # @param from [String] The id, {Capybara.configure test_id} attribute, name or label of the select box
195
197
  #
196
198
  # @return [Capybara::Node::Element] The option element selected
197
199
  def select(value = nil, from: nil, **options)
@@ -209,7 +211,7 @@ module Capybara
209
211
  ##
210
212
  #
211
213
  # Find a select box on the page and unselect a particular option from it. If the select
212
- # box is a multiple select, +unselect+ can be called multiple times to unselect more than
214
+ # box is a multiple select, {#unselect} can be called multiple times to unselect more than
213
215
  # one option. The select box can be found via its name, id or label text.
214
216
  #
215
217
  # page.unselect 'March', from: 'Month'
@@ -218,7 +220,7 @@ module Capybara
218
220
  # @macro waiting_behavior
219
221
  #
220
222
  # @param value [String] Which option to unselect
221
- # @param from [String] The id, Capybara.test_id attribute, name or label of the select box
223
+ # @param from [String] The id, {Capybara.configure test_id} attribute, name or label of the select box
222
224
  #
223
225
  #
224
226
  # @return [Capybara::Node::Element] The option element unselected
@@ -232,7 +234,7 @@ module Capybara
232
234
  ##
233
235
  #
234
236
  # Find a descendant file field on the page and attach a file given its path. There are two ways to use
235
- # `attach_file`, in the first method the file field can be found via its name, id or label text.
237
+ # {#attach_file}, in the first method the file field can be found via its name, id or label text.
236
238
  # In the case of the file field being hidden for
237
239
  # styling reasons the `make_visible` option can be used to temporarily change the CSS of
238
240
  # the file field, attach the file, and then revert the CSS back to original. If no locator is
@@ -257,13 +259,16 @@ module Capybara
257
259
  # @param [String] locator Which field to attach the file to
258
260
  # @param [String, Array<String>] paths The path(s) of the file(s) that will be attached
259
261
  #
260
- # @option options [Symbol] match (Capybara.match) The matching strategy to use (:one, :first, :prefer_exact, :smart).
261
- # @option options [Boolean] exact (Capybara.exact) Match the exact label name/contents or accept a partial match.
262
+ # @option options [Symbol] match
263
+ # The matching strategy to use (:one, :first, :prefer_exact, :smart). Defaults to {Capybara.configure match}.
264
+ # @option options [Boolean] exact
265
+ # Match the exact label name/contents or accept a partial match. Defaults to {Capybara.configure exact}.
262
266
  # @option options [Boolean] multiple Match field which allows multiple file selection
263
267
  # @option options [String, Regexp] id Match fields that match the id attribute
264
268
  # @option options [String] name Match fields that match the name attribute
265
269
  # @option options [String, Array<String>, Regexp] class Match fields that match the class(es) provided
266
- # @option options [true, Hash] make_visible A Hash of CSS styles to change before attempting to attach the file, if `true` { opacity: 1, display: 'block', visibility: 'visible' } is used (may not be supported by all drivers)
270
+ # @option options [true, Hash] make_visible
271
+ # A Hash of CSS styles to change before attempting to attach the file, if `true`, `{ opacity: 1, display: 'block', visibility: 'visible' }` is used (may not be supported by all drivers).
267
272
  # @overload attach_file(paths, &blk)
268
273
  # @param [String, Array<String>] paths The path(s) of the file(s) that will be attached
269
274
  # @yield Block whose actions will trigger the system file chooser to be shown
@@ -326,7 +331,9 @@ module Capybara
326
331
  end
327
332
 
328
333
  def while_visible(element, visible_css)
329
- visible_css = { opacity: 1, display: 'block', visibility: 'visible' } if visible_css == true
334
+ if visible_css == true
335
+ visible_css = { opacity: 1, display: 'block', visibility: 'visible', width: 'auto', height: 'auto' }
336
+ end
330
337
  _update_style(element, visible_css)
331
338
  raise ExpectationNotMet, 'The style changes in :make_visible did not make the file input visible' unless element.visible?
332
339
 
@@ -43,7 +43,7 @@ module Capybara
43
43
 
44
44
  ##
45
45
  #
46
- # Retrieve the text of the element. If `Capybara.ignore_hidden_elements`
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{}] options Driver specific options for how to set the value. Take default values from `Capybara#default_set_options` - See {Capybara::configure}
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" #=> value: 'test'
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
- # Scroll the page or element
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 :offset
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] :align Where to align the element being scrolled into view with relation to the current page/element if possible
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. +execute_script+ should be used over
431
- # +evaluate_script+ whenever possible. `this` in the script will refer to the element this is called on.
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. Driver support for this is optional and types of objects supported may differ between drivers
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. +execute_script+ might
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