selenium-webdriver 4.1.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +405 -1
  3. data/Gemfile +3 -0
  4. data/LICENSE +1 -1
  5. data/NOTICE +1 -1
  6. data/README.md +3 -3
  7. data/bin/linux/selenium-manager +0 -0
  8. data/bin/macos/selenium-manager +0 -0
  9. data/bin/windows/selenium-manager.exe +0 -0
  10. data/lib/selenium/server.rb +38 -40
  11. data/lib/selenium/webdriver/atoms/findElements.js +27 -27
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +6 -100
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +24 -96
  14. data/lib/selenium/webdriver/atoms/mutationListener.js +0 -0
  15. data/lib/selenium/webdriver/atoms.rb +5 -3
  16. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  17. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  18. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  19. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  20. data/lib/selenium/webdriver/{common/driver_extensions/has_location.rb → bidi/log/filter_by.rb} +14 -11
  21. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  22. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  23. data/lib/selenium/webdriver/bidi/log_handler.rb +63 -0
  24. data/lib/selenium/webdriver/bidi/log_inspector.rb +147 -0
  25. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  26. data/lib/selenium/webdriver/bidi/session.rb +51 -0
  27. data/lib/selenium/webdriver/bidi/struct.rb +44 -0
  28. data/lib/selenium/webdriver/bidi.rb +66 -0
  29. data/lib/selenium/webdriver/chrome/driver.rb +9 -29
  30. data/lib/selenium/webdriver/chrome/features.rb +9 -67
  31. data/lib/selenium/webdriver/chrome/options.rb +3 -223
  32. data/lib/selenium/webdriver/chrome/profile.rb +3 -83
  33. data/lib/selenium/webdriver/chrome/service.rb +4 -19
  34. data/lib/selenium/webdriver/chrome.rb +0 -16
  35. data/lib/selenium/webdriver/chromium/driver.rb +61 -0
  36. data/lib/selenium/webdriver/chromium/features.rb +99 -0
  37. data/lib/selenium/webdriver/chromium/options.rb +243 -0
  38. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  39. data/lib/selenium/webdriver/chromium.rb +29 -0
  40. data/lib/selenium/webdriver/common/action_builder.rb +60 -22
  41. data/lib/selenium/webdriver/common/child_process.rb +130 -0
  42. data/lib/selenium/webdriver/common/driver.rb +46 -90
  43. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +0 -1
  45. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  46. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +0 -2
  47. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +0 -2
  48. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_bidi.rb} +10 -5
  49. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +10 -1
  50. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +0 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +1 -4
  52. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  53. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +0 -2
  54. data/lib/selenium/webdriver/common/driver_extensions/has_fedcm_dialog.rb +55 -0
  55. data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
  56. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +0 -2
  57. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +2 -3
  58. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +0 -2
  59. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +2 -69
  60. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +0 -2
  61. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +1 -3
  62. data/lib/selenium/webdriver/common/driver_finder.rb +97 -0
  63. data/lib/selenium/webdriver/common/element.rb +8 -8
  64. data/lib/selenium/webdriver/common/error.rb +27 -4
  65. data/lib/selenium/webdriver/common/fedcm/account.rb +50 -0
  66. data/lib/selenium/webdriver/common/fedcm/dialog.rb +74 -0
  67. data/lib/selenium/webdriver/common/fedcm.rb +27 -0
  68. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  69. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  70. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -25
  71. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  72. data/lib/selenium/webdriver/common/interactions/key_actions.rb +5 -1
  73. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  74. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  75. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  76. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +59 -71
  77. data/lib/selenium/webdriver/common/{driver_extensions/has_network_connection.rb → interactions/pointer_cancel.rb} +19 -11
  78. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  79. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  80. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  81. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  82. data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
  83. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  84. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  85. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +114 -0
  86. data/lib/selenium/webdriver/common/interactions/wheel_input.rb +42 -0
  87. data/lib/selenium/webdriver/common/keys.rb +1 -0
  88. data/lib/selenium/webdriver/common/local_driver.rb +53 -0
  89. data/lib/selenium/webdriver/common/logger.rb +93 -28
  90. data/lib/selenium/webdriver/common/manager.rb +1 -28
  91. data/lib/selenium/webdriver/common/options.rb +19 -19
  92. data/lib/selenium/webdriver/common/platform.rb +12 -52
  93. data/lib/selenium/webdriver/common/port_prober.rb +1 -1
  94. data/lib/selenium/webdriver/common/profile_helper.rb +1 -1
  95. data/lib/selenium/webdriver/common/proxy.rb +4 -4
  96. data/lib/selenium/webdriver/common/script.rb +45 -0
  97. data/lib/selenium/webdriver/common/search_context.rb +10 -8
  98. data/lib/selenium/webdriver/common/selenium_manager.rb +104 -0
  99. data/lib/selenium/webdriver/common/service.rb +21 -30
  100. data/lib/selenium/webdriver/common/service_manager.rb +8 -15
  101. data/lib/selenium/webdriver/common/shadow_root.rb +2 -3
  102. data/lib/selenium/webdriver/common/socket_lock.rb +3 -3
  103. data/lib/selenium/webdriver/common/socket_poller.rb +3 -3
  104. data/lib/selenium/webdriver/common/takes_screenshot.rb +6 -5
  105. data/lib/selenium/webdriver/common/target_locator.rb +2 -3
  106. data/lib/selenium/webdriver/common/timeouts.rb +2 -2
  107. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
  108. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
  109. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
  110. data/lib/selenium/webdriver/common/websocket_connection.rb +176 -0
  111. data/lib/selenium/webdriver/common/window.rb +6 -6
  112. data/lib/selenium/webdriver/common/zipper.rb +1 -1
  113. data/lib/selenium/webdriver/common.rb +26 -5
  114. data/lib/selenium/webdriver/devtools/console_event.rb +0 -2
  115. data/lib/selenium/webdriver/devtools/exception_event.rb +0 -2
  116. data/lib/selenium/webdriver/devtools/mutation_event.rb +0 -2
  117. data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
  118. data/lib/selenium/webdriver/devtools/pinned_script.rb +0 -2
  119. data/lib/selenium/webdriver/devtools/request.rb +1 -3
  120. data/lib/selenium/webdriver/devtools/response.rb +1 -3
  121. data/lib/selenium/webdriver/devtools.rb +17 -114
  122. data/lib/selenium/webdriver/edge/driver.rb +9 -3
  123. data/lib/selenium/webdriver/edge/features.rb +8 -4
  124. data/lib/selenium/webdriver/edge/options.rb +17 -5
  125. data/lib/selenium/webdriver/edge/profile.rb +2 -2
  126. data/lib/selenium/webdriver/edge/service.rb +8 -7
  127. data/lib/selenium/webdriver/edge.rb +0 -2
  128. data/lib/selenium/webdriver/firefox/driver.rb +9 -2
  129. data/lib/selenium/webdriver/firefox/features.rb +11 -7
  130. data/lib/selenium/webdriver/firefox/options.rb +10 -16
  131. data/lib/selenium/webdriver/firefox/profile.rb +21 -17
  132. data/lib/selenium/webdriver/firefox/profiles_ini.rb +1 -1
  133. data/lib/selenium/webdriver/firefox/service.rb +0 -18
  134. data/lib/selenium/webdriver/firefox/util.rb +46 -0
  135. data/lib/selenium/webdriver/firefox.rb +1 -14
  136. data/lib/selenium/webdriver/ie/driver.rb +7 -1
  137. data/lib/selenium/webdriver/ie/features.rb +34 -0
  138. data/lib/selenium/webdriver/ie/options.rb +6 -4
  139. data/lib/selenium/webdriver/ie/service.rb +0 -22
  140. data/lib/selenium/webdriver/ie.rb +4 -17
  141. data/lib/selenium/webdriver/remote/bidi_bridge.rb +44 -0
  142. data/lib/selenium/webdriver/remote/{commands.rb → bridge/commands.rb} +22 -9
  143. data/lib/selenium/webdriver/remote/bridge/locator_converter.rb +76 -0
  144. data/lib/selenium/webdriver/remote/bridge.rb +147 -99
  145. data/lib/selenium/webdriver/remote/capabilities.rb +5 -55
  146. data/lib/selenium/webdriver/remote/driver.rb +35 -14
  147. data/lib/selenium/webdriver/remote/features.rb +75 -0
  148. data/lib/selenium/webdriver/remote/http/common.rb +24 -6
  149. data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
  150. data/lib/selenium/webdriver/remote/http/default.rb +8 -14
  151. data/lib/selenium/webdriver/remote/response.rb +8 -34
  152. data/lib/selenium/webdriver/remote/server_error.rb +2 -2
  153. data/lib/selenium/webdriver/remote.rb +2 -1
  154. data/lib/selenium/webdriver/safari/driver.rb +7 -1
  155. data/lib/selenium/webdriver/safari/features.rb +5 -3
  156. data/lib/selenium/webdriver/safari/options.rb +5 -1
  157. data/lib/selenium/webdriver/safari/service.rb +10 -4
  158. data/lib/selenium/webdriver/safari.rb +1 -15
  159. data/lib/selenium/webdriver/support/color.rb +22 -22
  160. data/lib/selenium/webdriver/support/event_firing_bridge.rb +4 -4
  161. data/lib/selenium/webdriver/support/guards/guard.rb +14 -14
  162. data/lib/selenium/webdriver/support/guards/guard_condition.rb +1 -3
  163. data/lib/selenium/webdriver/support/guards.rb +2 -2
  164. data/lib/selenium/webdriver/support/relative_locator.rb +0 -1
  165. data/lib/selenium/webdriver/support/select.rb +3 -1
  166. data/lib/selenium/webdriver/version.rb +1 -1
  167. data/lib/selenium/webdriver.rb +7 -5
  168. data/selenium-webdriver.gemspec +20 -16
  169. metadata +135 -47
  170. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -65
  171. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +0 -63
  172. data/lib/selenium/webdriver/support/cdp_client_generator.rb +0 -108
