capybara 3.37.1 → 3.39.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +68 -4
- data/README.md +23 -11
- data/lib/capybara/helpers.rb +5 -1
- data/lib/capybara/node/actions.rb +4 -4
- data/lib/capybara/node/base.rb +2 -1
- data/lib/capybara/node/finders.rb +2 -0
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/base_query.rb +2 -2
- data/lib/capybara/queries/selector_query.rb +4 -2
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +8 -2
- data/lib/capybara/rack_test/form.rb +29 -7
- data/lib/capybara/rack_test/node.rb +18 -15
- data/lib/capybara/registrations/drivers.rb +3 -3
- data/lib/capybara/registrations/servers.rb +30 -10
- data/lib/capybara/rspec/matcher_proxies.rb +3 -3
- data/lib/capybara/rspec/matchers/base.rb +8 -6
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +2 -1
- data/lib/capybara/selector/definition.rb +1 -1
- data/lib/capybara/selector/filter_set.rb +4 -5
- data/lib/capybara/selector/regexp_disassembler.rb +2 -5
- data/lib/capybara/selenium/driver.rb +6 -3
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +8 -4
- 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 +6 -2
- data/lib/capybara/selenium/node.rb +61 -26
- data/lib/capybara/selenium/nodes/chrome_node.rb +5 -1
- data/lib/capybara/selenium/nodes/edge_node.rb +24 -2
- data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
- data/lib/capybara/selenium/nodes/safari_node.rb +2 -2
- 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 +21 -22
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/session/config.rb +3 -1
- data/lib/capybara/session.rb +11 -9
- data/lib/capybara/spec/public/test.js +4 -0
- data/lib/capybara/spec/session/all_spec.rb +1 -1
- data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
- data/lib/capybara/spec/session/check_spec.rb +1 -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 +2 -2
- 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 +2 -2
- data/lib/capybara/spec/session/has_button_spec.rb +6 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +1 -1
- data/lib/capybara/spec/session/has_link_spec.rb +10 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +6 -0
- data/lib/capybara/spec/session/has_text_spec.rb +4 -8
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -0
- data/lib/capybara/spec/session/node_spec.rb +40 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +13 -0
- data/lib/capybara/spec/session/scroll_spec.rb +3 -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 +8 -2
- data/lib/capybara/spec/test_app.rb +25 -6
- data/lib/capybara/spec/views/form.erb +17 -0
- data/lib/capybara/spec/views/with_html.erb +3 -3
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +4 -2
- 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 +2 -0
- 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 +10 -2
- data/spec/rspec/scenarios_spec.rb +1 -1
- data/spec/rspec/shared_spec_matchers.rb +1 -1
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +2 -2
- data/spec/sauce_spec_chrome.rb +1 -1
- data/spec/selector_spec.rb +2 -2
- data/spec/selenium_spec_chrome.rb +7 -6
- data/spec/selenium_spec_chrome_remote.rb +9 -9
- data/spec/selenium_spec_edge.rb +12 -6
- data/spec/selenium_spec_firefox.rb +20 -8
- data/spec/selenium_spec_firefox_remote.rb +19 -4
- data/spec/selenium_spec_ie.rb +4 -2
- data/spec/selenium_spec_safari.rb +3 -1
- data/spec/server_spec.rb +2 -2
- data/spec/shared_selenium_session.rb +5 -5
- data/spec/spec_helper.rb +34 -1
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +1 -1
- metadata +5 -2
@@ -36,7 +36,7 @@ if RUBY_ENGINE == 'jruby'
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
if defined?(
|
39
|
+
if defined?(RSpec::Matchers)
|
40
40
|
module ::RSpec::Matchers
|
41
41
|
def self.included(base)
|
42
42
|
base.send(:include, ::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
|
@@ -76,7 +76,7 @@ else
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
Capybara::DSL.prepend
|
79
|
+
Capybara::DSL.prepend Capybara::DSLRSpecProxyInstaller
|
80
80
|
|
81
|
-
|
81
|
+
RSpec::Matchers.prepend Capybara::RSpecMatcherProxyInstaller if defined?(RSpec::Matchers)
|
82
82
|
end
|
@@ -47,14 +47,16 @@ module Capybara
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class WrappedElementMatcher < Base
|
50
|
-
def matches?(actual)
|
50
|
+
def matches?(actual, &filter_block)
|
51
|
+
@filter_block ||= filter_block
|
51
52
|
element_matches?(wrap(actual))
|
52
53
|
rescue Capybara::ExpectationNotMet => e
|
53
54
|
@failure_message = e.message
|
54
55
|
false
|
55
56
|
end
|
56
57
|
|
57
|
-
def does_not_match?(actual)
|
58
|
+
def does_not_match?(actual, &filter_block)
|
59
|
+
@filter_block ||= filter_block
|
58
60
|
element_does_not_match?(wrap(actual))
|
59
61
|
rescue Capybara::ExpectationNotMet => e
|
60
62
|
@failure_message_when_negated = e.message
|
@@ -86,12 +88,12 @@ module Capybara
|
|
86
88
|
@matcher = matcher
|
87
89
|
end
|
88
90
|
|
89
|
-
def matches?(actual)
|
90
|
-
@matcher.does_not_match?(actual)
|
91
|
+
def matches?(actual, &filter_block)
|
92
|
+
@matcher.does_not_match?(actual, &filter_block)
|
91
93
|
end
|
92
94
|
|
93
|
-
def does_not_match?(actual)
|
94
|
-
@matcher.matches?(actual)
|
95
|
+
def does_not_match?(actual, &filter_block)
|
96
|
+
@matcher.matches?(actual, &filter_block)
|
95
97
|
end
|
96
98
|
|
97
99
|
def description
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara.add_selector(:link, locator_type: [String, Symbol]) do
|
4
|
-
xpath do |locator, href: true, alt: nil, title: nil, **|
|
4
|
+
xpath do |locator, href: true, alt: nil, title: nil, target: nil, **|
|
5
5
|
xpath = XPath.descendant(:a)
|
6
6
|
xpath = builder(xpath).add_attribute_conditions(href: href) unless href == false
|
7
7
|
|
@@ -25,6 +25,7 @@ Capybara.add_selector(:link, locator_type: [String, Symbol]) do
|
|
25
25
|
|
26
26
|
xpath = xpath[find_by_attr(:title, title)]
|
27
27
|
xpath = xpath[XPath.descendant(:img)[XPath.attr(:alt) == alt]] if alt
|
28
|
+
xpath = xpath[find_by_attr(:target, target)] if target
|
28
29
|
|
29
30
|
xpath
|
30
31
|
end
|
@@ -203,7 +203,7 @@ module Capybara
|
|
203
203
|
|
204
204
|
##
|
205
205
|
#
|
206
|
-
# Set the default visibility mode that
|
206
|
+
# Set the default visibility mode that should be used if no visible option is passed when using the selector.
|
207
207
|
# If not specified will default to the behavior indicated by Capybara.ignore_hidden_elements
|
208
208
|
#
|
209
209
|
# @param [Symbol] default_visibility Only find elements with the specified visibility:
|
@@ -101,11 +101,10 @@ module Capybara
|
|
101
101
|
private
|
102
102
|
|
103
103
|
def options_with_defaults(options)
|
104
|
-
expression_filters
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
104
|
+
expression_filters
|
105
|
+
.chain(node_filters)
|
106
|
+
.filter_map { |name, filter| [name, filter.default] if filter.default? }
|
107
|
+
.to_h.merge!(options)
|
109
108
|
end
|
110
109
|
|
111
110
|
def add_filter(name, filter_class, *types, matcher: nil, **options, &block)
|
@@ -69,11 +69,8 @@ module Capybara
|
|
69
69
|
suffixes = [[]]
|
70
70
|
strs.reverse_each do |str|
|
71
71
|
if str.is_a? Set
|
72
|
-
prefixes = str.
|
73
|
-
|
74
|
-
result = []
|
75
|
-
prefixes.product(suffixes) { |pair| result << pair.flatten(1) }
|
76
|
-
suffixes = result
|
72
|
+
prefixes = str.flat_map { |s| combine(s) }
|
73
|
+
suffixes = prefixes.product(suffixes).map { |pair| pair.flatten(1) }
|
77
74
|
else
|
78
75
|
suffixes.each { |arr| arr.unshift str }
|
79
76
|
end
|
@@ -12,7 +12,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|
12
12
|
clear_session_storage: nil
|
13
13
|
}.freeze
|
14
14
|
SPECIAL_OPTIONS = %i[browser clear_local_storage clear_session_storage timeout native_displayed].freeze
|
15
|
-
CAPS_VERSION = Gem::Requirement.new('
|
15
|
+
CAPS_VERSION = Gem::Requirement.new('> 4.0.0.alpha6', '< 4.8.0')
|
16
16
|
|
17
17
|
attr_reader :app, :options
|
18
18
|
|
@@ -315,14 +315,17 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|
315
315
|
].tap do |errors|
|
316
316
|
unless selenium_4?
|
317
317
|
::Selenium::WebDriver.logger.suppress_deprecations do
|
318
|
-
errors.
|
318
|
+
errors.push(
|
319
319
|
::Selenium::WebDriver::Error::UnhandledError,
|
320
320
|
::Selenium::WebDriver::Error::ElementNotVisibleError,
|
321
321
|
::Selenium::WebDriver::Error::InvalidElementStateError,
|
322
322
|
::Selenium::WebDriver::Error::ElementNotSelectableError
|
323
|
-
|
323
|
+
)
|
324
324
|
end
|
325
325
|
end
|
326
|
+
if defined?(::Selenium::WebDriver::Error::DetachedShadowRootError)
|
327
|
+
errors.push(::Selenium::WebDriver::Error::DetachedShadowRootError)
|
328
|
+
end
|
326
329
|
end
|
327
330
|
end
|
328
331
|
|
@@ -103,9 +103,13 @@ private
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def execute_cdp(cmd, params = {})
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
if browser.respond_to? :execute_cdp
|
107
|
+
browser.execute_cdp(cmd, **params)
|
108
|
+
else
|
109
|
+
args = { cmd: cmd, params: params }
|
110
|
+
result = bridge.http.call(:post, "session/#{bridge.session_id}/ms/cdp/execute", args)
|
111
|
+
result['value']
|
112
|
+
end
|
109
113
|
end
|
110
114
|
|
111
115
|
def build_node(native_node, initial_cache = {})
|
@@ -115,7 +119,7 @@ private
|
|
115
119
|
def edgedriver_version
|
116
120
|
@edgedriver_version ||= begin
|
117
121
|
caps = browser.capabilities
|
118
|
-
caps['
|
122
|
+
caps['msedge']&.fetch('msedgedriverVersion', nil).to_f
|
119
123
|
end
|
120
124
|
end
|
121
125
|
end
|
@@ -10,7 +10,7 @@ module Capybara::Selenium::Driver::FirefoxDriver
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.w3c?(driver)
|
13
|
-
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION
|
13
|
+
(defined?(Selenium::WebDriver::VERSION) && (Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4'))) ||
|
14
14
|
driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
15
15
|
end
|
16
16
|
end
|
@@ -39,10 +39,8 @@ class Capybara::Selenium::Node
|
|
39
39
|
input.set_file(args)
|
40
40
|
driver.execute_script DROP_FILE, self, input
|
41
41
|
else
|
42
|
-
items = args.
|
43
|
-
arg.
|
44
|
-
arr_ << { type: type, data: data }
|
45
|
-
end
|
42
|
+
items = args.flat_map do |arg|
|
43
|
+
arg.map { |(type, data)| { type: type, data: data } }
|
46
44
|
end
|
47
45
|
driver.execute_script DROP_STRING, items, self
|
48
46
|
end
|
@@ -168,6 +166,9 @@ class Capybara::Selenium::Node
|
|
168
166
|
opts[key + 'Key'] = true;
|
169
167
|
}
|
170
168
|
|
169
|
+
var dragEnterEvent = new DragEvent('dragenter', opts);
|
170
|
+
target.dispatchEvent(dragEnterEvent);
|
171
|
+
|
171
172
|
// fire 2 dragover events to simulate dragging with a direction
|
172
173
|
var entryPoint = pointOnRect(sourceCenter, targetRect)
|
173
174
|
var dragOverOpts = Object.assign({clientX: entryPoint.x, clientY: entryPoint.y}, opts);
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Capybara
|
4
4
|
module Selenium
|
5
5
|
module DeprecationSuppressor
|
6
|
-
def initialize(
|
6
|
+
def initialize(...)
|
7
7
|
@suppress_for_capybara = false
|
8
8
|
super
|
9
9
|
end
|
@@ -18,6 +18,10 @@ module Capybara
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def warn(*args, **opts)
|
22
|
+
super unless @suppress_for_capybara
|
23
|
+
end
|
24
|
+
|
21
25
|
def suppress_deprecations
|
22
26
|
prev_suppress_for_capybara, @suppress_for_capybara = @suppress_for_capybara, true
|
23
27
|
yield
|
@@ -27,7 +31,7 @@ module Capybara
|
|
27
31
|
end
|
28
32
|
|
29
33
|
module ErrorSuppressor
|
30
|
-
def for_code(
|
34
|
+
def for_code(...)
|
31
35
|
::Selenium::WebDriver.logger.suppress_deprecations do
|
32
36
|
super
|
33
37
|
end
|
@@ -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
21
|
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", ' ')
|
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
|
##
|
@@ -115,11 +113,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
115
113
|
action.click(target)
|
116
114
|
else
|
117
115
|
action.click_and_hold(target)
|
118
|
-
|
119
|
-
action.pause(action.pointer_inputs.first, click_options.delay)
|
120
|
-
else
|
121
|
-
action.pause(click_options.delay)
|
122
|
-
end
|
116
|
+
action_pause(action, click_options.delay)
|
123
117
|
action.release
|
124
118
|
end
|
125
119
|
end
|
@@ -140,9 +134,9 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
140
134
|
action.context_click(target)
|
141
135
|
elsif w3c?
|
142
136
|
action.move_to(target) if target
|
143
|
-
action.pointer_down(:right)
|
144
|
-
|
145
|
-
|
137
|
+
action.pointer_down(:right).then do |act|
|
138
|
+
action_pause(act, click_options.delay)
|
139
|
+
end.pointer_up(:right)
|
146
140
|
else
|
147
141
|
raise ArgumentError, 'Delay is not supported when right clicking with legacy (non-w3c) selenium driver'
|
148
142
|
end
|
@@ -184,7 +178,12 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
184
178
|
end
|
185
179
|
|
186
180
|
def tag_name
|
187
|
-
@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
|
188
187
|
end
|
189
188
|
|
190
189
|
def visible?; boolean_attr(native.displayed?); end
|
@@ -220,7 +219,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|
220
219
|
end
|
221
220
|
|
222
221
|
def shadow_root
|
223
|
-
|
222
|
+
raise 'You must be using Selenium 4.1+ for shadow_root support' unless native.respond_to? :shadow_root
|
224
223
|
|
225
224
|
root = native.shadow_root
|
226
225
|
root && build_node(native.shadow_root)
|
@@ -236,7 +235,7 @@ protected
|
|
236
235
|
end
|
237
236
|
|
238
237
|
def scroll_to_center
|
239
|
-
script = <<-
|
238
|
+
script = <<-JS
|
240
239
|
try {
|
241
240
|
arguments[0].scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'});
|
242
241
|
} catch(e) {
|
@@ -415,10 +414,30 @@ private
|
|
415
414
|
|
416
415
|
def action_with_modifiers(click_options)
|
417
416
|
actions = browser_action.tap do |acts|
|
418
|
-
if click_options.
|
419
|
-
|
417
|
+
if click_options.coords?
|
418
|
+
if click_options.center_offset?
|
419
|
+
if Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('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 Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('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
|
420
439
|
else
|
421
|
-
acts.move_to(native
|
440
|
+
acts.move_to(native)
|
422
441
|
end
|
423
442
|
end
|
424
443
|
modifiers_down(actions, click_options.keys)
|
@@ -457,10 +476,22 @@ private
|
|
457
476
|
end
|
458
477
|
|
459
478
|
def w3c?
|
460
|
-
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION
|
479
|
+
(defined?(Selenium::WebDriver::VERSION) && (Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4'))) ||
|
461
480
|
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
462
481
|
end
|
463
482
|
|
483
|
+
def action_pause(action, duration)
|
484
|
+
if w3c?
|
485
|
+
if Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('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
|
+
|
464
495
|
def normalize_keys(keys)
|
465
496
|
keys.map do |key|
|
466
497
|
case key
|
@@ -487,7 +518,7 @@ private
|
|
487
518
|
def attrs(*attr_names)
|
488
519
|
return attr_names.map { |name| self[name.to_s] } if ENV['CAPYBARA_THOROUGH']
|
489
520
|
|
490
|
-
driver.evaluate_script <<~
|
521
|
+
driver.evaluate_script <<~JS, self, attr_names.map(&:to_s)
|
491
522
|
(function(el, names){
|
492
523
|
return names.map(function(name){
|
493
524
|
return el[name]
|
@@ -502,6 +533,10 @@ private
|
|
502
533
|
id || type_or_id
|
503
534
|
end
|
504
535
|
|
536
|
+
def shadow_root?
|
537
|
+
defined?(::Selenium::WebDriver::ShadowRoot) && native.is_a?(::Selenium::WebDriver::ShadowRoot)
|
538
|
+
end
|
539
|
+
|
505
540
|
GET_XPATH_SCRIPT = <<~'JS'
|
506
541
|
(function(el, xml){
|
507
542
|
var xpath = '';
|
@@ -534,7 +569,7 @@ private
|
|
534
569
|
})(arguments[0], document)
|
535
570
|
JS
|
536
571
|
|
537
|
-
OBSCURED_OR_OFFSET_SCRIPT = <<~
|
572
|
+
OBSCURED_OR_OFFSET_SCRIPT = <<~JS
|
538
573
|
(function(el, x, y) {
|
539
574
|
var box = el.getBoundingClientRect();
|
540
575
|
if (x == null) x = box.width/2;
|
@@ -551,7 +586,7 @@ private
|
|
551
586
|
})(arguments[0], arguments[1], arguments[2])
|
552
587
|
JS
|
553
588
|
|
554
|
-
RAPID_APPEND_TEXT = <<~
|
589
|
+
RAPID_APPEND_TEXT = <<~JS
|
555
590
|
(function(el, value) {
|
556
591
|
value = el.value + value;
|
557
592
|
if (el.maxLength && el.maxLength != -1){
|
@@ -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 }
|
@@ -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
|
@@ -11,8 +11,8 @@ 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
17
|
return find_css('th:first-child,td:first-child')[0].click(keys, **options)
|
18
18
|
end
|
@@ -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) && (Gem::Version.new(Selenium::WebDriver::VERSION) < Gem::Version.new('4')) &&
|
24
|
+
defined?(Selenium::WebDriver::ActionBuilder)
|
25
|
+
Selenium::WebDriver::ActionBuilder.prepend(ActionPauser)
|
26
26
|
end
|
@@ -18,19 +18,18 @@ module Capybara
|
|
18
18
|
@app = app
|
19
19
|
@disable_css_markup = format(DISABLE_CSS_MARKUP_TEMPLATE,
|
20
20
|
selector: self.class.selector_for(Capybara.disable_animation))
|
21
|
-
@disable_js_markup =
|
22
|
-
selector: self.class.selector_for(Capybara.disable_animation))
|
21
|
+
@disable_js_markup = +DISABLE_JS_MARKUP_TEMPLATE
|
23
22
|
end
|
24
23
|
|
25
24
|
def call(env)
|
26
|
-
|
27
|
-
return [
|
25
|
+
status, headers, body = @app.call(env)
|
26
|
+
return [status, headers, body] unless html_content?(headers)
|
28
27
|
|
29
|
-
nonces = directive_nonces.transform_values { |nonce| "nonce=\"#{nonce}\"" if nonce && !nonce.empty? }
|
30
|
-
response = Rack::Response.new([],
|
28
|
+
nonces = directive_nonces(headers).transform_values { |nonce| "nonce=\"#{nonce}\"" if nonce && !nonce.empty? }
|
29
|
+
response = Rack::Response.new([], status, headers)
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
body.each { |html| response.write insert_disable(html, nonces) }
|
32
|
+
body.close if body.respond_to?(:close)
|
34
33
|
|
35
34
|
response.finish
|
36
35
|
end
|
@@ -39,8 +38,8 @@ module Capybara
|
|
39
38
|
|
40
39
|
attr_reader :disable_css_markup, :disable_js_markup
|
41
40
|
|
42
|
-
def html_content?
|
43
|
-
/html/.match?(
|
41
|
+
def html_content?(headers)
|
42
|
+
/html/.match?(headers['Content-Type']) # rubocop:todo Performance/StringInclude
|
44
43
|
end
|
45
44
|
|
46
45
|
def insert_disable(html, nonces)
|
@@ -48,18 +47,18 @@ module Capybara
|
|
48
47
|
.sub(%r{(</body>)}, "<script #{nonces['script-src']}>#{disable_js_markup}</script>\\1")
|
49
48
|
end
|
50
49
|
|
51
|
-
def directive_nonces
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
63
62
|
end
|
64
63
|
|
65
64
|
DISABLE_CSS_MARKUP_TEMPLATE = <<~CSS
|
@@ -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
|