capybara 3.8.1 → 3.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +465 -0
- data/License.txt +1 -1
- data/README.md +58 -57
- data/lib/capybara/config.rb +10 -4
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +2 -2
- data/lib/capybara/driver/node.rb +26 -5
- data/lib/capybara/dsl.rb +12 -4
- data/lib/capybara/helpers.rb +8 -4
- data/lib/capybara/minitest/spec.rb +162 -85
- data/lib/capybara/minitest.rb +248 -148
- data/lib/capybara/node/actions.rb +149 -96
- data/lib/capybara/node/base.rb +27 -10
- data/lib/capybara/node/document.rb +12 -0
- data/lib/capybara/node/document_matchers.rb +9 -5
- data/lib/capybara/node/element.rb +254 -109
- data/lib/capybara/node/finders.rb +83 -76
- data/lib/capybara/node/matchers.rb +279 -141
- data/lib/capybara/node/simple.rb +25 -6
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +11 -5
- data/lib/capybara/queries/current_path_query.rb +3 -3
- data/lib/capybara/queries/match_query.rb +1 -0
- data/lib/capybara/queries/selector_query.rb +467 -103
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +6 -2
- data/lib/capybara/queries/text_query.rb +17 -3
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +22 -15
- data/lib/capybara/rack_test/driver.rb +10 -1
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +33 -28
- data/lib/capybara/rack_test/node.rb +74 -6
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +55 -23
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matcher_proxies.rb +36 -15
- data/lib/capybara/rspec/matchers/base.rb +111 -0
- data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
- data/lib/capybara/rspec/matchers/compound.rb +88 -0
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
- data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +33 -0
- data/lib/capybara/rspec/matchers/have_title.rb +29 -0
- data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
- data/lib/capybara/rspec/matchers/match_style.rb +38 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +117 -311
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +69 -0
- data/lib/capybara/selector/css.rb +17 -15
- data/lib/capybara/selector/definition/button.rb +52 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +27 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +54 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/definition.rb +277 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +26 -19
- data/lib/capybara/selector/filters/base.rb +24 -5
- data/lib/capybara/selector/filters/expression_filter.rb +3 -3
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -2
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +73 -367
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +221 -480
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +203 -86
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +88 -14
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +110 -0
- data/lib/capybara/selenium/extensions/html5_drag.rb +191 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +78 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +298 -93
- data/lib/capybara/selenium/nodes/chrome_node.rb +100 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +131 -0
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -3
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +4 -3
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/server.rb +30 -7
- data/lib/capybara/session/config.rb +14 -10
- data/lib/capybara/session/matchers.rb +11 -7
- data/lib/capybara/session.rb +152 -111
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +101 -10
- data/lib/capybara/spec/session/all_spec.rb +96 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +29 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_selector_spec.rb +0 -10
- data/lib/capybara/spec/session/assert_style_spec.rb +4 -4
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +63 -36
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +117 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +16 -0
- data/lib/capybara/spec/session/click_link_spec.rb +17 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +13 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +47 -6
- data/lib/capybara/spec/session/find_field_spec.rb +1 -1
- data/lib/capybara/spec/session/find_spec.rb +74 -4
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +13 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +1 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +122 -12
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +55 -0
- data/lib/capybara/spec/session/has_select_spec.rb +34 -6
- data/lib/capybara/spec/session/has_selector_spec.rb +11 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +166 -0
- data/lib/capybara/spec/session/has_text_spec.rb +48 -1
- data/lib/capybara/spec/session/has_xpath_spec.rb +17 -0
- data/lib/capybara/spec/session/html_spec.rb +7 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +643 -18
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +4 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +23 -8
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +10 -10
- data/lib/capybara/spec/session/selectors_spec.rb +36 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_spec.rb +59 -58
- data/lib/capybara/spec/session/window/windows_spec.rb +4 -0
- data/lib/capybara/spec/session/within_spec.rb +23 -0
- data/lib/capybara/spec/spec_helper.rb +16 -6
- data/lib/capybara/spec/test_app.rb +28 -23
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +48 -7
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +20 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +67 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_hover.erb +1 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +32 -6
- data/lib/capybara/spec/views/with_js.erb +3 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +11 -11
- data/lib/capybara.rb +118 -111
- data/spec/basic_node_spec.rb +14 -3
- data/spec/capybara_spec.rb +29 -29
- data/spec/css_builder_spec.rb +101 -0
- data/spec/dsl_spec.rb +46 -21
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +18 -4
- data/spec/minitest_spec_spec.rb +59 -44
- data/spec/rack_test_spec.rb +117 -89
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +51 -49
- data/spec/rspec/features_spec.rb +3 -0
- data/spec/rspec/shared_spec_matchers.rb +112 -97
- data/spec/rspec_spec.rb +35 -17
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +244 -28
- data/spec/selenium_spec_chrome.rb +125 -54
- data/spec/selenium_spec_chrome_remote.rb +26 -12
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +208 -0
- data/spec/selenium_spec_firefox_remote.rb +15 -18
- data/spec/selenium_spec_ie.rb +82 -13
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +118 -77
- data/spec/session_spec.rb +19 -3
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +110 -65
- data/spec/spec_helper.rb +57 -9
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +257 -17
- data/lib/capybara/rspec/compound.rb +0 -94
- data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -49
- data/lib/capybara/selenium/nodes/marionette_node.rb +0 -121
- data/lib/capybara/spec/session/has_style_spec.rb +0 -25
- data/spec/selenium_spec_marionette.rb +0 -172
@@ -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
|
|
@@ -43,7 +45,7 @@ module Capybara
|
|
43
45
|
|
44
46
|
##
|
45
47
|
#
|
46
|
-
# Retrieve the text of the element. If
|
48
|
+
# Retrieve the text of the element. If {Capybara.configure ignore_hidden_elements}
|
47
49
|
# is `true`, which it is by default, then this will return only text
|
48
50
|
# which is visible. The exact semantics of this may differ between
|
49
51
|
# drivers, but generally any text within elements with `display:none` is
|
@@ -61,7 +63,7 @@ module Capybara
|
|
61
63
|
|
62
64
|
##
|
63
65
|
#
|
64
|
-
# Retrieve the given attribute
|
66
|
+
# Retrieve the given attribute.
|
65
67
|
#
|
66
68
|
# element[:title] # => HTML title attribute
|
67
69
|
#
|
@@ -74,7 +76,7 @@ module Capybara
|
|
74
76
|
|
75
77
|
##
|
76
78
|
#
|
77
|
-
# Retrieve the given CSS styles
|
79
|
+
# Retrieve the given CSS styles.
|
78
80
|
#
|
79
81
|
# element.style('color', 'font-size') # => Computed values of CSS 'color' and 'font-size' styles
|
80
82
|
#
|
@@ -84,13 +86,14 @@ module Capybara
|
|
84
86
|
def style(*styles)
|
85
87
|
styles = styles.flatten.map(&:to_s)
|
86
88
|
raise ArgumentError, 'You must specify at least one CSS style' if styles.empty?
|
89
|
+
|
87
90
|
begin
|
88
91
|
synchronize { base.style(styles) }
|
89
|
-
rescue NotImplementedError =>
|
92
|
+
rescue NotImplementedError => e
|
90
93
|
begin
|
91
94
|
evaluate_script(STYLE_SCRIPT, *styles)
|
92
95
|
rescue Capybara::NotSupportedByDriverError
|
93
|
-
raise
|
96
|
+
raise e
|
94
97
|
end
|
95
98
|
end
|
96
99
|
end
|
@@ -108,78 +111,98 @@ module Capybara
|
|
108
111
|
# Set the value of the form element to the given value.
|
109
112
|
#
|
110
113
|
# @param [String] value The new value
|
111
|
-
# @param [Hash
|
114
|
+
# @param [Hash] options Driver specific options for how to set the value. Take default values from {Capybara.configure default_set_options}.
|
112
115
|
#
|
113
116
|
# @return [Capybara::Node::Element] The element
|
114
117
|
def set(value, **options)
|
115
|
-
|
118
|
+
if ENV['CAPYBARA_THOROUGH'] && readonly?
|
119
|
+
raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}"
|
120
|
+
end
|
121
|
+
|
116
122
|
options = session_options.default_set_options.to_h.merge(options)
|
117
|
-
synchronize { base.set(value, options) }
|
123
|
+
synchronize { base.set(value, **options) }
|
118
124
|
self
|
119
125
|
end
|
120
126
|
|
121
127
|
##
|
122
128
|
#
|
123
|
-
# Select this node if is an option element inside a select tag
|
129
|
+
# Select this node if it is an option element inside a select tag.
|
130
|
+
#
|
131
|
+
# @!macro action_waiting_behavior
|
132
|
+
# If the driver dynamic pages (JS) and the element is currently non-interactable, this method will
|
133
|
+
# continuously retry the action until either the element becomes interactable or the maximum
|
134
|
+
# wait time expires.
|
124
135
|
#
|
136
|
+
# @param [false, Numeric] wait
|
137
|
+
# Maximum time to wait for the action to succeed. Defaults to {Capybara.configure default_max_wait_time}.
|
125
138
|
# @return [Capybara::Node::Element] The element
|
126
|
-
def select_option
|
127
|
-
|
128
|
-
synchronize { base.select_option }
|
139
|
+
def select_option(wait: nil)
|
140
|
+
synchronize(wait) { base.select_option }
|
129
141
|
self
|
130
142
|
end
|
131
143
|
|
132
144
|
##
|
133
145
|
#
|
134
|
-
# Unselect this node if is an option element inside a multiple select tag
|
146
|
+
# Unselect this node if it is an option element inside a multiple select tag.
|
135
147
|
#
|
148
|
+
# @macro action_waiting_behavior
|
136
149
|
# @return [Capybara::Node::Element] The element
|
137
|
-
def unselect_option
|
138
|
-
synchronize { base.unselect_option }
|
150
|
+
def unselect_option(wait: nil)
|
151
|
+
synchronize(wait) { base.unselect_option }
|
139
152
|
self
|
140
153
|
end
|
141
154
|
|
142
155
|
##
|
143
156
|
#
|
144
|
-
# Click the Element
|
157
|
+
# Click the Element.
|
145
158
|
#
|
159
|
+
# @macro action_waiting_behavior
|
146
160
|
# @!macro click_modifiers
|
147
|
-
# 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
|
148
|
-
# @overload $0(*modifier_keys, **offset)
|
161
|
+
# 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.
|
162
|
+
# @overload $0(*modifier_keys, wait: nil, **offset)
|
149
163
|
# @param *modifier_keys [:alt, :control, :meta, :shift] ([]) Keys to be held down when clicking
|
150
|
-
# @option
|
151
|
-
#
|
164
|
+
# @option options [Integer] x X coordinate to offset the click location. If {Capybara.configure w3c_click_offset} is `true` the
|
165
|
+
# offset will be from the element center, otherwise it will be from the top left corner of the element
|
166
|
+
# @option options [Integer] y Y coordinate to offset the click location. If {Capybara.configure w3c_click_offset} is `true` the
|
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)
|
152
169
|
# @return [Capybara::Node::Element] The element
|
153
|
-
def click(*keys, **
|
154
|
-
|
155
|
-
|
170
|
+
def click(*keys, **options)
|
171
|
+
perform_click_action(keys, **options) do |k, opts|
|
172
|
+
base.click(k, **opts)
|
173
|
+
end
|
156
174
|
end
|
157
175
|
|
158
176
|
##
|
159
177
|
#
|
160
|
-
# Right Click the Element
|
178
|
+
# Right Click the Element.
|
161
179
|
#
|
180
|
+
# @macro action_waiting_behavior
|
162
181
|
# @macro click_modifiers
|
182
|
+
# @option options [Float] delay Delay between the mouse down and mouse up events in seconds (0)
|
163
183
|
# @return [Capybara::Node::Element] The element
|
164
|
-
def right_click(*keys, **
|
165
|
-
|
166
|
-
|
184
|
+
def right_click(*keys, **options)
|
185
|
+
perform_click_action(keys, **options) do |k, opts|
|
186
|
+
base.right_click(k, **opts)
|
187
|
+
end
|
167
188
|
end
|
168
189
|
|
169
190
|
##
|
170
191
|
#
|
171
|
-
# Double Click the Element
|
192
|
+
# Double Click the Element.
|
172
193
|
#
|
194
|
+
# @macro action_waiting_behavior
|
173
195
|
# @macro click_modifiers
|
174
196
|
# @return [Capybara::Node::Element] The element
|
175
|
-
def double_click(*keys, **
|
176
|
-
|
177
|
-
|
197
|
+
def double_click(*keys, **options)
|
198
|
+
perform_click_action(keys, **options) do |k, opts|
|
199
|
+
base.double_click(k, **opts)
|
200
|
+
end
|
178
201
|
end
|
179
202
|
|
180
203
|
##
|
181
204
|
#
|
182
|
-
# Send Keystrokes to the Element
|
205
|
+
# Send Keystrokes to the Element.
|
183
206
|
#
|
184
207
|
# @overload send_keys(keys, ...)
|
185
208
|
# @param keys [String, Symbol, Array<String,Symbol>]
|
@@ -187,65 +210,65 @@ module Capybara
|
|
187
210
|
# Examples:
|
188
211
|
#
|
189
212
|
# element.send_keys "foo" #=> value: 'foo'
|
190
|
-
# element.send_keys "tet", :left, "s"
|
213
|
+
# element.send_keys "tet", :left, "s" #=> value: 'test'
|
191
214
|
# element.send_keys [:control, 'a'], :space #=> value: ' ' - assuming ctrl-a selects all contents
|
192
215
|
#
|
193
|
-
# Symbols supported for keys
|
194
|
-
# :cancel
|
195
|
-
# :help
|
196
|
-
# :backspace
|
197
|
-
# :tab
|
198
|
-
# :clear
|
199
|
-
# :return
|
200
|
-
# :enter
|
201
|
-
# :shift
|
202
|
-
# :control
|
203
|
-
# :alt
|
204
|
-
# :pause
|
205
|
-
# :escape
|
206
|
-
# :space
|
207
|
-
# :page_up
|
208
|
-
# :page_down
|
209
|
-
# :end
|
210
|
-
# :home
|
211
|
-
# :left
|
212
|
-
# :up
|
213
|
-
# :right
|
214
|
-
# :down
|
215
|
-
# :insert
|
216
|
-
# :delete
|
217
|
-
# :semicolon
|
218
|
-
# :equals
|
219
|
-
# :numpad0
|
220
|
-
# :numpad1
|
221
|
-
# :numpad2
|
222
|
-
# :numpad3
|
223
|
-
# :numpad4
|
224
|
-
# :numpad5
|
225
|
-
# :numpad6
|
226
|
-
# :numpad7
|
227
|
-
# :numpad8
|
228
|
-
# :numpad9
|
229
|
-
# :multiply - numeric keypad *
|
230
|
-
# :add - numeric keypad +
|
231
|
-
# :separator - numeric keypad 'separator' key ??
|
232
|
-
# :subtract - numeric keypad -
|
233
|
-
# :decimal - numeric keypad .
|
234
|
-
# :divide - numeric keypad /
|
235
|
-
# :f1
|
236
|
-
# :f2
|
237
|
-
# :f3
|
238
|
-
# :f4
|
239
|
-
# :f5
|
240
|
-
# :f6
|
241
|
-
# :f7
|
242
|
-
# :f8
|
243
|
-
# :f9
|
244
|
-
# :f10
|
245
|
-
# :f11
|
246
|
-
# :f12
|
247
|
-
# :meta
|
248
|
-
# :command - alias of :meta
|
216
|
+
# Symbols supported for keys:
|
217
|
+
# * :cancel
|
218
|
+
# * :help
|
219
|
+
# * :backspace
|
220
|
+
# * :tab
|
221
|
+
# * :clear
|
222
|
+
# * :return
|
223
|
+
# * :enter
|
224
|
+
# * :shift
|
225
|
+
# * :control
|
226
|
+
# * :alt
|
227
|
+
# * :pause
|
228
|
+
# * :escape
|
229
|
+
# * :space
|
230
|
+
# * :page_up
|
231
|
+
# * :page_down
|
232
|
+
# * :end
|
233
|
+
# * :home
|
234
|
+
# * :left
|
235
|
+
# * :up
|
236
|
+
# * :right
|
237
|
+
# * :down
|
238
|
+
# * :insert
|
239
|
+
# * :delete
|
240
|
+
# * :semicolon
|
241
|
+
# * :equals
|
242
|
+
# * :numpad0
|
243
|
+
# * :numpad1
|
244
|
+
# * :numpad2
|
245
|
+
# * :numpad3
|
246
|
+
# * :numpad4
|
247
|
+
# * :numpad5
|
248
|
+
# * :numpad6
|
249
|
+
# * :numpad7
|
250
|
+
# * :numpad8
|
251
|
+
# * :numpad9
|
252
|
+
# * :multiply - numeric keypad *
|
253
|
+
# * :add - numeric keypad +
|
254
|
+
# * :separator - numeric keypad 'separator' key ??
|
255
|
+
# * :subtract - numeric keypad -
|
256
|
+
# * :decimal - numeric keypad .
|
257
|
+
# * :divide - numeric keypad /
|
258
|
+
# * :f1
|
259
|
+
# * :f2
|
260
|
+
# * :f3
|
261
|
+
# * :f4
|
262
|
+
# * :f5
|
263
|
+
# * :f6
|
264
|
+
# * :f7
|
265
|
+
# * :f8
|
266
|
+
# * :f9
|
267
|
+
# * :f10
|
268
|
+
# * :f11
|
269
|
+
# * :f12
|
270
|
+
# * :meta
|
271
|
+
# * :command - alias of :meta
|
249
272
|
#
|
250
273
|
# @return [Capybara::Node::Element] The element
|
251
274
|
def send_keys(*args)
|
@@ -255,7 +278,7 @@ module Capybara
|
|
255
278
|
|
256
279
|
##
|
257
280
|
#
|
258
|
-
# Hover on the Element
|
281
|
+
# Hover on the Element.
|
259
282
|
#
|
260
283
|
# @return [Capybara::Node::Element] The element
|
261
284
|
def hover
|
@@ -268,7 +291,8 @@ module Capybara
|
|
268
291
|
# @return [String] The tag name of the element
|
269
292
|
#
|
270
293
|
def tag_name
|
271
|
-
|
294
|
+
# Element type is immutable so cache it
|
295
|
+
@tag_name ||= initial_cache[:tag_name] || synchronize { base.tag_name }
|
272
296
|
end
|
273
297
|
|
274
298
|
##
|
@@ -282,6 +306,17 @@ module Capybara
|
|
282
306
|
synchronize { base.visible? }
|
283
307
|
end
|
284
308
|
|
309
|
+
##
|
310
|
+
#
|
311
|
+
# Whether or not the element is currently in the viewport and it (or descendants)
|
312
|
+
# would be considered clickable at the elements center point.
|
313
|
+
#
|
314
|
+
# @return [Boolean] Whether the elements center is obscured.
|
315
|
+
#
|
316
|
+
def obscured?
|
317
|
+
synchronize { base.obscured? }
|
318
|
+
end
|
319
|
+
|
285
320
|
##
|
286
321
|
#
|
287
322
|
# Whether or not the element is checked.
|
@@ -334,7 +369,7 @@ module Capybara
|
|
334
369
|
|
335
370
|
##
|
336
371
|
#
|
337
|
-
# An XPath expression describing where on the page the element can be found
|
372
|
+
# An XPath expression describing where on the page the element can be found.
|
338
373
|
#
|
339
374
|
# @return [String] An XPath expression
|
340
375
|
#
|
@@ -342,6 +377,10 @@ module Capybara
|
|
342
377
|
synchronize { base.path }
|
343
378
|
end
|
344
379
|
|
380
|
+
def rect
|
381
|
+
synchronize { base.rect }
|
382
|
+
end
|
383
|
+
|
345
384
|
##
|
346
385
|
#
|
347
386
|
# Trigger any event on the current element, for example mouseover or focus
|
@@ -366,21 +405,85 @@ module Capybara
|
|
366
405
|
# source.drag_to(target)
|
367
406
|
#
|
368
407
|
# @param [Capybara::Node::Element] node The element to drag to
|
408
|
+
# @param [Hash] options Driver specific options for dragging. May not be supported by all drivers.
|
409
|
+
# @option options [Numeric] :delay (0.05) When using Chrome/Firefox with Selenium and HTML5 dragging this is the number
|
410
|
+
# of seconds between each stage of the drag.
|
411
|
+
# @option options [Boolean] :html5 When using Chrome/Firefox with Selenium enables to force the use of HTML5
|
412
|
+
# (true) or legacy (false) dragging. If not specified the driver will attempt to
|
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
|
+
#
|
416
|
+
#
|
417
|
+
# @return [Capybara::Node::Element] The dragged element
|
418
|
+
def drag_to(node, **options)
|
419
|
+
synchronize { base.drag_to(node.base, **options) }
|
420
|
+
self
|
421
|
+
end
|
422
|
+
|
423
|
+
##
|
424
|
+
#
|
425
|
+
# Drop items on the current element.
|
426
|
+
#
|
427
|
+
# target = page.find('#foo')
|
428
|
+
# target.drop('/some/path/file.csv')
|
429
|
+
#
|
430
|
+
# @overload drop(path, ...)
|
431
|
+
# @param [String, #to_path] path Location of the file to drop on the element
|
432
|
+
#
|
433
|
+
# @overload drop(strings, ...)
|
434
|
+
# @param [Hash] strings A hash of type to data to be dropped - `{ "text/url" => "https://www.google.com" }`
|
369
435
|
#
|
370
436
|
# @return [Capybara::Node::Element] The element
|
371
|
-
def
|
372
|
-
|
437
|
+
def drop(*args)
|
438
|
+
options = args.map do |arg|
|
439
|
+
return arg.to_path if arg.respond_to?(:to_path)
|
440
|
+
|
441
|
+
arg
|
442
|
+
end
|
443
|
+
synchronize { base.drop(*options) }
|
444
|
+
self
|
445
|
+
end
|
446
|
+
|
447
|
+
##
|
448
|
+
#
|
449
|
+
# Scroll the page or element.
|
450
|
+
#
|
451
|
+
# @overload scroll_to(position, offset: [0,0])
|
452
|
+
# Scroll the page or element to its top, bottom or middle.
|
453
|
+
# @param [:top, :bottom, :center, :current] position
|
454
|
+
# @param [[Integer, Integer]] offset
|
455
|
+
#
|
456
|
+
# @overload scroll_to(element, align: :top)
|
457
|
+
# Scroll the page or current element until the given element is aligned at the top, bottom, or center of it.
|
458
|
+
# @param [Capybara::Node::Element] element The element to be scrolled into view
|
459
|
+
# @param [:top, :bottom, :center] align Where to align the element being scrolled into view with relation to the current page/element if possible
|
460
|
+
#
|
461
|
+
# @overload scroll_to(x,y)
|
462
|
+
# @param [Integer] x Horizontal scroll offset
|
463
|
+
# @param [Integer] y Vertical scroll offset
|
464
|
+
#
|
465
|
+
# @return [Capybara::Node::Element] The element
|
466
|
+
def scroll_to(pos_or_el_or_x, y = nil, align: :top, offset: nil)
|
467
|
+
case pos_or_el_or_x
|
468
|
+
when Symbol
|
469
|
+
synchronize { base.scroll_to(nil, pos_or_el_or_x) } unless pos_or_el_or_x == :current
|
470
|
+
when Capybara::Node::Element
|
471
|
+
synchronize { base.scroll_to(pos_or_el_or_x.base, align) }
|
472
|
+
else
|
473
|
+
synchronize { base.scroll_to(nil, nil, [pos_or_el_or_x, y]) }
|
474
|
+
end
|
475
|
+
synchronize { base.scroll_by(*offset) } unless offset.nil?
|
373
476
|
self
|
374
477
|
end
|
375
478
|
|
376
479
|
##
|
377
480
|
#
|
378
481
|
# Execute the given JS in the context of the element not returning a result. This is useful for scripts that return
|
379
|
-
# complex objects, such as jQuery statements.
|
380
|
-
#
|
482
|
+
# complex objects, such as jQuery statements. {#execute_script} should be used over
|
483
|
+
# {#evaluate_script} whenever a result is not expected or needed. `this` in the script will refer to the element this is called on.
|
381
484
|
#
|
382
485
|
# @param [String] script A string of JavaScript to execute
|
383
|
-
# @param args Optional arguments that will be passed to the script.
|
486
|
+
# @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
|
384
487
|
#
|
385
488
|
def execute_script(script, *args)
|
386
489
|
session.execute_script(<<~JS, self, *args)
|
@@ -393,7 +496,7 @@ module Capybara
|
|
393
496
|
##
|
394
497
|
#
|
395
498
|
# Evaluate the given JS in the context of the element and return the result. Be careful when using this with
|
396
|
-
# scripts that return complex objects, such as jQuery statements.
|
499
|
+
# scripts that return complex objects, such as jQuery statements. {#execute_script} might
|
397
500
|
# be a better alternative. `this` in the script will refer to the element this is called on.
|
398
501
|
#
|
399
502
|
# @param [String] script A string of JavaScript to evaluate
|
@@ -411,7 +514,7 @@ module Capybara
|
|
411
514
|
#
|
412
515
|
# Evaluate the given JavaScript in the context of the element and obtain the result from a
|
413
516
|
# callback function which will be passed as the last argument to the script. `this` in the
|
414
|
-
# script will refer to the element this is called on
|
517
|
+
# script will refer to the element this is called on.
|
415
518
|
#
|
416
519
|
# @param [String] script A string of JavaScript to evaluate
|
417
520
|
# @return [Object] The result of the evaluated JavaScript (may be driver specific)
|
@@ -424,27 +527,59 @@ module Capybara
|
|
424
527
|
JS
|
425
528
|
end
|
426
529
|
|
530
|
+
##
|
531
|
+
#
|
532
|
+
# Toggle the elements background color between white and black for a period of time.
|
533
|
+
#
|
534
|
+
# @return [Capybara::Node::Element] The element
|
535
|
+
def flash
|
536
|
+
execute_script(<<~JS, 100)
|
537
|
+
async function flash(el, delay){
|
538
|
+
var old_bg = el.style.backgroundColor;
|
539
|
+
var colors = ["black", "white"];
|
540
|
+
for(var i=0; i<20; i++){
|
541
|
+
el.style.backgroundColor = colors[i % colors.length];
|
542
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
543
|
+
}
|
544
|
+
el.style.backgroundColor = old_bg;
|
545
|
+
}
|
546
|
+
flash(this, arguments[0]);
|
547
|
+
JS
|
548
|
+
|
549
|
+
self
|
550
|
+
end
|
551
|
+
|
552
|
+
# @api private
|
427
553
|
def reload
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
554
|
+
return self unless @allow_reload
|
555
|
+
|
556
|
+
begin
|
557
|
+
reloaded = @query.resolve_for(query_scope.reload)[@query_idx.to_i]
|
558
|
+
@base = reloaded.base if reloaded
|
559
|
+
rescue StandardError => e
|
560
|
+
raise e unless catch_error?(e)
|
435
561
|
end
|
436
562
|
self
|
437
563
|
end
|
438
564
|
|
565
|
+
##
|
566
|
+
#
|
567
|
+
# A human-readable representation of the element.
|
568
|
+
#
|
569
|
+
# @return [String] A string representation
|
439
570
|
def inspect
|
440
571
|
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
441
572
|
rescue NotSupportedByDriverError
|
442
573
|
%(#<Capybara::Node::Element tag="#{base.tag_name}">)
|
443
|
-
rescue
|
444
|
-
raise unless session.driver.invalid_element_errors.any? { |et| err.is_a?(et) }
|
574
|
+
rescue *session.driver.invalid_element_errors
|
445
575
|
%(Obsolete #<Capybara::Node::Element>)
|
446
576
|
end
|
447
577
|
|
578
|
+
# @api private
|
579
|
+
def initial_cache
|
580
|
+
base.respond_to?(:initial_cache) ? base.initial_cache : {}
|
581
|
+
end
|
582
|
+
|
448
583
|
STYLE_SCRIPT = <<~JS
|
449
584
|
(function(){
|
450
585
|
var s = window.getComputedStyle(this);
|
@@ -456,6 +591,16 @@ module Capybara
|
|
456
591
|
return result;
|
457
592
|
}).apply(this, arguments)
|
458
593
|
JS
|
594
|
+
|
595
|
+
private
|
596
|
+
|
597
|
+
def perform_click_action(keys, wait: nil, **options)
|
598
|
+
raise ArgumentError, 'You must specify both x: and y: for a click offset' if nil ^ options[:x] ^ options[:y]
|
599
|
+
|
600
|
+
options[:offset] ||= :center if session_options.w3c_click_offset
|
601
|
+
synchronize(wait) { yield keys, options }
|
602
|
+
self
|
603
|
+
end
|
459
604
|
end
|
460
605
|
end
|
461
606
|
end
|