selenium-webdriver 4.4.0 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +86 -1
  3. data/LICENSE +1 -1
  4. data/NOTICE +1 -1
  5. data/bin/linux/selenium-manager +0 -0
  6. data/bin/macos/selenium-manager +0 -0
  7. data/bin/windows/selenium-manager.exe +0 -0
  8. data/lib/selenium/server.rb +20 -16
  9. data/lib/selenium/webdriver/atoms/findElements.js +0 -0
  10. data/lib/selenium/webdriver/atoms/getAttribute.js +0 -0
  11. data/lib/selenium/webdriver/atoms/isDisplayed.js +0 -0
  12. data/lib/selenium/webdriver/atoms/mutationListener.js +0 -0
  13. data/lib/selenium/webdriver/atoms.rb +2 -3
  14. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  15. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  16. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  17. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  18. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  19. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  20. data/lib/selenium/webdriver/bidi/log_inspector.rb +140 -0
  21. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  22. data/lib/selenium/webdriver/bidi/session.rb +13 -0
  23. data/lib/selenium/webdriver/bidi.rb +2 -1
  24. data/lib/selenium/webdriver/chrome/driver.rb +19 -28
  25. data/lib/selenium/webdriver/chrome/features.rb +5 -72
  26. data/lib/selenium/webdriver/chrome/options.rb +3 -237
  27. data/lib/selenium/webdriver/chrome/profile.rb +3 -83
  28. data/lib/selenium/webdriver/chrome/service.rb +4 -19
  29. data/lib/selenium/webdriver/chromium/driver.rb +61 -0
  30. data/lib/selenium/webdriver/chromium/features.rb +103 -0
  31. data/lib/selenium/webdriver/chromium/options.rb +261 -0
  32. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  33. data/lib/selenium/webdriver/chromium/service.rb +42 -0
  34. data/lib/selenium/webdriver/chromium.rb +32 -0
  35. data/lib/selenium/webdriver/common/action_builder.rb +11 -48
  36. data/lib/selenium/webdriver/common/child_process.rb +124 -0
  37. data/lib/selenium/webdriver/common/driver.rb +34 -25
  38. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  39. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +0 -1
  40. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  41. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +0 -2
  43. data/lib/selenium/webdriver/common/driver_extensions/has_bidi.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +0 -1
  45. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +0 -2
  46. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +0 -2
  47. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  48. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +0 -2
  49. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +0 -2
  50. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +1 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +0 -1
  52. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +0 -2
  53. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +0 -2
  54. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +0 -2
  55. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +0 -2
  56. data/lib/selenium/webdriver/common/element.rb +7 -7
  57. data/lib/selenium/webdriver/common/error.rb +0 -2
  58. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  59. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +3 -3
  60. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +2 -2
  61. data/lib/selenium/webdriver/common/interactions/scroll.rb +7 -5
  62. data/lib/selenium/webdriver/common/logger.rb +10 -2
  63. data/lib/selenium/webdriver/common/options.rb +30 -8
  64. data/lib/selenium/webdriver/common/platform.rb +4 -1
  65. data/lib/selenium/webdriver/common/profile_helper.rb +1 -1
  66. data/lib/selenium/webdriver/common/proxy.rb +1 -1
  67. data/lib/selenium/webdriver/common/selenium_manager.rb +89 -0
  68. data/lib/selenium/webdriver/common/service.rb +16 -8
  69. data/lib/selenium/webdriver/common/service_manager.rb +2 -10
  70. data/lib/selenium/webdriver/common/shadow_root.rb +1 -2
  71. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  72. data/lib/selenium/webdriver/common/takes_screenshot.rb +2 -3
  73. data/lib/selenium/webdriver/common/target_locator.rb +2 -3
  74. data/lib/selenium/webdriver/common/timeouts.rb +2 -2
  75. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +8 -6
  76. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +0 -1
  77. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +16 -16
  78. data/lib/selenium/webdriver/common/websocket_connection.rb +10 -2
  79. data/lib/selenium/webdriver/common.rb +2 -0
  80. data/lib/selenium/webdriver/devtools/console_event.rb +0 -2
  81. data/lib/selenium/webdriver/devtools/exception_event.rb +0 -2
  82. data/lib/selenium/webdriver/devtools/mutation_event.rb +0 -2
  83. data/lib/selenium/webdriver/devtools/network_interceptor.rb +3 -6
  84. data/lib/selenium/webdriver/devtools/pinned_script.rb +0 -2
  85. data/lib/selenium/webdriver/devtools/request.rb +0 -2
  86. data/lib/selenium/webdriver/devtools/response.rb +0 -2
  87. data/lib/selenium/webdriver/devtools.rb +0 -1
  88. data/lib/selenium/webdriver/edge/driver.rb +20 -3
  89. data/lib/selenium/webdriver/edge/features.rb +3 -4
  90. data/lib/selenium/webdriver/edge/options.rb +3 -5
  91. data/lib/selenium/webdriver/edge/profile.rb +2 -2
  92. data/lib/selenium/webdriver/edge/service.rb +2 -2
  93. data/lib/selenium/webdriver/firefox/driver.rb +19 -2
  94. data/lib/selenium/webdriver/firefox/features.rb +5 -2
  95. data/lib/selenium/webdriver/firefox/options.rb +6 -2
  96. data/lib/selenium/webdriver/firefox/profile.rb +6 -6
  97. data/lib/selenium/webdriver/firefox/service.rb +0 -1
  98. data/lib/selenium/webdriver/ie/driver.rb +20 -1
  99. data/lib/selenium/webdriver/ie/service.rb +1 -2
  100. data/lib/selenium/webdriver/remote/bridge.rb +8 -15
  101. data/lib/selenium/webdriver/remote/capabilities.rb +34 -12
  102. data/lib/selenium/webdriver/remote/commands.rb +0 -2
  103. data/lib/selenium/webdriver/remote/driver.rb +13 -13
  104. data/lib/selenium/webdriver/remote/http/curb.rb +0 -2
  105. data/lib/selenium/webdriver/remote/http/default.rb +1 -0
  106. data/lib/selenium/webdriver/remote/response.rb +0 -1
  107. data/lib/selenium/webdriver/safari/driver.rb +20 -1
  108. data/lib/selenium/webdriver/safari/features.rb +0 -2
  109. data/lib/selenium/webdriver/safari/options.rb +5 -1
  110. data/lib/selenium/webdriver/safari.rb +1 -1
  111. data/lib/selenium/webdriver/support/color.rb +15 -15
  112. data/lib/selenium/webdriver/support/guards/guard.rb +0 -2
  113. data/lib/selenium/webdriver/support/guards/guard_condition.rb +0 -2
  114. data/lib/selenium/webdriver/support/relative_locator.rb +0 -1
  115. data/lib/selenium/webdriver/support/select.rb +3 -1
  116. data/lib/selenium/webdriver/version.rb +1 -1
  117. data/lib/selenium/webdriver.rb +3 -4
  118. data/selenium-webdriver.gemspec +8 -9
  119. metadata +29 -73
  120. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +0 -63
  121. data/lib/selenium/webdriver/support/cdp_client_generator.rb +0 -108
