capybara 3.16.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 +321 -0
- data/README.md +51 -60
- data/lib/capybara.rb +71 -114
- data/lib/capybara/config.rb +8 -5
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/node.rb +15 -3
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +5 -3
- data/lib/capybara/minitest.rb +242 -141
- data/lib/capybara/minitest/spec.rb +159 -90
- data/lib/capybara/node/actions.rb +85 -74
- data/lib/capybara/node/base.rb +4 -4
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +216 -117
- data/lib/capybara/node/finders.rb +65 -65
- data/lib/capybara/node/matchers.rb +228 -126
- data/lib/capybara/node/simple.rb +9 -4
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +296 -30
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +2 -2
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/queries/title_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +7 -2
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +1 -1
- data/lib/capybara/rack_test/node.rb +43 -7
- 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 +36 -8
- data/lib/capybara/rspec/matcher_proxies.rb +6 -4
- data/lib/capybara/rspec/matchers.rb +100 -63
- data/lib/capybara/rspec/matchers/base.rb +23 -10
- 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 +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +4 -4
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +2 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/selector.rb +219 -588
- data/lib/capybara/selector/builders/css_builder.rb +10 -6
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +4 -2
- data/lib/capybara/selector/definition.rb +277 -0
- 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/filter_set.rb +13 -9
- data/lib/capybara/selector/filters/base.rb +11 -2
- data/lib/capybara/selector/filters/locator_filter.rb +13 -3
- data/lib/capybara/selector/regexp_disassembler.rb +9 -2
- data/lib/capybara/selector/selector.rb +43 -448
- 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 +125 -56
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +73 -17
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +41 -2
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +14 -5
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +67 -45
- data/lib/capybara/selenium/extensions/html5_drag.rb +152 -36
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +227 -56
- data/lib/capybara/selenium/nodes/chrome_node.rb +93 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +37 -59
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +27 -54
- 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/server.rb +19 -3
- data/lib/capybara/server/animation_disabler.rb +2 -2
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/session.rb +124 -106
- data/lib/capybara/session/config.rb +12 -10
- data/lib/capybara/session/matchers.rb +6 -6
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +94 -5
- data/lib/capybara/spec/session/all_spec.rb +84 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -6
- 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 +44 -1
- data/lib/capybara/spec/session/click_link_spec.rb +11 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +37 -2
- data/lib/capybara/spec/session/find_spec.rb +60 -6
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +35 -6
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +34 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +47 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +574 -16
- 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 +1 -1
- data/lib/capybara/spec/session/select_spec.rb +5 -10
- data/lib/capybara/spec/session/selectors_spec.rb +24 -3
- 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/window_spec.rb +10 -9
- data/lib/capybara/spec/spec_helper.rb +7 -2
- data/lib/capybara/spec/test_app.rb +26 -21
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +25 -4
- data/lib/capybara/spec/views/frame_child.erb +2 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +9 -9
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/spatial.erb +31 -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_html.erb +28 -2
- data/lib/capybara/spec/views/with_js.erb +2 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +10 -10
- data/spec/basic_node_spec.rb +6 -6
- data/spec/capybara_spec.rb +28 -28
- data/spec/dsl_spec.rb +16 -3
- 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 +12 -2
- data/spec/minitest_spec_spec.rb +56 -45
- data/spec/rack_test_spec.rb +25 -12
- data/spec/regexp_dissassembler_spec.rb +53 -39
- data/spec/result_spec.rb +50 -54
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/shared_spec_matchers.rb +78 -62
- data/spec/rspec_spec.rb +5 -5
- data/spec/sauce_spec_chrome.rb +1 -0
- data/spec/selector_spec.rb +26 -16
- data/spec/selenium_spec_chrome.rb +84 -5
- data/spec/selenium_spec_chrome_remote.rb +23 -8
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +16 -21
- data/spec/selenium_spec_firefox_remote.rb +4 -13
- data/spec/selenium_spec_ie.rb +23 -15
- data/spec/selenium_spec_safari.rb +17 -17
- data/spec/server_spec.rb +87 -42
- data/spec/session_spec.rb +11 -4
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +62 -72
- data/spec/spec_helper.rb +43 -5
- metadata +114 -16
data/lib/capybara/node/base.rb
CHANGED
@@ -81,19 +81,19 @@ module Capybara
|
|
81
81
|
timer = Capybara::Helpers.timer(expire_in: seconds)
|
82
82
|
begin
|
83
83
|
yield
|
84
|
-
rescue StandardError =>
|
84
|
+
rescue StandardError => e
|
85
85
|
session.raise_server_error!
|
86
|
-
raise
|
86
|
+
raise e unless catch_error?(e, errors)
|
87
87
|
|
88
88
|
if driver.wait?
|
89
|
-
raise
|
89
|
+
raise e if timer.expired?
|
90
90
|
|
91
91
|
sleep(0.01)
|
92
92
|
reload if session_options.automatic_reload
|
93
93
|
else
|
94
94
|
old_base = @base
|
95
95
|
reload if session_options.automatic_reload
|
96
|
-
raise
|
96
|
+
raise e if old_base == @base
|
97
97
|
end
|
98
98
|
retry
|
99
99
|
ensure
|
@@ -42,7 +42,7 @@ module Capybara
|
|
42
42
|
# @return [Boolean]
|
43
43
|
#
|
44
44
|
def has_title?(title, **options)
|
45
|
-
make_predicate(options) { assert_title(title, options) }
|
45
|
+
make_predicate(options) { assert_title(title, **options) }
|
46
46
|
end
|
47
47
|
|
48
48
|
##
|
@@ -52,13 +52,13 @@ module Capybara
|
|
52
52
|
# @return [Boolean]
|
53
53
|
#
|
54
54
|
def has_no_title?(title, **options)
|
55
|
-
make_predicate(options) { assert_no_title(title, options) }
|
55
|
+
make_predicate(options) { assert_no_title(title, **options) }
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
60
|
def _verify_title(title, options)
|
61
|
-
query = Capybara::Queries::TitleQuery.new(title, options)
|
61
|
+
query = Capybara::Queries::TitleQuery.new(title, **options)
|
62
62
|
synchronize(query.wait) { yield(query) }
|
63
63
|
true
|
64
64
|
end
|
@@ -27,9 +27,11 @@ module Capybara
|
|
27
27
|
@query_scope = query_scope
|
28
28
|
@query = query
|
29
29
|
@allow_reload = false
|
30
|
+
@query_idx = nil
|
30
31
|
end
|
31
32
|
|
32
|
-
def allow_reload!
|
33
|
+
def allow_reload!(idx = nil)
|
34
|
+
@query_idx = idx
|
33
35
|
@allow_reload = true
|
34
36
|
end
|
35
37
|
|
@@ -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
|
#
|
@@ -87,11 +89,11 @@ module Capybara
|
|
87
89
|
|
88
90
|
begin
|
89
91
|
synchronize { base.style(styles) }
|
90
|
-
rescue NotImplementedError =>
|
92
|
+
rescue NotImplementedError => e
|
91
93
|
begin
|
92
94
|
evaluate_script(STYLE_SCRIPT, *styles)
|
93
95
|
rescue Capybara::NotSupportedByDriverError
|
94
|
-
raise
|
96
|
+
raise e
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
@@ -109,32 +111,41 @@ module Capybara
|
|
109
111
|
# Set the value of the form element to the given value.
|
110
112
|
#
|
111
113
|
# @param [String] value The new value
|
112
|
-
# @param [Hash
|
114
|
+
# @param [Hash] options Driver specific options for how to set the value. Take default values from {Capybara.configure default_set_options}.
|
113
115
|
#
|
114
116
|
# @return [Capybara::Node::Element] The element
|
115
117
|
def set(value, **options)
|
116
|
-
|
118
|
+
if ENV['CAPYBARA_THOROUGH'] && readonly?
|
119
|
+
raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}"
|
120
|
+
end
|
117
121
|
|
118
122
|
options = session_options.default_set_options.to_h.merge(options)
|
119
|
-
synchronize { base.set(value, options) }
|
123
|
+
synchronize { base.set(value, **options) }
|
120
124
|
self
|
121
125
|
end
|
122
126
|
|
123
127
|
##
|
124
128
|
#
|
125
|
-
# 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.
|
126
135
|
#
|
136
|
+
# @param [false, Numeric] wait
|
137
|
+
# Maximum time to wait for the action to succeed. Defaults to {Capybara.configure default_max_wait_time}.
|
127
138
|
# @return [Capybara::Node::Element] The element
|
128
139
|
def select_option(wait: nil)
|
129
|
-
warn "Attempt to select disabled option: #{value || text}" if disabled?
|
130
140
|
synchronize(wait) { base.select_option }
|
131
141
|
self
|
132
142
|
end
|
133
143
|
|
134
144
|
##
|
135
145
|
#
|
136
|
-
# 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.
|
137
147
|
#
|
148
|
+
# @macro action_waiting_behavior
|
138
149
|
# @return [Capybara::Node::Element] The element
|
139
150
|
def unselect_option(wait: nil)
|
140
151
|
synchronize(wait) { base.unselect_option }
|
@@ -143,51 +154,55 @@ module Capybara
|
|
143
154
|
|
144
155
|
##
|
145
156
|
#
|
146
|
-
# Click the Element
|
157
|
+
# Click the Element.
|
147
158
|
#
|
159
|
+
# @macro action_waiting_behavior
|
148
160
|
# @!macro click_modifiers
|
149
|
-
# 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
|
150
|
-
# @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)
|
151
163
|
# @param *modifier_keys [:alt, :control, :meta, :shift] ([]) Keys to be held down when clicking
|
152
|
-
# @option
|
153
|
-
#
|
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)
|
154
169
|
# @return [Capybara::Node::Element] The element
|
155
|
-
def click(*keys,
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
self
|
170
|
+
def click(*keys, **options)
|
171
|
+
perform_click_action(keys, **options) do |k, opts|
|
172
|
+
base.click(k, **opts)
|
173
|
+
end
|
160
174
|
end
|
161
175
|
|
162
176
|
##
|
163
177
|
#
|
164
|
-
# Right Click the Element
|
178
|
+
# Right Click the Element.
|
165
179
|
#
|
180
|
+
# @macro action_waiting_behavior
|
166
181
|
# @macro click_modifiers
|
182
|
+
# @option options [Float] delay Delay between the mouse down and mouse up events in seconds (0)
|
167
183
|
# @return [Capybara::Node::Element] The element
|
168
|
-
def right_click(*keys,
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
self
|
184
|
+
def right_click(*keys, **options)
|
185
|
+
perform_click_action(keys, **options) do |k, opts|
|
186
|
+
base.right_click(k, **opts)
|
187
|
+
end
|
173
188
|
end
|
174
189
|
|
175
190
|
##
|
176
191
|
#
|
177
|
-
# Double Click the Element
|
192
|
+
# Double Click the Element.
|
178
193
|
#
|
194
|
+
# @macro action_waiting_behavior
|
179
195
|
# @macro click_modifiers
|
180
196
|
# @return [Capybara::Node::Element] The element
|
181
|
-
def double_click(*keys,
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
self
|
197
|
+
def double_click(*keys, **options)
|
198
|
+
perform_click_action(keys, **options) do |k, opts|
|
199
|
+
base.double_click(k, **opts)
|
200
|
+
end
|
186
201
|
end
|
187
202
|
|
188
203
|
##
|
189
204
|
#
|
190
|
-
# Send Keystrokes to the Element
|
205
|
+
# Send Keystrokes to the Element.
|
191
206
|
#
|
192
207
|
# @overload send_keys(keys, ...)
|
193
208
|
# @param keys [String, Symbol, Array<String,Symbol>]
|
@@ -195,65 +210,65 @@ module Capybara
|
|
195
210
|
# Examples:
|
196
211
|
#
|
197
212
|
# element.send_keys "foo" #=> value: 'foo'
|
198
|
-
# element.send_keys "tet", :left, "s"
|
213
|
+
# element.send_keys "tet", :left, "s" #=> value: 'test'
|
199
214
|
# element.send_keys [:control, 'a'], :space #=> value: ' ' - assuming ctrl-a selects all contents
|
200
215
|
#
|
201
|
-
# Symbols supported for keys
|
202
|
-
# :cancel
|
203
|
-
# :help
|
204
|
-
# :backspace
|
205
|
-
# :tab
|
206
|
-
# :clear
|
207
|
-
# :return
|
208
|
-
# :enter
|
209
|
-
# :shift
|
210
|
-
# :control
|
211
|
-
# :alt
|
212
|
-
# :pause
|
213
|
-
# :escape
|
214
|
-
# :space
|
215
|
-
# :page_up
|
216
|
-
# :page_down
|
217
|
-
# :end
|
218
|
-
# :home
|
219
|
-
# :left
|
220
|
-
# :up
|
221
|
-
# :right
|
222
|
-
# :down
|
223
|
-
# :insert
|
224
|
-
# :delete
|
225
|
-
# :semicolon
|
226
|
-
# :equals
|
227
|
-
# :numpad0
|
228
|
-
# :numpad1
|
229
|
-
# :numpad2
|
230
|
-
# :numpad3
|
231
|
-
# :numpad4
|
232
|
-
# :numpad5
|
233
|
-
# :numpad6
|
234
|
-
# :numpad7
|
235
|
-
# :numpad8
|
236
|
-
# :numpad9
|
237
|
-
# :multiply - numeric keypad *
|
238
|
-
# :add - numeric keypad +
|
239
|
-
# :separator - numeric keypad 'separator' key ??
|
240
|
-
# :subtract - numeric keypad -
|
241
|
-
# :decimal - numeric keypad .
|
242
|
-
# :divide - numeric keypad /
|
243
|
-
# :f1
|
244
|
-
# :f2
|
245
|
-
# :f3
|
246
|
-
# :f4
|
247
|
-
# :f5
|
248
|
-
# :f6
|
249
|
-
# :f7
|
250
|
-
# :f8
|
251
|
-
# :f9
|
252
|
-
# :f10
|
253
|
-
# :f11
|
254
|
-
# :f12
|
255
|
-
# :meta
|
256
|
-
# :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
|
257
272
|
#
|
258
273
|
# @return [Capybara::Node::Element] The element
|
259
274
|
def send_keys(*args)
|
@@ -263,7 +278,7 @@ module Capybara
|
|
263
278
|
|
264
279
|
##
|
265
280
|
#
|
266
|
-
# Hover on the Element
|
281
|
+
# Hover on the Element.
|
267
282
|
#
|
268
283
|
# @return [Capybara::Node::Element] The element
|
269
284
|
def hover
|
@@ -276,7 +291,8 @@ module Capybara
|
|
276
291
|
# @return [String] The tag name of the element
|
277
292
|
#
|
278
293
|
def tag_name
|
279
|
-
|
294
|
+
# Element type is immutable so cache it
|
295
|
+
@tag_name ||= initial_cache[:tag_name] || synchronize { base.tag_name }
|
280
296
|
end
|
281
297
|
|
282
298
|
##
|
@@ -290,6 +306,17 @@ module Capybara
|
|
290
306
|
synchronize { base.visible? }
|
291
307
|
end
|
292
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
|
+
|
293
320
|
##
|
294
321
|
#
|
295
322
|
# Whether or not the element is checked.
|
@@ -342,7 +369,7 @@ module Capybara
|
|
342
369
|
|
343
370
|
##
|
344
371
|
#
|
345
|
-
# 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.
|
346
373
|
#
|
347
374
|
# @return [String] An XPath expression
|
348
375
|
#
|
@@ -350,6 +377,10 @@ module Capybara
|
|
350
377
|
synchronize { base.path }
|
351
378
|
end
|
352
379
|
|
380
|
+
def rect
|
381
|
+
synchronize { base.rect }
|
382
|
+
end
|
383
|
+
|
353
384
|
##
|
354
385
|
#
|
355
386
|
# Trigger any event on the current element, for example mouseover or focus
|
@@ -374,26 +405,58 @@ module Capybara
|
|
374
405
|
# source.drag_to(target)
|
375
406
|
#
|
376
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" }`
|
377
435
|
#
|
378
436
|
# @return [Capybara::Node::Element] The element
|
379
|
-
def
|
380
|
-
|
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) }
|
381
444
|
self
|
382
445
|
end
|
383
446
|
|
384
447
|
##
|
385
448
|
#
|
386
|
-
# Scroll the page or element
|
449
|
+
# Scroll the page or element.
|
387
450
|
#
|
388
|
-
# Scroll the page or element to its top, bottom or middle
|
389
451
|
# @overload scroll_to(position, offset: [0,0])
|
452
|
+
# Scroll the page or element to its top, bottom or middle.
|
390
453
|
# @param [:top, :bottom, :center, :current] position
|
391
|
-
# @param
|
454
|
+
# @param [[Integer, Integer]] offset
|
392
455
|
#
|
393
|
-
# Scroll the page or current element until the given element is aligned at the top, bottom, or center of it
|
394
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.
|
395
458
|
# @param [Capybara::Node::Element] element The element to be scrolled into view
|
396
|
-
# @param [:top, :bottom, :center]
|
459
|
+
# @param [:top, :bottom, :center] align Where to align the element being scrolled into view with relation to the current page/element if possible
|
397
460
|
#
|
398
461
|
# @overload scroll_to(x,y)
|
399
462
|
# @param [Integer] x Horizontal scroll offset
|
@@ -416,11 +479,11 @@ module Capybara
|
|
416
479
|
##
|
417
480
|
#
|
418
481
|
# Execute the given JS in the context of the element not returning a result. This is useful for scripts that return
|
419
|
-
# complex objects, such as jQuery statements.
|
420
|
-
#
|
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.
|
421
484
|
#
|
422
485
|
# @param [String] script A string of JavaScript to execute
|
423
|
-
# @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
|
424
487
|
#
|
425
488
|
def execute_script(script, *args)
|
426
489
|
session.execute_script(<<~JS, self, *args)
|
@@ -433,7 +496,7 @@ module Capybara
|
|
433
496
|
##
|
434
497
|
#
|
435
498
|
# Evaluate the given JS in the context of the element and return the result. Be careful when using this with
|
436
|
-
# scripts that return complex objects, such as jQuery statements.
|
499
|
+
# scripts that return complex objects, such as jQuery statements. {#execute_script} might
|
437
500
|
# be a better alternative. `this` in the script will refer to the element this is called on.
|
438
501
|
#
|
439
502
|
# @param [String] script A string of JavaScript to evaluate
|
@@ -451,7 +514,7 @@ module Capybara
|
|
451
514
|
#
|
452
515
|
# Evaluate the given JavaScript in the context of the element and obtain the result from a
|
453
516
|
# callback function which will be passed as the last argument to the script. `this` in the
|
454
|
-
# script will refer to the element this is called on
|
517
|
+
# script will refer to the element this is called on.
|
455
518
|
#
|
456
519
|
# @param [String] script A string of JavaScript to evaluate
|
457
520
|
# @return [Object] The result of the evaluated JavaScript (may be driver specific)
|
@@ -464,25 +527,51 @@ module Capybara
|
|
464
527
|
JS
|
465
528
|
end
|
466
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
|
467
553
|
def reload
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
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)
|
475
561
|
end
|
476
562
|
self
|
477
563
|
end
|
478
564
|
|
565
|
+
##
|
566
|
+
#
|
567
|
+
# A human-readable representation of the element.
|
568
|
+
#
|
569
|
+
# @return [String] A string representation
|
479
570
|
def inspect
|
480
571
|
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
481
572
|
rescue NotSupportedByDriverError
|
482
573
|
%(#<Capybara::Node::Element tag="#{base.tag_name}">)
|
483
|
-
rescue
|
484
|
-
raise unless session.driver.invalid_element_errors.any? { |et| err.is_a?(et) }
|
485
|
-
|
574
|
+
rescue *session.driver.invalid_element_errors
|
486
575
|
%(Obsolete #<Capybara::Node::Element>)
|
487
576
|
end
|
488
577
|
|
@@ -502,6 +591,16 @@ module Capybara
|
|
502
591
|
return result;
|
503
592
|
}).apply(this, arguments)
|
504
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
|
505
604
|
end
|
506
605
|
end
|
507
606
|
end
|