@@ -26,10 +26,18 @@ module Selenium
26
26
  CONTENT_TYPE = 'application/json'
27
27
  DEFAULT_HEADERS = {
28
28
  'Accept' => CONTENT_TYPE,
29
- 'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8",
30
- 'User-Agent' => "selenium/#{WebDriver::VERSION} (ruby #{Platform.os})"
29
+ 'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8"
31
30
  }.freeze
32
31
 
32
+ class << self
33
+ attr_accessor :extra_headers
34
+ attr_writer :user_agent
35
+
36
+ def user_agent
37
+ @user_agent ||= "selenium/#{WebDriver::VERSION} (ruby #{Platform.os})"
38
+ end
39
+ end
40
+
33
41
  attr_writer :server_url
34
42
 
35
43
  def quit_errors
@@ -42,15 +50,15 @@ module Selenium
42
50
 
43
51
  def call(verb, url, command_hash)
44
52
  url = server_url.merge(url) unless url.is_a?(URI)
45
- headers = DEFAULT_HEADERS.dup
53
+ headers = common_headers.dup
46
54
  headers['Cache-Control'] = 'no-cache' if verb == :get
47
55
 
48
56
  if command_hash
49
57
  payload = JSON.generate(command_hash)
50
58
  headers['Content-Length'] = payload.bytesize.to_s if %i[post put].include?(verb)