@@ -48,9 +48,10 @@ module Selenium
48
48
  #
49
49
  # @param [String] progname Allow child projects to use Selenium's Logger pattern
50
50
  #
51
- def initialize(progname = 'Selenium')
51
+ def initialize(progname = 'Selenium', ignored: nil)
52
52
  @logger = create_logger(progname)
53
- @ignored = []
53
+ @ignored = Array(ignored)
54
+ @first_warning = false
54
55
  end
55
56
 
56
57
  #
@@ -94,6 +95,13 @@ module Selenium
94
95
  # @yield see #deprecate
95
96
  #
96
97
  def warn(message, id: [])
98
+ unless @first_warning
99
+ @first_warning = true
100
+ warn("Details on how to use and modify Selenium logger:\n", id: [:logger_info]) do
101
+ "https://selenium.dev/documentation/webdriver/troubleshooting/logging#ruby\n"
102
+ end
103
+ end
104
+
97
105
  id = Array(id)
98
106
  return if (@ignored & id).any?
99
107
 
@@ -38,12 +38,12 @@ module Selenium
38
38
  def ie(**opts)
39
39
  IE::Options.new(**opts)
40
40
  end
41
- alias_method :internet_explorer, :ie
41
+ alias internet_explorer ie
42
42
 
43
43
  def edge(**opts)
