capybara 3.29.0 → 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/History.md +91 -1
- data/README.md +10 -3
- data/lib/capybara.rb +17 -7
- data/lib/capybara/config.rb +7 -3
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +3 -1
- data/lib/capybara/minitest.rb +232 -144
- data/lib/capybara/minitest/spec.rb +153 -97
- data/lib/capybara/node/actions.rb +35 -35
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +23 -16
- data/lib/capybara/node/finders.rb +17 -11
- data/lib/capybara/node/matchers.rb +64 -51
- data/lib/capybara/node/simple.rb +4 -2
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/selector_query.rb +25 -5
- data/lib/capybara/queries/sibling_query.rb +1 -1
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +6 -0
- 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 +34 -9
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/servers.rb +1 -1
- data/lib/capybara/result.rb +29 -5
- data/lib/capybara/rspec/matcher_proxies.rb +4 -4
- data/lib/capybara/rspec/matchers.rb +27 -27
- data/lib/capybara/rspec/matchers/base.rb +12 -6
- data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
- data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +15 -7
- data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
- data/lib/capybara/rspec/matchers/have_text.rb +3 -3
- 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 +2 -1
- data/lib/capybara/selector.rb +34 -17
- data/lib/capybara/selector/css.rb +1 -1
- data/lib/capybara/selector/definition.rb +7 -6
- data/lib/capybara/selector/definition/button.rb +8 -2
- data/lib/capybara/selector/definition/checkbox.rb +2 -2
- data/lib/capybara/selector/definition/css.rb +3 -1
- data/lib/capybara/selector/definition/datalist_input.rb +1 -1
- data/lib/capybara/selector/definition/datalist_option.rb +1 -1
- data/lib/capybara/selector/definition/element.rb +1 -1
- data/lib/capybara/selector/definition/field.rb +1 -1
- data/lib/capybara/selector/definition/file_field.rb +1 -1
- data/lib/capybara/selector/definition/fillable_field.rb +2 -2
- data/lib/capybara/selector/definition/label.rb +4 -2
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/radio_button.rb +2 -2
- data/lib/capybara/selector/definition/select.rb +32 -13
- data/lib/capybara/selector/definition/table.rb +6 -3
- data/lib/capybara/selector/filter_set.rb +11 -9
- data/lib/capybara/selector/filters/base.rb +6 -1
- data/lib/capybara/selector/filters/locator_filter.rb +1 -1
- data/lib/capybara/selector/selector.rb +8 -2
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
- data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
- data/lib/capybara/selenium/driver.rb +22 -11
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -10
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +7 -9
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -2
- data/lib/capybara/selenium/extensions/html5_drag.rb +30 -13
- data/lib/capybara/selenium/node.rb +97 -18
- data/lib/capybara/selenium/nodes/chrome_node.rb +11 -14
- data/lib/capybara/selenium/nodes/edge_node.rb +4 -2
- data/lib/capybara/selenium/nodes/firefox_node.rb +4 -4
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/logs.rb +3 -5
- data/lib/capybara/server.rb +15 -3
- data/lib/capybara/server/checker.rb +1 -1
- data/lib/capybara/server/middleware.rb +20 -10
- data/lib/capybara/session.rb +43 -26
- data/lib/capybara/session/config.rb +9 -3
- data/lib/capybara/session/matchers.rb +6 -6
- data/lib/capybara/spec/public/test.js +69 -6
- data/lib/capybara/spec/session/all_spec.rb +60 -5
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/click_button_spec.rb +16 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
- data/lib/capybara/spec/session/find_spec.rb +31 -8
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +12 -9
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +16 -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_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +160 -29
- 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/selectors_spec.rb +15 -2
- data/lib/capybara/spec/session/window/window_spec.rb +7 -7
- data/lib/capybara/spec/spec_helper.rb +2 -2
- data/lib/capybara/spec/test_app.rb +14 -18
- data/lib/capybara/spec/views/form.erb +18 -2
- data/lib/capybara/spec/views/with_dragula.erb +3 -1
- data/lib/capybara/spec/views/with_html.erb +2 -2
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +16 -3
- data/spec/minitest_spec.rb +1 -1
- data/spec/minitest_spec_spec.rb +46 -46
- data/spec/rack_test_spec.rb +13 -1
- data/spec/regexp_dissassembler_spec.rb +40 -36
- data/spec/result_spec.rb +43 -32
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/shared_spec_matchers.rb +68 -56
- data/spec/rspec_spec.rb +4 -4
- data/spec/selector_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +9 -6
- data/spec/selenium_spec_chrome_remote.rb +2 -0
- data/spec/selenium_spec_firefox.rb +7 -2
- data/spec/server_spec.rb +65 -31
- data/spec/session_spec.rb +1 -1
- data/spec/shared_selenium_node.rb +21 -3
- data/spec/shared_selenium_session.rb +33 -14
- data/spec/spec_helper.rb +1 -1
- metadata +6 -4
@@ -18,14 +18,16 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
18
18
|
# In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
|
19
19
|
if browser_version >= 75.0
|
20
20
|
driver.execute_script(<<~JS, self)
|
21
|
-
if (arguments[0].multiple &&
|
21
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
22
22
|
arguments[0].value = null;
|
23
23
|
}
|
24
24
|
JS
|
25
25
|
end
|
26
26
|
super
|
27
27
|
rescue *file_errors => e
|
28
|
-
|
28
|
+
if e.message.match?(/File not found : .+\n.+/m)
|
29
|
+
raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload"
|
30
|
+
end
|
29
31
|
|
30
32
|
raise
|
31
33
|
end
|
@@ -34,13 +36,15 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
34
36
|
html5_drop(*args)
|
35
37
|
end
|
36
38
|
|
37
|
-
def click(
|
39
|
+
def click(*, **)
|
38
40
|
super
|
39
41
|
rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError
|
40
42
|
raise
|
41
43
|
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
42
44
|
# chromedriver 74 (at least on mac) raises the wrong error for this
|
43
|
-
|
45
|
+
if e.message.match?(/element click intercepted/)
|
46
|
+
raise ::Selenium::WebDriver::Error::ElementClickInterceptedError, e.message
|
47
|
+
end
|
44
48
|
|
45
49
|
raise
|
46
50
|
end
|
@@ -71,9 +75,11 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|
71
75
|
|
72
76
|
private
|
73
77
|
|
74
|
-
def perform_legacy_drag(element)
|
78
|
+
def perform_legacy_drag(element, drop_modifiers)
|
75
79
|
return super if chromedriver_fixed_actions_key_state? || !w3c? || element.obscured?
|
76
80
|
|
81
|
+
raise ArgumentError, 'Modifier keys are not supported while dragging in this version of Chrome.' unless drop_modifiers.empty?
|
82
|
+
|
77
83
|
# W3C Chrome/chromedriver < 77 doesn't maintain mouse button state across actions API performs
|
78
84
|
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2981
|
79
85
|
browser_action.release.perform
|
@@ -86,11 +92,6 @@ private
|
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
|
-
def w3c?
|
90
|
-
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
91
|
-
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
92
|
-
end
|
93
|
-
|
94
95
|
def browser_version(to_float = true)
|
95
96
|
caps = capabilities
|
96
97
|
ver = (caps[:browser_version] || caps[:version])
|
@@ -110,10 +111,6 @@ private
|
|
110
111
|
capabilities['chrome']['chromedriverVersion'].split(' ')[0]
|
111
112
|
end
|
112
113
|
|
113
|
-
def capabilities
|
114
|
-
driver.browser.capabilities
|
115
|
-
end
|
116
|
-
|
117
114
|
def native_displayed?
|
118
115
|
(driver.options[:native_displayed] != false) &&
|
119
116
|
(w3c? && chromedriver_supports_displayed_endpoint?) &&
|
@@ -18,14 +18,16 @@ class Capybara::Selenium::EdgeNode < Capybara::Selenium::Node
|
|
18
18
|
# In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
|
19
19
|
if chrome_edge?
|
20
20
|
driver.execute_script(<<~JS, self)
|
21
|
-
if (arguments[0].multiple &&
|
21
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
22
22
|
arguments[0].value = null;
|
23
23
|
}
|
24
24
|
JS
|
25
25
|
end
|
26
26
|
super
|
27
27
|
rescue *file_errors => e
|
28
|
-
|
28
|
+
if e.message.match?(/File not found : .+\n.+/m)
|
29
|
+
raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload"
|
30
|
+
end
|
29
31
|
|
30
32
|
raise
|
31
33
|
end
|
@@ -14,7 +14,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
14
14
|
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - '\
|
15
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
|
-
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
|
end
|
@@ -26,7 +26,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
26
26
|
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
27
27
|
# By default files are appended so we have to clear here if its multiple and already set
|
28
28
|
driver.execute_script(<<~JS, self)
|
29
|
-
if (arguments[0].multiple &&
|
29
|
+
if (arguments[0].multiple && arguments[0].files.length){
|
30
30
|
arguments[0].value = null;
|
31
31
|
}
|
32
32
|
JS
|
@@ -42,7 +42,7 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|
42
42
|
|
43
43
|
def send_keys(*args)
|
44
44
|
# https://github.com/mozilla/geckodriver/issues/846
|
45
|
-
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?
|
45
|
+
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?(Array)
|
46
46
|
|
47
47
|
native.click
|
48
48
|
_send_keys(args).perform
|
@@ -85,7 +85,7 @@ private
|
|
85
85
|
(driver.options[:native_displayed] != false) && !ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS']
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def perform_with_options(click_options)
|
89
89
|
# Firefox/marionette has an issue clicking with offset near viewport edge
|
90
90
|
# scroll element to middle just in case
|
91
91
|
scroll_to_center if click_options.coords?
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPauser
|
4
|
+
def initialize(mouse, keyboard)
|
5
|
+
super
|
6
|
+
@devices[:pauser] = Pauser.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def pause(duration)
|
10
|
+
@actions << [:pauser, :pause, [duration]]
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
class Pauser
|
15
|
+
def pause(duration)
|
16
|
+
sleep duration
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private_constant :Pauser
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined?(::Selenium::WebDriver::VERSION) && (::Selenium::WebDriver::VERSION.to_f < 4) &&
|
24
|
+
defined?(::Selenium::WebDriver::ActionBuilder)
|
25
|
+
::Selenium::WebDriver::ActionBuilder.prepend(ActionPauser)
|
26
|
+
end
|
@@ -33,11 +33,9 @@ module Capybara
|
|
33
33
|
end
|
34
34
|
|
35
35
|
Array(data).map do |l|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
next
|
40
|
-
end
|
36
|
+
::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
|
37
|
+
rescue KeyError
|
38
|
+
next
|
41
39
|
end
|
42
40
|
rescue ::Selenium::WebDriver::Error::UnknownCommandError
|
43
41
|
raise NotImplementedError, LOG_MSG
|
data/lib/capybara/server.rb
CHANGED
@@ -24,7 +24,9 @@ module Capybara
|
|
24
24
|
host: Capybara.server_host,
|
25
25
|
reportable_errors: Capybara.server_errors,
|
26
26
|
extra_middleware: [])
|
27
|
-
|
27
|
+
unless deprecated_options.empty?
|
28
|
+
warn 'Positional arguments, other than the application, to Server#new are deprecated, please use keyword arguments'
|
29
|
+
end
|
28
30
|
@app = app
|
29
31
|
@extra_middleware = extra_middleware
|
30
32
|
@server_thread = nil # suppress warnings
|
@@ -61,7 +63,7 @@ module Capybara
|
|
61
63
|
def wait_for_pending_requests
|
62
64
|
timer = Capybara::Helpers.timer(expire_in: 60)
|
63
65
|
while pending_requests?
|
64
|
-
raise
|
66
|
+
raise "Requests did not finish in 60 seconds: #{middleware.pending_requests}" if timer.expired?
|
65
67
|
|
66
68
|
sleep 0.01
|
67
69
|
end
|
@@ -106,7 +108,17 @@ module Capybara
|
|
106
108
|
|
107
109
|
def find_available_port(host)
|
108
110
|
server = TCPServer.new(host, 0)
|
109
|
-
server.addr[1]
|
111
|
+
port = server.addr[1]
|
112
|
+
server.close
|
113
|
+
|
114
|
+
# Workaround issue where some platforms (mac, ???) when passed a host
|
115
|
+
# of '0.0.0.0' will return a port that is only available on one of the
|
116
|
+
# ip addresses that resolves to, but the next binding to that port requires
|
117
|
+
# that port to be available on all ips
|
118
|
+
server = TCPServer.new(host, port)
|
119
|
+
port
|
120
|
+
rescue Errno::EADDRINUSE
|
121
|
+
retry
|
110
122
|
ensure
|
111
123
|
server&.close
|
112
124
|
end
|
@@ -4,19 +4,25 @@ module Capybara
|
|
4
4
|
class Server
|
5
5
|
class Middleware
|
6
6
|
class Counter
|
7
|
-
attr_reader :value
|
8
|
-
|
9
7
|
def initialize
|
10
|
-
@value =
|
8
|
+
@value = []
|
11
9
|
@mutex = Mutex.new
|
12
10
|
end
|
13
11
|
|
14
|
-
def increment
|
15
|
-
@mutex.synchronize { @value
|
12
|
+
def increment(uri)
|
13
|
+
@mutex.synchronize { @value.push(uri) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def decrement(uri)
|
17
|
+
@mutex.synchronize { @value.delete_at(@value.index(uri) || @value.length) }
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
@mutex.synchronize { @value
|
20
|
+
def positive?
|
21
|
+
@mutex.synchronize { @value.length.positive? }
|
22
|
+
end
|
23
|
+
|
24
|
+
def value
|
25
|
+
@mutex.synchronize { @value.dup }
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
@@ -31,8 +37,12 @@ module Capybara
|
|
31
37
|
@server_errors = server_errors
|
32
38
|
end
|
33
39
|
|
40
|
+
def pending_requests
|
41
|
+
@counter.value
|
42
|
+
end
|
43
|
+
|
34
44
|
def pending_requests?
|
35
|
-
@counter.
|
45
|
+
@counter.positive?
|
36
46
|
end
|
37
47
|
|
38
48
|
def clear_error
|
@@ -43,14 +53,14 @@ module Capybara
|
|
43
53
|
if env['PATH_INFO'] == '/__identify__'
|
44
54
|
[200, {}, [@app.object_id.to_s]]
|
45
55
|
else
|
46
|
-
@counter.increment
|
56
|
+
@counter.increment(env['REQUEST_URI'])
|
47
57
|
begin
|
48
58
|
@extended_app.call(env)
|
49
59
|
rescue *@server_errors => e
|
50
60
|
@error ||= e
|
51
61
|
raise e
|
52
62
|
ensure
|
53
|
-
@counter.decrement
|
63
|
+
@counter.decrement(env['REQUEST_URI'])
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/capybara/session.rb
CHANGED
@@ -75,7 +75,9 @@ module Capybara
|
|
75
75
|
attr_accessor :synchronized
|
76
76
|
|
77
77
|
def initialize(mode, app = nil)
|
78
|
-
|
78
|
+
if app && !app.respond_to?(:call)
|
79
|
+
raise TypeError, 'The second parameter to Session::new should be a rack app if passed.'
|
80
|
+
end
|
79
81
|
|
80
82
|
@@instance_created = true # rubocop:disable Style/ClassVars
|
81
83
|
@mode = mode
|
@@ -88,15 +90,15 @@ module Capybara
|
|
88
90
|
@server = if config.run_server && @app && driver.needs_server?
|
89
91
|
server_options = { port: config.server_port, host: config.server_host, reportable_errors: config.server_errors }
|
90
92
|
server_options[:extra_middleware] = [Capybara::Server::AnimationDisabler] if config.disable_animation
|
91
|
-
Capybara::Server.new(@app, server_options).boot
|
93
|
+
Capybara::Server.new(@app, **server_options).boot
|
92
94
|
end
|
93
95
|
@touched = false
|
94
96
|
end
|
95
97
|
|
96
98
|
def driver
|
97
99
|
@driver ||= begin
|
98
|
-
unless Capybara.drivers
|
99
|
-
other_drivers = Capybara.drivers.
|
100
|
+
unless Capybara.drivers[mode]
|
101
|
+
other_drivers = Capybara.drivers.names.map(&:inspect)
|
100
102
|
raise Capybara::DriverNotFoundError, "no driver called #{mode.inspect} was found, available drivers: #{other_drivers.join(', ')}"
|
101
103
|
end
|
102
104
|
driver = Capybara.drivers[mode].call(app)
|
@@ -190,7 +192,7 @@ module Capybara
|
|
190
192
|
# @return [String] A snapshot of the DOM of the current document, as it looks right now (potentially modified by JavaScript).
|
191
193
|
#
|
192
194
|
def html
|
193
|
-
driver.html
|
195
|
+
driver.html || ''
|
194
196
|
end
|
195
197
|
alias_method :body, :html
|
196
198
|
alias_method :source, :html
|
@@ -336,8 +338,8 @@ module Capybara
|
|
336
338
|
#
|
337
339
|
# @raise [Capybara::ElementNotFound] If the scope can't be found before time expires
|
338
340
|
#
|
339
|
-
def within(*args)
|
340
|
-
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args)
|
341
|
+
def within(*args, **kw_args)
|
342
|
+
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
|
341
343
|
begin
|
342
344
|
scopes.push(new_scope)
|
343
345
|
yield if block_given?
|
@@ -421,8 +423,8 @@ module Capybara
|
|
421
423
|
# @param [String] locator The locator for the given selector kind. For :frame this is the name/id of a frame/iframe element
|
422
424
|
# @overload within_frame(index)
|
423
425
|
# @param [Integer] index index of a frame (0 based)
|
424
|
-
def within_frame(*args)
|
425
|
-
switch_to_frame(_find_frame(*args))
|
426
|
+
def within_frame(*args, **kw_args)
|
427
|
+
switch_to_frame(_find_frame(*args, **kw_args))
|
426
428
|
begin
|
427
429
|
yield if block_given?
|
428
430
|
ensure
|
@@ -494,7 +496,7 @@ module Capybara
|
|
494
496
|
'`within` or `within_frame` blocks.'
|
495
497
|
end
|
496
498
|
|
497
|
-
_switch_to_window(window, options, &window_locator)
|
499
|
+
_switch_to_window(window, **options, &window_locator)
|
498
500
|
end
|
499
501
|
|
500
502
|
##
|
@@ -528,7 +530,7 @@ module Capybara
|
|
528
530
|
when Proc
|
529
531
|
_switch_to_window { window_or_proc.call }
|
530
532
|
else
|
531
|
-
raise ArgumentError
|
533
|
+
raise ArgumentError, '`#within_window` requires a `Capybara::Window` instance or a lambda'
|
532
534
|
end
|
533
535
|
|
534
536
|
begin
|
@@ -721,7 +723,7 @@ module Capybara
|
|
721
723
|
# @param [Hash] options a customizable set of options
|
722
724
|
# @return [String] the path to which the file was saved
|
723
725
|
def save_screenshot(path = nil, **options)
|
724
|
-
prepare_path(path, 'png').tap { |p_path| driver.save_screenshot(p_path, options) }
|
726
|
+
prepare_path(path, 'png').tap { |p_path| driver.save_screenshot(p_path, **options) }
|
725
727
|
end
|
726
728
|
|
727
729
|
##
|
@@ -736,7 +738,7 @@ module Capybara
|
|
736
738
|
# @param [Hash] options a customizable set of options
|
737
739
|
#
|
738
740
|
def save_and_open_screenshot(path = nil, **options)
|
739
|
-
save_screenshot(path, options).tap { |s_path| open_file(s_path) } # rubocop:disable Lint/Debugger
|
741
|
+
save_screenshot(path, **options).tap { |s_path| open_file(s_path) } # rubocop:disable Lint/Debugger
|
740
742
|
end
|
741
743
|
|
742
744
|
def document
|
@@ -744,15 +746,32 @@ module Capybara
|
|
744
746
|
end
|
745
747
|
|
746
748
|
NODE_METHODS.each do |method|
|
747
|
-
|
748
|
-
|
749
|
-
|
749
|
+
if RUBY_VERSION >= '2.7'
|
750
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
751
|
+
def #{method}(...)
|
752
|
+
@touched = true
|
753
|
+
current_scope.#{method}(...)
|
754
|
+
end
|
755
|
+
METHOD
|
756
|
+
else
|
757
|
+
define_method method do |*args, &block|
|
758
|
+
@touched = true
|
759
|
+
current_scope.send(method, *args, &block)
|
760
|
+
end
|
750
761
|
end
|
751
762
|
end
|
752
763
|
|
753
764
|
DOCUMENT_METHODS.each do |method|
|
754
|
-
|
755
|
-
|
765
|
+
if RUBY_VERSION >= '2.7'
|
766
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
767
|
+
def #{method}(...)
|
768
|
+
document.#{method}(...)
|
769
|
+
end
|
770
|
+
METHOD
|
771
|
+
else
|
772
|
+
define_method method do |*args, &block|
|
773
|
+
document.send(method, *args, &block)
|
774
|
+
end
|
756
775
|
end
|
757
776
|
end
|
758
777
|
|
@@ -819,11 +838,11 @@ module Capybara
|
|
819
838
|
end
|
820
839
|
|
821
840
|
def accept_modal(type, text_or_options, options, &blk)
|
822
|
-
driver.accept_modal(type, modal_options(text_or_options, options), &blk)
|
841
|
+
driver.accept_modal(type, **modal_options(text_or_options, **options), &blk)
|
823
842
|
end
|
824
843
|
|
825
844
|
def dismiss_modal(type, text_or_options, options, &blk)
|
826
|
-
driver.dismiss_modal(type, modal_options(text_or_options, options), &blk)
|
845
|
+
driver.dismiss_modal(type, **modal_options(text_or_options, **options), &blk)
|
827
846
|
end
|
828
847
|
|
829
848
|
def modal_options(text = nil, **options)
|
@@ -871,16 +890,14 @@ module Capybara
|
|
871
890
|
uri.port ||= @server.port if @server && config.always_include_port
|
872
891
|
end
|
873
892
|
|
874
|
-
def _find_frame(*args)
|
875
|
-
return find(:frame) if args.length.zero?
|
876
|
-
|
893
|
+
def _find_frame(*args, **kw_args)
|
877
894
|
case args[0]
|
878
895
|
when Capybara::Node::Element
|
879
896
|
args[0]
|
880
|
-
when String,
|
881
|
-
find(:frame, *args)
|
897
|
+
when String, nil
|
898
|
+
find(:frame, *args, **kw_args)
|
882
899
|
when Symbol
|
883
|
-
find(*args)
|
900
|
+
find(*args, **kw_args)
|
884
901
|
when Integer
|
885
902
|
idx = args[0]
|
886
903
|
all(:frame, minimum: idx + 1)[idx]
|
@@ -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].freeze
|
11
|
+
predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze
|
12
12
|
|
13
13
|
attr_accessor(*OPTIONS)
|
14
14
|
|
@@ -37,6 +37,8 @@ module Capybara
|
|
37
37
|
# See {Capybara.configure}
|
38
38
|
# @!method enable_aria_label
|
39
39
|
# See {Capybara.configure}
|
40
|
+
# @!method enable_aria_role
|
41
|
+
# See {Capybara.configure}
|
40
42
|
# @!method save_path
|
41
43
|
# See {Capybara.configure}
|
42
44
|
# @!method asset_host
|
@@ -79,14 +81,18 @@ module Capybara
|
|
79
81
|
|
80
82
|
remove_method :app_host=
|
81
83
|
def app_host=(url)
|
82
|
-
|
84
|
+
unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
|
85
|
+
raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
|
86
|
+
end
|
83
87
|
|
84
88
|
@app_host = url
|
85
89
|
end
|
86
90
|
|
87
91
|
remove_method :default_host=
|
88
92
|
def default_host=(url)
|
89
|
-
|
93
|
+
unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
|
94
|
+
raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
|
95
|
+
end
|
90
96
|
|
91
97
|
@default_host = url
|
92
98
|
end
|