51
59
 
52
- WebDriver.logger.info(" >>> #{url} | #{payload}")
53
- WebDriver.logger.debug(" > #{headers.inspect}")
60
+ WebDriver.logger.debug(" >>> #{url} | #{payload}", id: :command)
61
+ WebDriver.logger.debug(" > #{headers.inspect}", id: :header)
54
62
  elsif verb == :post
55
63
  payload = '{}'
56
64
  headers['Content-Length'] = '2'
@@ -61,6 +69,16 @@ module Selenium
61
69
 
62
70
  private
63
71
 
72
+ def common_headers
73
+ @common_headers ||= begin
74
+ headers = DEFAULT_HEADERS.dup
75
+ headers['User-Agent'] = Common.user_agent
76
+ headers = headers.merge(Common.extra_headers || {})
77
+
78
+ headers
79
+ end
80
+ end
81
+
64
82
  def server_url
65
83
  return @server_url if @server_url
66
84
 
@@ -75,7 +93,7 @@ module Selenium
75
93
  code = code.to_i
76
94
  body = body.to_s.strip
77
95
  content_type = content_type.to_s
78
- WebDriver.logger.info("<- #{body}")
96
+ WebDriver.logger.debug("<- #{body}", id: :command)
79
97
 
80
98
  if content_type.include? CONTENT_TYPE
81
99
  raise Error::WebDriverError, "empty body: #{content_type.inspect} (#{code})\n#{body}" if body.empty?
@@ -22,7 +22,6 @@ require 'curb'
22
22
  module Selenium
23
23
  module WebDriver