44
44
  Edge::Options.new(**opts)
45
45
  end
46
- alias_method :microsoftedge, :edge
46
+ alias microsoftedge edge
47
47
 
48
48
  def safari(**opts)
49
49
  Safari::Options.new(**opts)
@@ -85,7 +85,13 @@ module Selenium
85
85
  #
86
86
 
87
87
  def add_option(name, value = nil)
88
- @options[name.keys.first] = name.values.first if value.nil? && name.is_a?(Hash)
88
+ name, value = name.first if value.nil? && name.is_a?(Hash)
89
+
90
+ unless name.to_s.include?(':')
91
+ WebDriver.logger.deprecate('Options#add_option for w3c or browser specific capabilities',
92
+ 'applicable attribute accessors or pass into constructor',
93
+ id: :add_option)
94
+ end
89
95
  @options[name] = value
90
96
  end
91
97
 
@@ -95,7 +101,7 @@ module Selenium
95
101
  as_json == other.as_json
96
102
  end
97
103
 
98
- alias_method :eql?, :==
104
+ alias eql? ==
99
105
 
100
106
  #
101
107
  # @api private
@@ -106,11 +112,27 @@ module Selenium
106
112
 
107
113
  w3c_options = process_w3c_options(options)
108
114
 
109
- self.class::CAPABILITIES.each do |capability_alias, capability_name|
110
- capability_value = options.delete(capability_alias)
111
- options[capability_name] = capability_value if !capability_value.nil? && !options.key?(capability_name)
115
+ browser_options = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash|
116
+ from_name = options.delete(capability_name)
117
+ from_alias = options.delete(capability_alias)
118
+ capability_value = if !from_name.nil? && capability_alias != capability_name
119
+ WebDriver.logger.deprecate("#{capability_name} as option",
120
+ capability_alias.to_s, id: :option_symbols)
121
+ from_name
122
+ elsif !from_alias.nil?
123
+ from_alias
124
+ end
125
+
126
+ hash[capability_name] = capability_value unless capability_value.nil?
112
127
  end
113
- browser_options = defined?(self.class::KEY) ? {self.class::KEY => options} : options
128
+
129
+ unless options.empty?
130
+ msg = 'These options are not w3c compliant and will result in failures in a future release'
131
+ WebDriver.logger.warn("#{msg}: #{options}")
132
+ browser_options.merge!(options)
133
+ end
134
+
135
+ browser_options = {self.class::KEY => browser_options} if defined?(self.class::KEY)
114
136
 
115
137
  process_browser_options(browser_options)
116
138
  generate_as_json(w3c_options.merge(browser_options))
@@ -78,6 +78,10 @@ module Selenium
78
78
  engine == :jruby
79
79
  end
80
80
 
81
+ def truffleruby?
82
+ engine == :truffleruby
83
+ end
84
+
81
85
  def ruby_version
82
86
  RUBY_VERSION
83
87
  end
@@ -105,7 +109,6 @@ module Selenium
105
109
 
106
110
  def cygwin?
107
111
  RUBY_PLATFORM.include?('cygwin')
108
- !Regexp.last_match.nil?
109
112
  end
110
113
 
111
114
  def null_device
@@ -40,7 +40,7 @@ module Selenium
40
40
  end
41
41
 
42
42
  def as_json(*)
