capybara 3.35.3 → 3.39.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +110 -4
- data/README.md +28 -12
- data/lib/capybara/config.rb +16 -4
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/driver/node.rb +5 -1
- data/lib/capybara/dsl.rb +4 -10
- data/lib/capybara/helpers.rb +8 -13
- data/lib/capybara/minitest/spec.rb +2 -2
- data/lib/capybara/node/actions.rb +14 -9
- data/lib/capybara/node/base.rb +2 -1
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/element.rb +13 -2
- data/lib/capybara/node/finders.rb +11 -2
- data/lib/capybara/node/simple.rb +5 -1
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +2 -1
- data/lib/capybara/queries/base_query.rb +2 -2
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +38 -10
- data/lib/capybara/queries/sibling_query.rb +2 -1
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +63 -8
- data/lib/capybara/rack_test/driver.rb +4 -4
- data/lib/capybara/rack_test/form.rb +29 -7
- data/lib/capybara/rack_test/node.rb +28 -22
- data/lib/capybara/registration_container.rb +0 -3
- data/lib/capybara/registrations/drivers.rb +6 -6
- data/lib/capybara/registrations/servers.rb +30 -10
- data/lib/capybara/rspec/matcher_proxies.rb +6 -6
- data/lib/capybara/rspec/matchers/base.rb +8 -6
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/rspec/matchers/have_selector.rb +5 -5
- data/lib/capybara/rspec/matchers.rb +14 -14
- data/lib/capybara/selector/builders/css_builder.rb +1 -1
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +1 -1
- data/lib/capybara/selector/definition/button.rb +9 -4
- data/lib/capybara/selector/definition/checkbox.rb +1 -1
- data/lib/capybara/selector/definition/file_field.rb +1 -1
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +2 -1
- data/lib/capybara/selector/definition/radio_button.rb +1 -1
- data/lib/capybara/selector/definition.rb +4 -2
- data/lib/capybara/selector/filter_set.rb +4 -7
- data/lib/capybara/selector/regexp_disassembler.rb +2 -5
- data/lib/capybara/selector/selector.rb +5 -1
- data/lib/capybara/selector.rb +1 -0
- data/lib/capybara/selenium/driver.rb +30 -13
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +1 -1
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -5
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +1 -1
- data/lib/capybara/selenium/extensions/html5_drag.rb +5 -4
- data/lib/capybara/selenium/logger_suppressor.rb +4 -0
- data/lib/capybara/selenium/node.rb +81 -32
- data/lib/capybara/selenium/nodes/chrome_node.rb +6 -2
- data/lib/capybara/selenium/nodes/edge_node.rb +25 -3
- data/lib/capybara/selenium/nodes/firefox_node.rb +3 -3
- data/lib/capybara/selenium/nodes/safari_node.rb +4 -4
- data/lib/capybara/selenium/patches/action_pauser.rb +3 -3
- data/lib/capybara/selenium/patches/atoms.rb +1 -1
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
- data/lib/capybara/server/animation_disabler.rb +40 -23
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/session/config.rb +4 -2
- data/lib/capybara/session.rb +31 -32
- data/lib/capybara/spec/public/test.js +4 -0
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +10 -14
- data/lib/capybara/spec/session/assert_text_spec.rb +17 -17
- data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
- data/lib/capybara/spec/session/check_spec.rb +10 -0
- data/lib/capybara/spec/session/choose_spec.rb +6 -0
- data/lib/capybara/spec/session/click_link_spec.rb +11 -0
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +7 -1
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +2 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -2
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/has_button_spec.rb +30 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +3 -3
- data/lib/capybara/spec/session/has_field_spec.rb +25 -1
- data/lib/capybara/spec/session/has_link_spec.rb +40 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +10 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +15 -0
- data/lib/capybara/spec/session/has_text_spec.rb +6 -14
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -0
- data/lib/capybara/spec/session/node_spec.rb +82 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +13 -0
- data/lib/capybara/spec/session/scroll_spec.rb +7 -5
- data/lib/capybara/spec/session/visit_spec.rb +20 -0
- data/lib/capybara/spec/session/window/window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/session/within_spec.rb +13 -0
- data/lib/capybara/spec/spec_helper.rb +12 -5
- data/lib/capybara/spec/test_app.rb +91 -14
- data/lib/capybara/spec/views/animated.erb +1 -1
- data/lib/capybara/spec/views/form.erb +28 -3
- data/lib/capybara/spec/views/frame_child.erb +1 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +1 -1
- data/lib/capybara/spec/views/offset.erb +2 -1
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +2 -2
- data/lib/capybara/spec/views/scroll.erb +2 -1
- data/lib/capybara/spec/views/spatial.erb +1 -1
- data/lib/capybara/spec/views/with_animation.erb +2 -3
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +2 -2
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +2 -2
- data/lib/capybara/spec/views/with_html.erb +3 -3
- data/lib/capybara/spec/views/with_jquery_animation.erb +1 -1
- data/lib/capybara/spec/views/with_js.erb +2 -3
- data/lib/capybara/spec/views/with_jstree.erb +1 -1
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/spec/views/with_shadow.erb +31 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +2 -2
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +1 -1
- data/lib/capybara.rb +23 -24
- data/spec/basic_node_spec.rb +16 -3
- data/spec/capybara_spec.rb +12 -0
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +1 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +5 -3
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/minitest_spec.rb +4 -0
- data/spec/minitest_spec_spec.rb +4 -0
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +30 -12
- data/spec/result_spec.rb +32 -35
- data/spec/rspec/features_spec.rb +3 -3
- data/spec/rspec/scenarios_spec.rb +2 -2
- data/spec/rspec/shared_spec_matchers.rb +3 -3
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +2 -2
- data/spec/sauce_spec_chrome.rb +4 -4
- data/spec/selector_spec.rb +4 -4
- data/spec/selenium_spec_chrome.rb +16 -16
- data/spec/selenium_spec_chrome_remote.rb +15 -14
- data/spec/selenium_spec_edge.rb +12 -6
- data/spec/selenium_spec_firefox.rb +24 -7
- data/spec/selenium_spec_firefox_remote.rb +19 -4
- data/spec/selenium_spec_ie.rb +7 -8
- data/spec/selenium_spec_safari.rb +34 -20
- data/spec/server_spec.rb +7 -7
- data/spec/shared_selenium_node.rb +0 -4
- data/spec/shared_selenium_session.rb +24 -14
- data/spec/spec_helper.rb +34 -1
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +1 -1
- metadata +40 -14
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -4,22 +4,22 @@
|
|
4
4
|
|
5
5
|
require 'capybara/selenium/extensions/find'
|
6
6
|
require 'capybara/selenium/extensions/scroll'
|
7
|
+
require 'capybara/node/whitespace_normalizer'
|
7
8
|
|
8
9
|
class Capybara::Selenium::Node < Capybara::Driver::Node
|
10
|
+
include Capybara::Node::WhitespaceNormalizer
|
9
11
|
include Capybara::Selenium::Find
|
10
12
|
include Capybara::Selenium::Scroll
|
11
13
|
|
12
14
|
def visible_text
|
15
|
+
raise NotImplementedError, 'Getting visible text is not currently supported directly on shadow roots' if shadow_root?
|
16
|
+
|
13
17
|
native.text
|
14
18
|
end
|
15
19
|
|
16
20
|
def all_text
|
17
|
-
text = driver.evaluate_script('arguments[0].textContent', self)
|
18
|
-
text
|
19
|
-
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
|
20
|
-
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
|
21
|
-
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
|
22
|
-
.tr("\u00a0", ' ')
|
21
|
+
text = driver.evaluate_script('arguments[0].textContent', self) || ''
|
22
|
+
normalize_spacing(text)
|
23
23
|
end
|
24
24
|
|
25
25
|
def [](name)
|
@@ -37,9 +37,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def style(styles)
|
40
|
-
styles.
|
41
|
-
result[style] = native.css_value(style)
|
42
|
-
end
|
40
|
+
styles.to_h { |style| [style, native.css_value(style)] }
|
43
41
|
end
|
44
42
|
|
45
43
|
##
|
@@ -53,6 +51,11 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
53
51
|
# :none => append the new value to the existing value <br/>
|
54
52
|
# :backspace => send backspace keystrokes to clear the field <br/>
|
55
53
|
# Array => an array of keys to send before the value being set, e.g. [[:command, 'a'], :backspace]
|
54
|
+
# @option options [Boolean] :rapid (nil) Whether setting text inputs should use a faster "rapid" mode<br/>
|
55
|
+
# nil => Text inputs with length greater than 30 characters will be set using a faster driver script mode<br/>
|
56
|
+
# true => Rapid mode will be used regardless of input length<br/>
|
57
|
+
# false => Sends keys via conventional mode. This may be required to avoid losing key-presses if you have certain
|
58
|
+
# Javascript interactions on form inputs<br/>
|
56
59
|
def set(value, **options)
|
57
60
|
if value.is_a?(Array) && !multiple?
|
58
61
|
raise ArgumentError, "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
|
@@ -110,11 +113,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
110
113
|
action.click(target)
|
111
114
|
else
|
112
115
|
action.click_and_hold(target)
|
113
|
-
|
114
|
-
action.pause(action.pointer_inputs.first, click_options.delay)
|
115
|
-
else
|
116
|
-
action.pause(click_options.delay)
|
117
|
-
end
|
116
|
+
action_pause(action, click_options.delay)
|
118
117
|
action.release
|
119
118
|
end
|
120
119
|
end
|
@@ -135,9 +134,9 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
135
134
|
action.context_click(target)
|
136
135
|
elsif w3c?
|
137
136
|
action.move_to(target) if target
|
138
|
-
action.pointer_down(:right)
|
139
|
-
|
140
|
-
|
137
|
+
action.pointer_down(:right).then do |act|
|
138
|
+
action_pause(act, click_options.delay)
|
139
|
+
end.pointer_up(:right)
|
141
140
|
else
|
142
141
|
raise ArgumentError, 'Delay is not supported when right clicking with legacy (non-w3c) selenium driver'
|
143
142
|
end
|
@@ -179,7 +178,12 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
179
178
|
end
|
180
179
|
|
181
180
|
def tag_name
|
182
|
-
@tag_name ||=
|
181
|
+
@tag_name ||=
|
182
|
+
if native.respond_to? :tag_name
|
183
|
+
native.tag_name.downcase
|
184
|
+
else
|
185
|
+
shadow_root? ? 'ShadowRoot' : 'Unknown'
|
186
|
+
end
|
183
187
|
end
|
184
188
|
|
185
189
|
def visible?; boolean_attr(native.displayed?); end
|
@@ -199,10 +203,6 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
199
203
|
native.attribute('isContentEditable') == 'true'
|
200
204
|
end
|
201
205
|
|
202
|
-
def ==(other)
|
203
|
-
native == other.native
|
204
|
-
end
|
205
|
-
|
206
206
|
def path
|
207
207
|
driver.evaluate_script GET_XPATH_SCRIPT, self
|
208
208
|
end
|
@@ -218,6 +218,13 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
218
218
|
native.rect
|
219
219
|
end
|
220
220
|
|
221
|
+
def shadow_root
|
222
|
+
raise 'You must be using Selenium 4.1+ for shadow_root support' unless native.respond_to? :shadow_root
|
223
|
+
|
224
|
+
root = native.shadow_root
|
225
|
+
root && build_node(native.shadow_root)
|
226
|
+
end
|
227
|
+
|
221
228
|
protected
|
222
229
|
|
223
230
|
def scroll_if_needed
|
@@ -228,7 +235,7 @@ protected
|
|
228
235
|
end
|
229
236
|
|
230
237
|
def scroll_to_center
|
231
|
-
script = <<-
|
238
|
+
script = <<-JS
|
232
239
|
try {
|
233
240
|
arguments[0].scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'});
|
234
241
|
} catch(e) {
|
@@ -274,7 +281,7 @@ private
|
|
274
281
|
elsif clear == :backspace
|
275
282
|
# Clear field by sending the correct number of backspace keys.
|
276
283
|
backspaces = [:backspace] * self.value.to_s.length
|
277
|
-
send_keys(
|
284
|
+
send_keys(:end, *backspaces, value)
|
278
285
|
elsif clear.is_a? Array
|
279
286
|
send_keys(*clear, value)
|
280
287
|
else
|
@@ -282,7 +289,7 @@ private
|
|
282
289
|
if rapid == true || ((value.length > auto_rapid_set_length) && rapid != false)
|
283
290
|
send_keys(value[0..3])
|
284
291
|
driver.execute_script RAPID_APPEND_TEXT, self, value[4...-3]
|
285
|
-
send_keys(value[-3
|
292
|
+
send_keys(value[-3..])
|
286
293
|
else
|
287
294
|
send_keys(value)
|
288
295
|
end
|
@@ -298,7 +305,7 @@ private
|
|
298
305
|
|
299
306
|
scroll_if_needed do
|
300
307
|
action_with_modifiers(click_options) do |action|
|
301
|
-
if
|
308
|
+
if block
|
302
309
|
yield action
|
303
310
|
else
|
304
311
|
click_options.coords? ? action.click : action.click(native)
|
@@ -407,10 +414,30 @@ private
|
|
407
414
|
|
408
415
|
def action_with_modifiers(click_options)
|
409
416
|
actions = browser_action.tap do |acts|
|
410
|
-
if click_options.
|
411
|
-
|
417
|
+
if click_options.coords?
|
418
|
+
if click_options.center_offset?
|
419
|
+
if Selenium::WebDriver::VERSION.to_f >= 4.3
|
420
|
+
acts.move_to(native, *click_options.coords)
|
421
|
+
else
|
422
|
+
::Selenium::WebDriver.logger.suppress_deprecations do
|
423
|
+
acts.move_to(native).move_by(*click_options.coords)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
elsif Selenium::WebDriver::VERSION.to_f >= 4.3
|
427
|
+
right_by, down_by = *click_options.coords
|
428
|
+
size = native.size
|
429
|
+
left_offset = (size[:width] / 2).to_i
|
430
|
+
top_offset = (size[:height] / 2).to_i
|
431
|
+
left = -left_offset + right_by
|
432
|
+
top = -top_offset + down_by
|
433
|
+
acts.move_to(native, left, top)
|
434
|
+
else
|
435
|
+
::Selenium::WebDriver.logger.suppress_deprecations do
|
436
|
+
acts.move_to(native, *click_options.coords)
|
437
|
+
end
|
438
|
+
end
|
412
439
|
else
|
413
|
-
acts.move_to(native
|
440
|
+
acts.move_to(native)
|
414
441
|
end
|
415
442
|
end
|
416
443
|
modifiers_down(actions, click_options.keys)
|
@@ -453,6 +480,18 @@ private
|
|
453
480
|
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
454
481
|
end
|
455
482
|
|
483
|
+
def action_pause(action, duration)
|
484
|
+
if w3c?
|
485
|
+
if Selenium::WebDriver::VERSION.to_f >= 4.2
|
486
|
+
action.pause(device: action.pointer_inputs.first, duration: duration)
|
487
|
+
else
|
488
|
+
action.pause(action.pointer_inputs.first, duration)
|
489
|
+
end
|
490
|
+
else
|
491
|
+
action.pause(duration)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
456
495
|
def normalize_keys(keys)
|
457
496
|
keys.map do |key|
|
458
497
|
case key
|
@@ -479,7 +518,7 @@ private
|
|
479
518
|
def attrs(*attr_names)
|
480
519
|
return attr_names.map { |name| self[name.to_s] } if ENV['CAPYBARA_THOROUGH']
|
481
520
|
|
482
|
-
driver.evaluate_script <<~
|
521
|
+
driver.evaluate_script <<~JS, self, attr_names.map(&:to_s)
|
483
522
|
(function(el, names){
|
484
523
|
return names.map(function(name){
|
485
524
|
return el[name]
|
@@ -488,6 +527,16 @@ private
|
|
488
527
|
JS
|
489
528
|
end
|
490
529
|
|
530
|
+
def native_id
|
531
|
+
# Selenium 3 -> 4 changed the return of ref
|
532
|
+
type_or_id, id = native.ref
|
533
|
+
id || type_or_id
|
534
|
+
end
|
535
|
+
|
536
|
+
def shadow_root?
|
537
|
+
defined?(::Selenium::WebDriver::ShadowRoot) && native.is_a?(::Selenium::WebDriver::ShadowRoot)
|
538
|
+
end
|
539
|
+
|
491
540
|
GET_XPATH_SCRIPT = <<~'JS'
|
492
541
|
(function(el, xml){
|
493
542
|
var xpath = '';
|
@@ -520,7 +569,7 @@ private
|
|
520
569
|
})(arguments[0], document)
|
521
570
|
JS
|
522
571
|
|
523
|
-
OBSCURED_OR_OFFSET_SCRIPT = <<~
|
572
|
+
OBSCURED_OR_OFFSET_SCRIPT = <<~JS
|
524
573
|
(function(el, x, y) {
|
525
574
|
var box = el.getBoundingClientRect();
|
526
575
|
if (x == null) x = box.width/2;
|
@@ -537,7 +586,7 @@ private
|
|
537
586
|
})(arguments[0], arguments[1], arguments[2])
|
538
587
|
JS
|
539
588
|
|
540
|
-
RAPID_APPEND_TEXT = <<~
|
589
|
+
RAPID_APPEND_TEXT = <<~JS
|
541
590
|
(function(el, value) {
|
542
591
|
value = el.value + value;
|
543
592
|
if (el.maxLength && el.maxLength != -1){
|
@@ -65,7 +65,7 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
65
65
|
return super unless native_displayed?
|
66
66
|
|
67
67
|
begin
|
68
|
-
bridge.send(:execute, :is_element_displayed, id:
|
68
|
+
bridge.send(:execute, :is_element_displayed, id: native_id)
|
69
69
|
rescue Selenium::WebDriver::Error::UnknownCommandError
|
70
70
|
# If the is_element_displayed command is unknown, no point in trying again
|
71
71
|
driver.options[:native_displayed] = false
|
@@ -106,7 +106,11 @@ private
|
|
106
106
|
|
107
107
|
def file_errors
|
108
108
|
@file_errors = ::Selenium::WebDriver.logger.suppress_deprecations do
|
109
|
-
|
109
|
+
if defined? ::Selenium::WebDriver::Error::ExpectedError # Selenium < 4
|
110
|
+
[::Selenium::WebDriver::Error::ExpectedError]
|
111
|
+
else
|
112
|
+
[]
|
113
|
+
end
|
110
114
|
end
|
111
115
|
end
|
112
116
|
|
@@ -38,7 +38,7 @@ class Capybara::Selenium::EdgeNode < Capybara::Selenium::Node
|
|
38
38
|
html5_drop(*args)
|
39
39
|
end
|
40
40
|
|
41
|
-
def click(
|
41
|
+
def click(*, **)
|
42
42
|
super
|
43
43
|
rescue Selenium::WebDriver::Error::InvalidArgumentError => e
|
44
44
|
tag_name, type = attrs(:tagName, :type).map { |val| val&.downcase }
|
@@ -69,7 +69,7 @@ class Capybara::Selenium::EdgeNode < Capybara::Selenium::Node
|
|
69
69
|
return super unless chrome_edge? && native_displayed?
|
70
70
|
|
71
71
|
begin
|
72
|
-
bridge.send(:execute, :is_element_displayed, id:
|
72
|
+
bridge.send(:execute, :is_element_displayed, id: native_id)
|
73
73
|
rescue Selenium::WebDriver::Error::UnknownCommandError
|
74
74
|
# If the is_element_displayed command is unknown, no point in trying again
|
75
75
|
driver.options[:native_displayed] = false
|
@@ -77,11 +77,33 @@ class Capybara::Selenium::EdgeNode < Capybara::Selenium::Node
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def send_keys(*args)
|
81
|
+
args.chunk { |inp| inp.is_a?(String) && inp.match?(/\p{Emoji Presentation}/) }
|
82
|
+
.each do |contains_emoji, inputs|
|
83
|
+
if contains_emoji
|
84
|
+
inputs.join.grapheme_clusters.chunk { |gc| gc.match?(/\p{Emoji Presentation}/) }
|
85
|
+
.each do |emoji, clusters|
|
86
|
+
if emoji
|
87
|
+
driver.send(:execute_cdp, 'Input.insertText', text: clusters.join)
|
88
|
+
else
|
89
|
+
super(clusters.join)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
else
|
93
|
+
super(*inputs)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
80
98
|
private
|
81
99
|
|
82
100
|
def file_errors
|
83
101
|
@file_errors = ::Selenium::WebDriver.logger.suppress_deprecations do
|
84
|
-
|
102
|
+
if defined? ::Selenium::WebDriver::Error::ExpectedError # Selenium < 4
|
103
|
+
[::Selenium::WebDriver::Error::ExpectedError]
|
104
|
+
else
|
105
|
+
[]
|
106
|
+
end
|
85
107
|
end
|
86
108
|
end
|
87
109
|
|
@@ -11,8 +11,8 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
11
11
|
super
|
12
12
|
rescue ::Selenium::WebDriver::Error::ElementNotInteractableError
|
13
13
|
if tag_name == 'tr'
|
14
|
-
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - '\
|
15
|
-
'see https://github.com/mozilla/geckodriver/issues/1228
|
14
|
+
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - ' \
|
15
|
+
'see https://github.com/mozilla/geckodriver/issues/1228 - Your test should probably be ' \
|
16
16
|
'clicking on a table cell like a user would. Clicking the first cell in the row instead.'
|
17
17
|
return find_css('th:first-child,td:first-child')[0].click(keys, **options)
|
18
18
|
end
|
@@ -76,7 +76,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
76
76
|
return super unless native_displayed?
|
77
77
|
|
78
78
|
begin
|
79
|
-
bridge.send(:execute, :is_element_displayed, id:
|
79
|
+
bridge.send(:execute, :is_element_displayed, id: native_id)
|
80
80
|
rescue Selenium::WebDriver::Error::UnknownCommandError
|
81
81
|
# If the is_element_displayed command is unknown, no point in trying again
|
82
82
|
driver.options[:native_displayed] = false
|
@@ -11,10 +11,10 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
|
|
11
11
|
super
|
12
12
|
rescue ::Selenium::WebDriver::Error::ElementNotInteractableError
|
13
13
|
if tag_name == 'tr'
|
14
|
-
warn 'You are attempting to click a table row which has issues in safaridriver - '\
|
15
|
-
'Your test should probably be clicking on a table cell like a user would. '\
|
14
|
+
warn 'You are attempting to click a table row which has issues in safaridriver - ' \
|
15
|
+
'Your test should probably be clicking on a table cell like a user would. ' \
|
16
16
|
'Clicking the first cell in the row instead.'
|
17
|
-
return find_css('th:first-child,td:first-child')[0].click(keys, options)
|
17
|
+
return find_css('th:first-child,td:first-child')[0].click(keys, **options)
|
18
18
|
end
|
19
19
|
raise
|
20
20
|
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
@@ -74,7 +74,7 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
|
|
74
74
|
if clear == :backspace
|
75
75
|
# Clear field by sending the correct number of backspace keys.
|
76
76
|
backspaces = [:backspace] * self.value.to_s.length
|
77
|
-
send_keys(
|
77
|
+
send_keys([:control, 'e'], *backspaces, value)
|
78
78
|
else
|
79
79
|
super.tap do
|
80
80
|
# React doesn't see the safaridriver element clear
|
@@ -20,7 +20,7 @@ module ActionPauser
|
|
20
20
|
private_constant :Pauser
|
21
21
|
end
|
22
22
|
|
23
|
-
if defined?(
|
24
|
-
defined?(
|
25
|
-
|
23
|
+
if defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f < 4) &&
|
24
|
+
defined?(Selenium::WebDriver::ActionBuilder)
|
25
|
+
Selenium::WebDriver::ActionBuilder.prepend(ActionPauser)
|
26
26
|
end
|
@@ -16,48 +16,65 @@ module Capybara
|
|
16
16
|
|
17
17
|
def initialize(app)
|
18
18
|
@app = app
|
19
|
-
@
|
19
|
+
@disable_css_markup = format(DISABLE_CSS_MARKUP_TEMPLATE,
|
20
|
+
selector: self.class.selector_for(Capybara.disable_animation))
|
21
|
+
@disable_js_markup = +DISABLE_JS_MARKUP_TEMPLATE
|
20
22
|
end
|
21
23
|
|
22
24
|
def call(env)
|
23
|
-
|
24
|
-
return [
|
25
|
+
status, headers, body = @app.call(env)
|
26
|
+
return [status, headers, body] unless html_content?(headers)
|
25
27
|
|
26
|
-
|
28
|
+
nonces = directive_nonces(headers).transform_values { |nonce| "nonce=\"#{nonce}\"" if nonce && !nonce.empty? }
|
29
|
+
response = Rack::Response.new([], status, headers)
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
body.each { |html| response.write insert_disable(html, nonces) }
|
32
|
+
body.close if body.respond_to?(:close)
|
30
33
|
|
31
34
|
response.finish
|
32
35
|
end
|
33
36
|
|
34
37
|
private
|
35
38
|
|
36
|
-
attr_reader :
|
39
|
+
attr_reader :disable_css_markup, :disable_js_markup
|
37
40
|
|
38
|
-
def html_content?
|
39
|
-
/html/.match?(
|
41
|
+
def html_content?(headers)
|
42
|
+
/html/.match?(headers['Content-Type']) # rubocop:todo Performance/StringInclude
|
40
43
|
end
|
41
44
|
|
42
|
-
def insert_disable(html)
|
43
|
-
html.sub(%r{(</
|
45
|
+
def insert_disable(html, nonces)
|
46
|
+
html.sub(%r{(</head>)}, "<style #{nonces['style-src']}>#{disable_css_markup}</style>\\1")
|
47
|
+
.sub(%r{(</body>)}, "<script #{nonces['script-src']}>#{disable_js_markup}</script>\\1")
|
44
48
|
end
|
45
49
|
|
46
|
-
|
47
|
-
|
50
|
+
def directive_nonces(headers)
|
51
|
+
headers.fetch('Content-Security-Policy', '')
|
52
|
+
.split(';')
|
53
|
+
.map(&:split)
|
54
|
+
.to_h do |s|
|
55
|
+
[
|
56
|
+
s[0], s[1..].filter_map do |value|
|
57
|
+
/^'nonce-(?<nonce>.+)'/ =~ value
|
58
|
+
nonce
|
59
|
+
end[0]
|
60
|
+
]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
DISABLE_CSS_MARKUP_TEMPLATE = <<~CSS
|
65
|
+
%<selector>s, %<selector>s::before, %<selector>s::after {
|
66
|
+
transition: none !important;
|
67
|
+
animation-duration: 0s !important;
|
68
|
+
animation-delay: 0s !important;
|
69
|
+
scroll-behavior: auto !important;
|
70
|
+
}
|
71
|
+
CSS
|
72
|
+
|
73
|
+
DISABLE_JS_MARKUP_TEMPLATE = <<~SCRIPT
|
48
74
|
//<![CDATA[
|
49
75
|
(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);
|
50
76
|
//]]>
|
51
|
-
|
52
|
-
<style>
|
53
|
-
%<selector>s, %<selector>s::before, %<selector>s::after {
|
54
|
-
transition: none !important;
|
55
|
-
animation-duration: 0s !important;
|
56
|
-
animation-delay: 0s !important;
|
57
|
-
scroll-behavior: auto !important;
|
58
|
-
}
|
59
|
-
</style>
|
60
|
-
HTML
|
77
|
+
SCRIPT
|
61
78
|
end
|
62
79
|
end
|
63
80
|
end
|
@@ -8,7 +8,7 @@ module Capybara
|
|
8
8
|
automatic_reload match exact exact_text raise_server_errors visible_text_only
|
9
9
|
automatic_label_click enable_aria_label save_path asset_host default_host app_host
|
10
10
|
server_host server_port server_errors default_set_options disable_animation test_id
|
11
|
-
predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze
|
11
|
+
predicates_wait default_normalize_ws w3c_click_offset enable_aria_role default_retry_interval].freeze
|
12
12
|
|
13
13
|
attr_accessor(*OPTIONS)
|
14
14
|
|
@@ -21,6 +21,8 @@ module Capybara
|
|
21
21
|
# See {Capybara.configure}
|
22
22
|
# @!method default_max_wait_time
|
23
23
|
# See {Capybara.configure}
|
24
|
+
# @!method default_retry_interval
|
25
|
+
# See {Capybara.configure}
|
24
26
|
# @!method ignore_hidden_elements
|
25
27
|
# See {Capybara.configure}
|
26
28
|
# @!method automatic_reload
|
@@ -100,7 +102,7 @@ module Capybara
|
|
100
102
|
remove_method :test_id=
|
101
103
|
##
|
102
104
|
#
|
103
|
-
# Set an
|
105
|
+
# Set an attribute to be optionally matched against the locator for builtin selector types.
|
104
106
|
# This attribute will be checked by builtin selector types whenever id would normally be checked.
|
105
107
|
# If `nil` then it will be ignored.
|
106
108
|
#
|
data/lib/capybara/session.rb
CHANGED
@@ -40,6 +40,7 @@ module Capybara
|
|
40
40
|
|
41
41
|
NODE_METHODS = %i[
|
42
42
|
all first attach_file text check choose scroll_to scroll_by
|
43
|
+
click double_click right_click
|
43
44
|
click_link_or_button click_button click_link
|
44
45
|
fill_in find find_all find_button find_by_id find_field find_link
|
45
46
|
has_content? has_text? has_css? has_no_content? has_no_text?
|
@@ -58,7 +59,7 @@ module Capybara
|
|
58
59
|
].freeze
|
59
60
|
SESSION_METHODS = %i[
|
60
61
|
body html source current_url current_host current_path
|
61
|
-
execute_script evaluate_script visit refresh go_back go_forward send_keys
|
62
|
+
execute_script evaluate_script evaluate_async_script visit refresh go_back go_forward send_keys
|
62
63
|
within within_element within_fieldset within_table within_frame switch_to_frame
|
63
64
|
current_window windows open_new_window switch_to_window within_window window_opened_by
|
64
65
|
save_page save_and_open_page save_screenshot
|
@@ -129,6 +130,8 @@ module Capybara
|
|
129
130
|
if @touched
|
130
131
|
driver.reset!
|
131
132
|
@touched = false
|
133
|
+
switch_to_frame(:top) rescue nil # rubocop:disable Style/RescueModifier
|
134
|
+
@scopes = [nil]
|
132
135
|
end
|
133
136
|
@server&.wait_for_pending_requests
|
134
137
|
raise_server_error!
|
@@ -159,9 +162,8 @@ module Capybara
|
|
159
162
|
if config.raise_server_errors
|
160
163
|
raise CapybaraError, 'Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true'
|
161
164
|
end
|
162
|
-
rescue CapybaraError
|
163
|
-
|
164
|
-
raise @server.error, @server.error.message, @server.error.backtrace
|
165
|
+
rescue CapybaraError => capy_error # rubocop:disable Naming/RescuedExceptionsVariableName
|
166
|
+
raise @server.error, cause: capy_error
|
165
167
|
ensure
|
166
168
|
@server.reset_error!
|
167
169
|
end
|
@@ -311,6 +313,16 @@ module Capybara
|
|
311
313
|
driver.send_keys(*args, **kw_args)
|
312
314
|
end
|
313
315
|
|
316
|
+
##
|
317
|
+
#
|
318
|
+
# Returns the element with focus.
|
319
|
+
#
|
320
|
+
# Not supported by Rack Test
|
321
|
+
#
|
322
|
+
def active_element
|
323
|
+
Capybara::Queries::ActiveElementQuery.new.resolve_for(self)[0].tap(&:allow_reload!)
|
324
|
+
end
|
325
|
+
|
314
326
|
##
|
315
327
|
#
|
316
328
|
# Executes the given block within the context of a node. {#within} takes the
|
@@ -350,7 +362,7 @@ module Capybara
|
|
350
362
|
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
|
351
363
|
begin
|
352
364
|
scopes.push(new_scope)
|
353
|
-
yield if block_given?
|
365
|
+
yield new_scope if block_given?
|
354
366
|
ensure
|
355
367
|
scopes.pop
|
356
368
|
end
|
@@ -399,7 +411,7 @@ module Capybara
|
|
399
411
|
scopes.push(:frame)
|
400
412
|
when :parent
|
401
413
|
if scopes.last != :frame
|
402
|
-
raise Capybara::ScopeError, "`switch_to_frame(:parent)` cannot be called from inside a descendant frame's "\
|
414
|
+
raise Capybara::ScopeError, "`switch_to_frame(:parent)` cannot be called from inside a descendant frame's " \
|
403
415
|
'`within` block.'
|
404
416
|
end
|
405
417
|
scopes.pop
|
@@ -408,11 +420,11 @@ module Capybara
|
|
408
420
|
idx = scopes.index(:frame)
|
409
421
|
top_level_scopes = [:frame, nil]
|
410
422
|
if idx
|
411
|
-
if scopes.slice(idx
|
412
|
-
raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's "\
|
423
|
+
if scopes.slice(idx..).any? { |scope| !top_level_scopes.include?(scope) }
|
424
|
+
raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's " \
|
413
425
|
'`within` block.'
|
414
426
|
end
|
415
|
-
scopes.slice!(idx
|
427
|
+
scopes.slice!(idx..)
|
416
428
|
driver.switch_to_frame(:top)
|
417
429
|
end
|
418
430
|
else
|
@@ -501,7 +513,7 @@ module Capybara
|
|
501
513
|
raise ArgumentError, '`switch_to_window`: either window or block should be provided' if !window && !window_locator
|
502
514
|
|
503
515
|
unless scopes.last.nil?
|
504
|
-
raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from '\
|
516
|
+
raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from ' \
|
505
517
|
'`within` or `within_frame` blocks.'
|
506
518
|
end
|
507
519
|
|
@@ -572,7 +584,7 @@ module Capybara
|
|
572
584
|
synchronize_windows(options) do
|
573
585
|
opened_handles = (driver.window_handles - old_handles)
|
574
586
|
if opened_handles.size != 1
|
575
|
-
raise Capybara::WindowError, 'block passed to #window_opened_by '\
|
587
|
+
raise Capybara::WindowError, 'block passed to #window_opened_by ' \
|
576
588
|
"opened #{opened_handles.size} windows instead of 1"
|
577
589
|
end
|
578
590
|
Window.new(self, opened_handles.first)
|
@@ -755,33 +767,20 @@ module Capybara
|
|
755
767
|
end
|
756
768
|
|
757
769
|
NODE_METHODS.each do |method|
|
758
|
-
|
759
|
-
|
760
|
-
def #{method}(...)
|
761
|
-
@touched = true
|
762
|
-
current_scope.#{method}(...)
|
763
|
-
end
|
764
|
-
METHOD
|
765
|
-
else
|
766
|
-
define_method method do |*args, &block|
|
770
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
771
|
+
def #{method}(...)
|
767
772
|
@touched = true
|
768
|
-
current_scope
|
773
|
+
current_scope.#{method}(...)
|
769
774
|
end
|
770
|
-
|
775
|
+
METHOD
|
771
776
|
end
|
772
777
|
|
773
778
|
DOCUMENT_METHODS.each do |method|
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
document.#{method}(...)
|
778
|
-
end
|
779
|
-
METHOD
|
780
|
-
else
|
781
|
-
define_method method do |*args, &block|
|
782
|
-
document.send(method, *args, &block)
|
779
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
780
|
+
def #{method}(...)
|
781
|
+
document.#{method}(...)
|
783
782
|
end
|
784
|
-
|
783
|
+
METHOD
|
785
784
|
end
|
786
785
|
|
787
786
|
def inspect
|
@@ -44,6 +44,10 @@ $(function() {
|
|
44
44
|
$(this).after('<div class="log">DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
|
45
45
|
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
46
46
|
});
|
47
|
+
$('#drop_html5, #drop_html5_scroll').on('dragenter', function(ev){
|
48
|
+
$(this).after('<div class="log">DragEnter')
|
49
|
+
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|
50
|
+
});
|
47
51
|
$('#drop_html5, #drop_html5_scroll').on('dragleave', function(ev){
|
48
52
|
$(this).after('<div class="log">DragLeave with client position: ' + ev.clientX + ',' + ev.clientY)
|
49
53
|
if ($(this).hasClass('drop')) { ev.preventDefault(); }
|