24
24
  module Remote
25
-
26
25
  module Http
27
26
  #
28
27
  # An alternative to the default Net::HTTP client.
@@ -38,7 +37,6 @@ module Selenium
38
37
  #
39
38
 
40
39
  class Curb < Common
41
-
42
40
  def quit_errors
43
41
  [Curl::Err::RecvError] + super
44
42
  end
@@ -85,7 +83,7 @@ module Selenium
85
83
  c.max_redirects = MAX_REDIRECTS
86
84
  c.follow_location = true
87
85
  c.timeout = @timeout if @timeout
88
- c.verbose = WebDriver.logger.info?
86
+ c.verbose = WebDriver.logger.debug?
89
87
 
90
88
  c
91
89
  end
@@ -16,8 +16,6 @@
16
16
  # KIND, either express or implied. See the License for the
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
-
20
- require 'net/https'
21
19
  require 'ipaddr'
22
20
 
23
21
  module Selenium
@@ -75,9 +73,10 @@ module Selenium
75
73
  begin
76
74
  request = new_request_for(verb, url, headers, payload)
77
75
  response = response_for(request)
78
- rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
79
- # a retry is sometimes needed on Windows XP where we may quickly
80
- # run out of ephemeral ports
76
+ rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE, Errno::EADDRNOTAVAIL
77
+ # a retry is sometimes needed:
78
+ # on Windows XP where we may quickly run out of ephemeral ports
79
+ # when the port becomes temporarily unavailable
81
80
  #
82
81
  # A more robust solution is bumping the MaxUserPort setting
83
82
  # as described here:
@@ -85,13 +84,6 @@ module Selenium
85
84
  # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
86
85
  raise if retries >= MAX_RETRIES
87
86
 
88
- retries += 1
89
- sleep 2
90
- retry
91
- rescue Errno::EADDRNOTAVAIL => e
92
- # a retry is sometimes needed when the port becomes temporarily unavailable
93
- raise if retries >= MAX_RETRIES
94
-
95
87
  retries += 1
96
88
  sleep 2
97
89
  retry
@@ -102,10 +94,12 @@ module Selenium
102
94
  end
103
95
 
104
96
  if response.is_a? Net::HTTPRedirection
97
+ WebDriver.logger.debug("Redirect to #{response['Location']}; times: #{redirects}")
105
98
  raise Error::WebDriverError, 'too many redirects' if redirects >= MAX_REDIRECTS
106
99
 
107
100
  request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
108
101
  else
102
+ WebDriver.logger.debug(" <<< #{response.instance_variable_get(:@header).inspect}", id: :header)
109
103
  create_response response.code, response.body, response.content_type
110
104
  end
111
105
  end
@@ -142,8 +136,8 @@ module Selenium
142
136
 
143
137
  def proxy
144
138
  @proxy ||= begin
145
- proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
146
- no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
139
+ proxy = ENV.fetch('http_proxy', nil) || ENV.fetch('HTTP_PROXY', nil)
140
+ no_proxy = ENV.fetch('no_proxy', nil) || ENV.fetch('NO_PROXY', nil)
147
141
 
148
142
  if proxy
149
143
  proxy = "http://#{proxy}" unless proxy.start_with?('http://')
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Remote
23
-
24
23
  #
25
24
  # @api private
26
25
  #
@@ -29,7 +28,7 @@ module Selenium
29
28
  attr_reader :code, :payload
30
29
 
31
30
  def initialize(code, payload = nil)
32
- @code = code
31
+ @code = code
33
32
  @payload = payload || {}
34
33
 
35
34
  assert_ok
@@ -38,11 +37,8 @@ module Selenium
38
37
  def error
39
38
  error, message, backtrace = process_error
40
39
  klass = Error.for_error(error) || return
41
-
42
40
  ex = klass.new(message)
43
- ex.set_backtrace(caller)
44
- add_backtrace ex, backtrace
45
-
41
+ add_cause(ex, error, backtrace)
46
42
  ex
47
43
  end
48
44
 
@@ -60,34 +56,12 @@ module Selenium
60
56
  raise Error::ServerError, self
61
57
  end
62
58
 