43
- {"zip" => encoded}
43
+ {'zip' => encoded}
44
44
  end
45
45
 
46
46
  def to_json(*)
@@ -74,7 +74,7 @@ module Selenium
74
74
  def ==(other)
75
75
  other.is_a?(self.class) && as_json == other.as_json
76
76
  end
77
- alias_method :eql?, :==
77
+ alias eql? ==
78
78
 
79
79
  def ftp=(value)
80
80
  self.type = :manual
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ require 'open3'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ #
25
+ # Wrapper for getting information from the Selenium Manager binaries.
26
+ # This implementation is still in beta, and may change.
27
+ # @api private
28
+ #
29
+ class SeleniumManager
30
+ BIN_PATH = '../../../../../bin'
31
+
32
+ class << self
33
+ # @param [String] driver_name which driver to use.
34
+ # @return [String] the path to the correct driver.
35
+ def driver_path(driver_name)
36
+ unless %w[chromedriver geckodriver msedgedriver IEDriverServer].include?(driver_name)
37
+ msg = "Unable to locate driver with name: #{driver_name}"
38
+ raise Error::WebDriverError, msg
39
+ end
40
+
41
+ location = run("#{binary} --driver #{driver_name}")
42
+ WebDriver.logger.debug("Driver found at #{location}")
43
+ Platform.assert_executable location
44
+
45
+ location
46
+ end
47
+
48
+ private
49
+
50
+ # @return [String] the path to the correct selenium manager
51
+ def binary
52
+ @binary ||= begin
53
+ path = File.expand_path(BIN_PATH, __FILE__)
54
+ path << if Platform.windows?
55
+ '/windows/selenium-manager.exe'
56
+ elsif Platform.mac?
57
+ '/macos/selenium-manager'
58
+ elsif Platform.linux?
59
+ '/linux/selenium-manager'
60
+ end
61
+ location = File.expand_path(path, __FILE__)
62
+ unless location.is_a?(String) && File.exist?(location) && File.executable?(location)
63
+ raise Error::WebDriverError, 'Unable to obtain Selenium Manager'
64
+ end
65
+
66
+ WebDriver.logger.debug("Selenium Manager found at #{location}")
67
+ location
68
+ end
69
+ end
70
+
71
+ def run(command)
72
+ WebDriver.logger.debug("Executing Process #{command}")
73
+
74
+ begin
75
+ stdout, stderr, status = Open3.capture3(command)
76
+ rescue StandardError => e
77
+ raise Error::WebDriverError, "Unsuccessful command executed: #{command}", e.message
78
+ end
79
+
80
+ if status.exitstatus.positive?
81
+ raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{stdout}#{stderr}"
82
+ end
83
+
84
+ stdout.gsub("INFO\t", '').strip
85
+ end
86
+ end
87
+ end # SeleniumManager
88
+ end # WebDriver
89
+ end # Selenium
@@ -39,12 +39,13 @@ module Selenium
39
39
  def ie(**opts)
40
40
  IE::Service.new(**opts)
41
41
  end
42
- alias_method :internet_explorer, :ie
42
+ alias internet_explorer ie
43
43
 
44
44
  def edge(**opts)
45
45
  Edge::Service.new(**opts)
46
46
  end
47
- alias_method :microsoftedge, :edge
47
+ alias microsoftedge edge
48
+ alias msedge edge
48
49
 
49
50
  def safari(**opts)
50
51
  Safari::Service.new(**opts)
@@ -56,8 +57,8 @@ module Selenium
56
57
  end
57
58
  end
58
59
 
59
- attr_accessor :host
60
- attr_reader :executable_path, :port, :extra_args
60
+ attr_accessor :host, :executable_path, :port, :args
61
+ alias extra_args args
61
62
 
62
63
  #
63
64
  # End users should use a class method for the desired driver, rather than using this directly.
@@ -74,15 +75,13 @@ module Selenium
74
75
  @host = Platform.localhost
75
76
  @port = Integer(port)
76
77
 
77
- @extra_args = args.is_a?(Hash) ? extract_service_args(args) : args
78
+ @args = args.is_a?(Hash) ? extract_service_args(args) : args
78
79
 
79
80
  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
80
81
  end
81
82
 
82
83
  def launch
83
- sm = ServiceManager.new(self)
84
- sm.start
85
- sm
84
+ ServiceManager.new(self).tap(&:start)
86
85
  end
87
86
 
88
87
  def shutdown_supported
@@ -92,6 +91,9 @@ module Selenium
92
91
  protected
93
92
 
94
93
  def extract_service_args(driver_opts)
94
+ WebDriver.logger.deprecate('initializing Service class with :args using Hash',
95
+ ':args parameter with an Array of String values',
96
+ id: :driver_opts)
95
97
  driver_opts.key?(:args) ? driver_opts.delete(:args) : []
96
98
  end
97
99
 
@@ -101,6 +103,12 @@ module Selenium
101
103
  path = path.call if path.is_a?(Proc)
102
104
  path ||= Platform.find_binary(self.class::EXECUTABLE)
103
105
 
106
+ begin
107
+ path ||= SeleniumManager.driver_path(self.class::EXECUTABLE)
108
+ rescue Error::WebDriverError => e
109
+ WebDriver.logger.debug("Unable obtain driver using Selenium Manager\n #{e.message}")
110
+ end
111
+
104
112
  raise Error::WebDriverError, self.class::MISSING_TEXT unless path
105
113
 
106
114
  Platform.assert_executable path
@@ -40,7 +40,7 @@ module Selenium
40
40
  @executable_path = config.executable_path
41
41
  @host = Platform.localhost
42
42
  @port = config.port
43
- @extra_args = config.extra_args
43
+ @extra_args = config.args
44
44
  @shutdown_supported = config.shutdown_supported
45
45
 
46
46
  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
@@ -79,12 +79,7 @@ module Selenium
79
79
  def build_process(*command)
80
80
  WebDriver.logger.debug("Executing Process #{command}")
81
81
  @process = ChildProcess.build(*command)
82
- if WebDriver.logger.debug?
83
- @process.io.stdout = @process.io.stderr = WebDriver.logger.io
84
- elsif Platform.jruby?
85
- # Apparently we need to read the output of drivers on JRuby.
86
- @process.io.stdout = @process.io.stderr = File.new(Platform.null_device, 'w')
87
- end
82
+ @process.io = WebDriver.logger.io if WebDriver.logger.debug?
88
83
 
89
84
  @process
90
85
  end
@@ -104,8 +99,6 @@ module Selenium
104
99
 
105
100
  def start_process
106
101
  @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
107
- # NOTE: this is a bug only in Windows 7
108
- @process.leader = true unless Platform.windows?
109
102
  @process.start
110
103
  end
111
104
 
@@ -113,7 +106,6 @@ module Selenium
113
106
  return if process_exited?
114
107
 
115
108
  @process.stop STOP_TIMEOUT
116
- @process.io.stdout.close if Platform.jruby? && !WebDriver.logger.debug?
117
109
  end
118
110
 
119
111
  def stop_server
@@ -42,7 +42,7 @@ module Selenium
42
42
  def ==(other)
43
43
  other.is_a?(self.class) && ref == other.ref
44
44
  end
45
- alias_method :eql?, :==
45
+ alias eql? ==
46
46
 
47
47
  def hash
48
48
  [@id, @bridge].hash
@@ -81,7 +81,6 @@ module Selenium
81
81
  private
82
82
 
83
83
  attr_reader :bridge
84
-
85
84
  end # ShadowRoot
86
85
  end # WebDriver
87
86
  end # Selenium
@@ -26,6 +26,7 @@ module Selenium
26
26
  class SocketLock
27
27
  def initialize(port, timeout)
28
28
  @port = port
29
+ @server = nil
29
30
  @timeout = timeout
30
31
  end