63
- def add_backtrace(ex, server_trace)
64
- return unless server_trace
65
-
66
- backtrace = case server_trace
67
- when Array
68
- backtrace_from_remote(server_trace)
69
- when String
70
- server_trace.split("\n")
71
- end
72
-
73
- ex.set_backtrace(backtrace + ex.backtrace)
74
- end
75
-
76
- def backtrace_from_remote(server_trace)
77
- server_trace.map { |frame|
78
- next unless frame.is_a?(Hash)
79
-
80
- file = frame['fileName']
81
- line = frame['lineNumber']
82
- meth = frame['methodName']
83
-
84
- class_name = frame['className']
85
- file = "#{class_name}(#{file})" if class_name
86
-
87
- meth = 'unknown' if meth.nil? || meth.empty?
88
-
89
- "[remote server] #{file}:#{line}:in `#{meth}'"
90
- }.compact
59
+ def add_cause(ex, error, backtrace)
60
+ cause = Error::WebDriverError.new
61
+ cause.set_backtrace(backtrace)
62
+ raise ex, cause: cause
63
+ rescue Error.for_error(error)
64
+ ex
91
65
  end
92
66
 
93
67
  def process_error
@@ -23,9 +23,9 @@ module Selenium
23
23
  class ServerError < StandardError
24
24
  def initialize(response)
25
25
  if response.is_a? String
26
- super(response)
26
+ super
27
27
  else
28
- super("status code #{response.code}")
28
+ super("status code #{response.code}; payload #{response.payload}")
29
29
  end
30
30
  end
31
31
  end # ServerError
@@ -23,11 +23,12 @@ require 'selenium/webdriver/remote/server_error'
23
23
  module Selenium
24
24
  module WebDriver
25
25
  module Remote
26
+ autoload :Features, 'selenium/webdriver/remote/features'
26
27
  autoload :Bridge, 'selenium/webdriver/remote/bridge'
28
+ autoload :BiDiBridge, 'selenium/webdriver/remote/bidi_bridge'
27
29
  autoload :Driver, 'selenium/webdriver/remote/driver'
28
30
  autoload :Response, 'selenium/webdriver/remote/response'
29
31
  autoload :Capabilities, 'selenium/webdriver/remote/capabilities'
30
- autoload :COMMANDS, 'selenium/webdriver/remote/commands'
31
32
 
32
33
  module Http
33
34
  autoload :Common, 'selenium/webdriver/remote/http/common'
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Safari
23
-
24
23
  #
25
24
  # Driver implementation for Safari.
26
25
  # @api private
@@ -31,6 +30,13 @@ module Selenium
31
30
  DriverExtensions::HasApplePermissions,
32
31
  DriverExtensions::HasWebStorage].freeze
33
32
 
33
+ include LocalDriver
34
+
35
+ def initialize(options: nil, service: nil, url: nil, **opts)
36
+ caps, url = initialize_local_driver(options, service, url)
37
+ super(caps: caps, url: url, **opts)
38
+ end
39
+
34
40
  def browser
35
41
  :safari
36
42
  end
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module Safari
23
23
  module Features
24
-
25
24
  # https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/WebDriverEndpointDoc/Commands/Commands.html
26
25
  SAFARI_COMMANDS = {
27
26
  get_permissions: [:get, 'session/:session_id/apple/permissions'],
@@ -29,8 +28,12 @@ module Selenium
29
28
  attach_debugger: [:post, 'session/:session_id/apple/attach_debugger']
30
29
  }.freeze
31
30
 
31
+ def command_list
32
+ SAFARI_COMMANDS.merge(self.class::COMMANDS)
33
+ end
34
+
32
35
  def commands(command)
33
- SAFARI_COMMANDS[command] || self.class::COMMANDS[command]
36
+ command_list[command]
34
37
  end
35
38
 
36
39
  def permissions
@@ -44,7 +47,6 @@ module Selenium
44
47
  def attach_debugger
45
48
  execute :attach_debugger, {}, {}
46
49
  end
47
-
48
50
  end # Bridge
49
51
  end # Safari
50
52
  end # WebDriver
@@ -26,7 +26,7 @@ module Selenium
26
26
  # @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
27
27
  CAPABILITIES = {automatic_inspection: 'safari:automaticInspection',
28
28
  automatic_profiling: 'safari:automaticProfiling'}.freeze
29
- BROWSER = 'safari'
29
+ BROWSER = Selenium::WebDriver::Safari.technology_preview? ? 'Safari Technology Preview' : 'safari'
30
30
 
31
31
  def add_option(name, value = nil)