31
32
 
@@ -66,8 +67,7 @@ module Selenium
66
67
 
67
68
  def can_lock?
68
69
  @server = TCPServer.new(Platform.localhost, @port)
69
- ChildProcess.close_on_exec @server
70
-
70
+ @server.close_on_exec = true
71
71
  true
72
72
  rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => e
73
73
  WebDriver.logger.debug("#{self}: #{e.message}")
@@ -32,8 +32,8 @@ module Selenium
32
32
  def save_screenshot(png_path, full_page: false)
33
33
  extension = File.extname(png_path).downcase
34
34
  if extension != '.png'
35
- WebDriver.logger.warn "name used for saved screenshot does not match file type. " \
36
- "It should end with .png extension",
35
+ WebDriver.logger.warn 'name used for saved screenshot does not match file type. ' \
36
+ 'It should end with .png extension',
37
37
  id: :screenshot
38
38
  end
39
39
  File.open(png_path, 'wb') { |f| f << screenshot_as(:png, full_page: full_page) }
@@ -60,7 +60,6 @@ module Selenium
60
60
  rescue NameError
61
61
  raise Error::UnsupportedOperationError, "Full Page Screenshots are not supported for #{inspect}"
62
62
  end
63
-
64
63
  end # TakesScreenshot
65
64
  end # WebDriver
66
65
  end # Selenium
@@ -51,9 +51,8 @@ module Selenium
51
51
  #
52
52
 
53
53
  def new_window(type = :window)
54
- unless %i[window tab].include?(type)
55
- raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}"
56
- end
54
+ raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}" unless %i[window
55
+ tab].include?(type)
57
56
 
58
57
  handle = @bridge.new_window(type)['handle']
59
58
 
@@ -48,7 +48,7 @@ module Selenium
48
48
  def script
49
49
  Float(@bridge.timeouts['script']) / 1000
50
50
  end
51
- alias_method :script_timeout, :script
51
+ alias script_timeout script
52
52
 
53
53
  #
54
54
  # Sets the amount of time to wait for an asynchronous script to finish
@@ -59,7 +59,7 @@ module Selenium
59
59
  def script=(seconds)
60
60
  @bridge.timeouts = {'script' => Integer(seconds * 1000)}
61
61
  end
62
- alias_method :script_timeout=, :script=
62
+ alias script_timeout= script=
63
63
 
64
64
  #
65
65
  # Gets the amount of time to wait for a page load to complete before throwing an error.
@@ -44,8 +44,8 @@ module Selenium
44
44
 
45
45
  def from_json(opts)
46
46
  user_handle = opts['userHandle'] ? decode(opts['userHandle']) : nil