32
32
  key = name.is_a?(Hash) ? name.keys.first : name
@@ -35,6 +35,10 @@ module Selenium
35
35
  super
36
36
  end
37
37
 
38
+ def as_json(*)
39
+ @options[:browser_name] = Safari.technology_preview? ? 'Safari Technology Preview' : 'safari'
40
+ super
41
+ end
38
42
  end # Options
39
43
  end # Safari
40
44
  end # WebDriver
@@ -23,11 +23,17 @@ module Selenium
23
23
  class Service < WebDriver::Service
24
24
  DEFAULT_PORT = 7050
25
25
  EXECUTABLE = 'safaridriver'
26
- MISSING_TEXT = <<~ERROR
27
- Unable to find Apple's safaridriver which comes with Safari 10.
28
- More info at https://webkit.org/blog/6900/webdriver-support-in-safari-10/
29
- ERROR
30
26
  SHUTDOWN_SUPPORTED = false
27
+
28
+ def initialize(path: nil, port: nil, log: nil, args: nil)
29
+ raise Error::WebDriverError, 'Safari Service does not support setting log output' if log
30
+
31
+ super
32
+ end
33
+
34
+ def log=(*)
35
+ raise Error::WebDriverError, 'Safari Service does not support setting log output'
36
+ end
31
37
  end # Service
32
38
  end # Safari
33
39
  end # WebDriver
@@ -29,7 +29,7 @@ module Selenium
29
29
  attr_accessor :use_technology_preview
30
30
 
31
31
  def technology_preview
32
- "/Applications/Safari\ Technology\ Preview.app/Contents/MacOS/safaridriver"
32
+ '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver'
33
33
  end
34
34
 
35
35
  def technology_preview!
@@ -53,20 +53,6 @@ module Selenium
53
53
 
54
54
  raise Error::WebDriverError, 'Unable to find Safari'
55
55
  end
56
-
57
- def driver_path=(path)
58
- WebDriver.logger.deprecate 'Selenium::WebDriver::Safari#driver_path=',
59
- 'Selenium::WebDriver::Safari::Service#driver_path=',
60
- id: :driver_path
61
- Selenium::WebDriver::Safari::Service.driver_path = path
62
- end
63
-
64
- def driver_path
65
- WebDriver.logger.deprecate 'Selenium::WebDriver::Safari#driver_path',
66
- 'Selenium::WebDriver::Safari::Service#driver_path',
67
- id: :driver_path
68
- Selenium::WebDriver::Safari::Service.driver_path
69
- end
70
56
  end
71
57
  end # Safari
72
58
  end # WebDriver
@@ -21,29 +21,29 @@ module Selenium
21
21
  module WebDriver
22
22
  module Support
23
23
  class Color