47
- new(id: decode(opts["credentialId"]),
48
- resident_credential: opts["isResidentCredential"],
47
+ new(id: decode(opts['credentialId']),
48
+ resident_credential: opts['isResidentCredential'],
49
49
  rp_id: opts['rpId'],
50
50
  private_key: opts['privateKey'],
51
51
  sign_count: opts['signCount'],
@@ -54,15 +54,17 @@ module Selenium
54
54
  end
55
55
 
56
56
  attr_reader :id, :resident_credential, :rp_id, :user_handle, :private_key, :sign_count
57
- alias_method :resident_credential?, :resident_credential
57
+ alias resident_credential? resident_credential
58
58
 
59
- def initialize(id:, resident_credential:, rp_id:, private_key:, user_handle: nil, sign_count: 0)
59
+ def initialize(id:, resident_credential:, rp_id:, private_key:, **opts)
60
60
  @id = id
61
61
  @resident_credential = resident_credential
62
62
  @rp_id = rp_id
63
- @user_handle = user_handle
63
+ @user_handle = opts.delete(:user_handle) { nil }
64
64
  @private_key = private_key
65
- @sign_count = sign_count
65
+ @sign_count = opts.delete(:sign_count) { 0 }
66
+
67
+ raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
66
68
  end
67
69
 
68
70
  #
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  class VirtualAuthenticator
23
-
24
23
  attr_reader :options
25
24
 
26
25
  #
@@ -25,24 +25,24 @@
25
25
  module Selenium
26
26
  module WebDriver
27
27
  class VirtualAuthenticatorOptions
28
-
29
- PROTOCOL = {ctap2: "ctap2", u2f: "ctap1/u2f"}.freeze
30
- TRANSPORT = {ble: "ble", usb: "usb", nfc: "nfc", internal: "internal"}.freeze
28
+ PROTOCOL = {ctap2: 'ctap2', u2f: 'ctap1/u2f'}.freeze
29
+ TRANSPORT = {ble: 'ble', usb: 'usb', nfc: 'nfc', internal: 'internal'}.freeze
31
30
 
32
31
  attr_accessor :protocol, :transport, :resident_key, :user_verification, :user_consenting, :user_verified
33
- alias_method :resident_key?, :resident_key
34
- alias_method :user_verification?, :user_verification
35
- alias_method :user_consenting?, :user_consenting
36
- alias_method :user_verified?, :user_verified
37
-
38
- def initialize(protocol: :ctap2, transport: :usb, resident_key: false,
39
- user_verification: false, user_consenting: true, user_verified: false)
40
- @protocol = protocol
41
- @transport = transport
42
- @resident_key = resident_key
43
- @user_verification = user_verification
44
- @user_consenting = user_consenting
45
- @user_verified = user_verified
32
+ alias resident_key? resident_key
33
+ alias user_verification? user_verification
34
+ alias user_consenting? user_consenting
35
+ alias user_verified? user_verified
36
+
37
+ def initialize(**opts)
38
+ @protocol = opts.delete(:protocol) { :ctap2 }
39
+ @transport = opts.delete(:transport) { :usb }
40
+ @resident_key = opts.delete(:resident_key) { false }
41
+ @user_verification = opts.delete(:user_verification) { false }
42
+ @user_consenting = opts.delete(:user_consenting) { true }
43
+ @user_verified = opts.delete(:user_verified) { false }
44
+
45
+ raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
46
46
  end
47
47
 
48
48
  #
@@ -22,6 +22,11 @@ require 'websocket'
22
22
  module Selenium
23
23
  module WebDriver
24
24
  class WebSocketConnection
25
+ CONNECTION_ERRORS = [
26
+ Errno::ECONNRESET, # connection is aborted (browser process was killed)
27
+ Errno::EPIPE # broken pipe (browser process was killed)
28
+ ].freeze
29
+
25
30
  RESPONSE_WAIT_TIMEOUT = 30
26
31
  RESPONSE_WAIT_INTERVAL = 0.1
27
32
 
@@ -90,6 +95,8 @@ module Selenium
90
95
  end
91
96
  end
92
97
  end
98
+ rescue *CONNECTION_ERRORS
99
+ Thread.stop
93
100
  end
94
101
  end
95
102
 
@@ -104,7 +111,7 @@ module Selenium
104
111
  return {} if message.empty?
105
112
 
106
113
  message = JSON.parse(message)
107
- messages[message["id"]] = message
114
+ messages[message['id']] = message
108
115
  WebDriver.logger.debug "WebSocket <- #{message}"[...MAX_LOG_MESSAGE_SIZE]
109
116
 
110
117
  message
@@ -122,6 +129,8 @@ module Selenium
122
129
  Thread.current.report_on_exception = true
123
130
 
124
131
  yield params
132
+ rescue *CONNECTION_ERRORS
133
+ Thread.stop
125
134
  end
126
135
  end
127
136
 
@@ -150,7 +159,6 @@ module Selenium
150
159
  @id ||= 0
151
160
  @id += 1
152
161
  end
153
-
154
162
  end # BiDi
155
163
  end # WebDriver
156
164
  end # Selenium
@@ -22,6 +22,7 @@ require 'selenium/webdriver/common/platform'
22
22
  require 'selenium/webdriver/common/proxy'
23
23
  require 'selenium/webdriver/common/log_entry'
24
24
  require 'selenium/webdriver/common/file_reaper'
25
+ require 'selenium/webdriver/common/selenium_manager'
25
26
  require 'selenium/webdriver/common/service'
26
27
  require 'selenium/webdriver/common/service_manager'
27
28
  require 'selenium/webdriver/common/socket_lock'
@@ -95,3 +96,4 @@ require 'selenium/webdriver/common/driver'
95
96
  require 'selenium/webdriver/common/element'
96
97
  require 'selenium/webdriver/common/shadow_root'
97
98
  require 'selenium/webdriver/common/websocket_connection'
99
+ require 'selenium/webdriver/common/child_process'
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  class DevTools
23
23
  class ConsoleEvent
24
-
25
24
  attr_accessor :type, :timestamp, :args
26
25
 
27
26
  def initialize(type:, timestamp:, args:)
@@ -31,7 +30,6 @@ module Selenium
31
30
  arg.key?('value') ? arg['value'] : arg
32
31
  end
33
32
  end
34
-
35
33
  end # ConsoleEvent
36
34
  end # DevTools
37
35
  end # WebDriver
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  class DevTools
23
23
  class ExceptionEvent
24
-
25
24
  attr_accessor :description, :timestamp, :stacktrace
26
25
 
27
26
  def initialize(description:, timestamp:, stacktrace:)
@@ -29,7 +28,6 @@ module Selenium
29
28
  @timestamp = Time.at(timestamp / 1000)
30
29
  @stacktrace = stacktrace
31
30
  end
32
-
33
31
  end # ExceptionEvent
34
32
  end # DevTools
35
33
  end # WebDriver
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  class DevTools
23
23
  class MutationEvent
24
-
25
24
  attr_accessor :element, :attribute_name, :current_value, :old_value
26
25
 
27
26
  def initialize(element:, attribute_name:, current_value:, old_value:)
@@ -30,7 +29,6 @@ module Selenium
30
29
  @current_value = current_value
31
30
  @old_value = old_value
32
31
  end
33
-
34
32
  end # MutationEvent
35
33
  end # DevTools
36
34
  end # WebDriver
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  class DevTools
23
-
24
23
  #
25
24
  # Wraps the network request/response interception, providing
26
25
  # thread-safety guarantees and handling special cases such as browser
@@ -31,14 +30,13 @@ module Selenium
31
30
  #
32
31
 
33
32
  class NetworkInterceptor
34
-
35
33
  # CDP fails to get body on certain responses (301) and raises:
36
34
  # "Can only get response body on requests captured after headers received."
37
- CANNOT_GET_BODY_ON_REDIRECT_ERROR_CODE = "-32000"
35
+ CANNOT_GET_BODY_ON_REDIRECT_ERROR_CODE = '-32000'
38
36
 
39
37
  # CDP fails to operate with intercepted requests.
40
38
  # Typical reason is browser cancelling intercepted requests/responses.
41
- INVALID_INTERCEPTION_ID_ERROR_CODE = "-32602"
39
+ INVALID_INTERCEPTION_ID_ERROR_CODE = '-32602'
42
40
 
43
41
  def initialize(devtools)
44
42
  @devtools = devtools
@@ -129,7 +127,7 @@ module Selenium
129
127
  def continue_request(id)
130
128
  devtools.fetch.continue_request(request_id: id)
131
129
  end
132
- alias_method :continue_response, :continue_request
130
+ alias continue_response continue_request
133
131
 
134
132
  def mutate_request(request)
135
133
  devtools.fetch.continue_request(
@@ -169,7 +167,6 @@ module Selenium
169
167
  def cancelled?(network_id)
170
168
  lock.synchronize { !!cancelled_requests.delete(network_id) }
171
169
  end
172
-
173
170
  end # NetworkInterceptor
174
171
  end # DevTools
175
172
  end # WebDriver