24
- RGB_PATTERN = %r{^\s*rgb\(\s*(\d{1,3})\s*,
24
+ RGB_PATTERN = /^\s*rgb\(\s*(\d{1,3})\s*,
25
25
  \s*(\d{1,3})\s*,
26
- \s*(\d{1,3})\s*\)\s*$}x.freeze
27
- RGB_PCT_PATTERN = %r{^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
26
+ \s*(\d{1,3})\s*\)\s*$/x
27
+ RGB_PCT_PATTERN = /^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
28
28
  \s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
29
- \s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$}x.freeze
30
- RGBA_PATTERN = %r{^\s*rgba\(\s*(\d{1,3})\s*,
29
+ \s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$/x
30
+ RGBA_PATTERN = /^\s*rgba\(\s*(\d{1,3})\s*,
31
31
  \s*(\d{1,3})\s*,
32
32
  \s*(\d{1,3})\s*,
33
- \s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
34
- RGBA_PCT_PATTERN = %r{^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)
33
+ \s*(0|1|0\.\d+)\s*\)\s*$/x
34
+ RGBA_PCT_PATTERN = /^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)
35
35
  %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
36
36
  %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
37
- %\s*,\s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
38
- HEX_PATTERN = /#(\h{2})(\h{2})(\h{2})/.freeze
39
- HEX3_PATTERN = /#(\h)(\h)(\h)/.freeze
40
- HSL_PATTERN = %r{^\s*hsl\(\s*(\d{1,3})\s*,
37
+ %\s*,\s*(0|1|0\.\d+)\s*\)\s*$/x
38
+ HEX_PATTERN = /#(\h{2})(\h{2})(\h{2})/
39
+ HEX3_PATTERN = /#(\h)(\h)(\h)/
40
+ HSL_PATTERN = /^\s*hsl\(\s*(\d{1,3})\s*,
41
41
  \s*(\d{1,3})%\s*,
42
- \s*(\d{1,3})%\s*\)\s*$}x.freeze
43
- HSLA_PATTERN = %r{^\s*hsla\(\s*(\d{1,3})\s*,
42
+ \s*(\d{1,3})%\s*\)\s*$/x
43
+ HSLA_PATTERN = /^\s*hsla\(\s*(\d{1,3})\s*,
44
44
  \s*(\d{1,3})%\s*,
45
45
  \s*(\d{1,3})%\s*,
46
- \s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
46
+ \s*(0|1|0\.\d+)\s*\)\s*$/x
47
47
 
48
48
  attr_reader :red, :green, :blue, :alpha
49
49
 
@@ -83,12 +83,12 @@ module Selenium
83
83
  g = r
84
84
  b = r
85
85
  else
86
- luminocity2 = l < 0.5 ? l * (1 + s) : l + s - l * s
87
- luminocity1 = 2 * l - luminocity2
86
+ luminocity2 = l < 0.5 ? l * (s + 1) : l + s - (l * s)
87
+ luminocity1 = (l * 2) - luminocity2
88
88
 
89
- r = hue_to_rgb(luminocity1, luminocity2, h + 1.0 / 3.0)
89
+ r = hue_to_rgb(luminocity1, luminocity2, h + (1.0 / 3.0))
90
90
  g = hue_to_rgb(luminocity1, luminocity2, h)
91
- b = hue_to_rgb(luminocity1, luminocity2, h - 1.0 / 3.0)
91
+ b = hue_to_rgb(luminocity1, luminocity2, h - (1.0 / 3.0))
92
92
  end
93
93
 
94
94
  new (r * 255).round, (g * 255).round, (b * 255).round, a
@@ -99,11 +99,11 @@ module Selenium
99
99
  hue -= 1 if hue > 1.0
100
100
 
101
101
  if hue < 1.0 / 6.0
102
- (lum1 + (lum2 - lum1) * 6.0 * hue)
102
+ (lum1 + ((lum2 - lum1) * 6.0 * hue))
103
103
  elsif hue < 1.0 / 2.0
104
104
  lum2
105
105
  elsif hue < 2.0 / 3.0
106
- lum1 + (lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0
106
+ lum1 + ((lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0)
107
107
  else
108
108
  lum1
109
109
  end
@@ -122,10 +122,10 @@ module Selenium
122
122
 
123
123
  [red, green, blue, alpha] == [other.red, other.green, other.blue, other.alpha]
124
124
  end
125
- alias_method :eql?, :==
125
+ alias eql? ==
126
126
 
127
127
  def hash
128
- [red, green, blue, alpha].hash ^ self.class.hash
128
+ [red, green, blue, alpha, self.class].hash
129
129
  end
130
130
 
131
131
  def rgb
@@ -113,15 +113,15 @@ module Selenium
113
113
  end
114
114
 
115
115
  def dispatch(name, *args)
116
- @listener.__send__("before_#{name}", *args)
116
+ @listener.__send__(:"before_#{name}", *args)
117
117
  returned = yield
118
- @listener.__send__("after_#{name}", *args)
118
+ @listener.__send__(:"after_#{name}", *args)
119
119
 
120
120
  returned
121
121
  end
122
122
 
123
- def method_missing(meth, *args, &blk) # rubocop:disable Style/MissingRespondToMissing
124
- @delegate.__send__(meth, *args, &blk)
123
+ def method_missing(meth, ...) # rubocop:disable Style/MissingRespondToMissing
124
+ @delegate.__send__(meth, ...)
125
125
  end
126
126
  end # EventFiringBridge
127
127
  end # Support
@@ -21,15 +21,13 @@ module Selenium
21
21
  module WebDriver
22
22
  module Support
23
23
  class Guards
24
-
25
24
  #
26
25
  # Guard derived from RSpec example metadata.
27
26
  # @api private
28
27
  #
29
28
 
30
29
  class Guard
31
-
32
- attr_reader :guarded, :type, :messages, :reason
30
+ attr_reader :guarded, :type, :messages, :reason, :tracker
33
31
 
34
32
  def initialize(guarded, type, guards = nil)
35
33
  @guarded = guarded
@@ -38,24 +36,25 @@ module Selenium
38
36
  @messages[:unknown] = 'TODO: Investigate why this is failing and file a bug report'
39
37
  @type = type
40
38
 
41
- @reason = @guarded.delete(:reason)
39
+ @reason = @guarded[:reason] || 'No reason given'
40
+ @guarded[:reason] = @reason
42
41
  end
43
42
 
44
43
  def message
45
- details = case @reason
44
+ details = case reason
46
45
  when Integer
47
- "Bug Filed: #{@tracker}/#{@reason}"
46
+ "Bug Filed: #{tracker}/#{reason}"
48
47
  when Symbol
49
- @messages[@reason]
50
- when String
51
- @reason
48
+ messages[reason]
52
49
  else
53
- 'no reason given'
50
+ "Guarded by #{guarded};"
54
51
  end
55
52
 
56
- case @type
53
+ case type
57
54
  when :exclude
58
- "Test not guarded because it breaks test run; #{details}"
55
+ "Test skipped because it breaks test run; #{details}"
56
+ when :flaky
57
+ "Test skipped because it is unreliable in this configuration; #{details}"
59
58
  when :exclusive
60
59
  "Test does not apply to this configuration; #{details}"
61
60
  else
@@ -73,9 +72,10 @@ module Selenium
73
72
  @type == :only
74
73
  end
75
74
 
76
- # Bug is present on all configurations specified, but test can not be run because it breaks other tests
75
+ # Bug is present on all configurations specified, but test can not be run because it breaks other tests,
76
+ # or it is flaky and unreliable
77
77
  def exclude?
78
- @type == :exclude
78
+ @type == :exclude || @type == :flaky
79
79
  end
80
80
 
81
81
  # Test only applies to configurations specified
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module Support
23
23
  class Guards
24
-
25
24
  #
26
25
  # Guard derived from RSpec example metadata.
27
26
  # @api private
@@ -32,7 +31,7 @@ module Selenium
32
31
 
33
32
  def initialize(name, condition = nil, &blk)
34
33
  @name = name
35
- @execution = if block_given?
34
+ @execution = if blk
36
35
  proc(&blk)
37
36
  else
38
37
  proc { |guarded| guarded.include?(condition) }
@@ -44,7 +43,6 @@ module Selenium
44
43
 
45
44
  list.empty? || @execution.call(list)
46
45
  end
47
-
48
46
  end # GuardCondition
49
47
  end # Guards
50
48
  end # Support
@@ -24,7 +24,7 @@ module Selenium
24
24
  module WebDriver
25
25
  module Support
26
26
  class Guards
27
- GUARD_TYPES = %i[except only exclude exclusive].freeze
27
+ GUARD_TYPES = %i[except only exclude exclusive flaky].freeze
28
28
 
29
29
  attr_reader :messages
30
30
  attr_accessor :bug_tracker
@@ -48,7 +48,7 @@ module Selenium
48
48
  def disposition
49
49
  if !skipping_guard.nil?
50
50
  [:skip, skipping_guard.message]
51
- elsif !pending_guard.nil? && ENV['SKIP_PENDING']
51
+ elsif !pending_guard.nil? && ENV.fetch('SKIP_PENDING', nil)
52
52
  [:skip, pending_guard.message]
53
53
  elsif !pending_guard.nil?
54
54
  [:pending, pending_guard.message]
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  #
25
24
  # @api private
26
25
  #
@@ -86,7 +86,7 @@ module Selenium
86
86
  #
87
87
  # <option value="foo">Bar</option>
88
88
  #
89
- # When slecting by :value, selects all options that have a value matching the argument. That is, when given "foo" this
89
+ # When selecting by :value, selects all options that have a value matching the argument. That is, when given "foo" this
90
90
  # would select an option like:
91
91
  #
92
92
  # <option value="foo">Bar</option>
@@ -215,6 +215,8 @@ module Selenium
215
215
  end
216
216
 
217
217
  def select_option(option)
218
+ raise Error::UnsupportedOperationError, 'You may not select a disabled option' unless option.enabled?
219
+
218
220
  option.click unless option.selected?
219
221
  end
220
222
 
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- VERSION = '4.1.0'
22
+ VERSION = '4.23.0'
23
23
  end # WebDriver
24
24
  end # Selenium