selenium-webdriver 3.142.7 → 4.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +685 -5
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/NOTICE +2 -0
  6. data/README.md +4 -5
  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 +93 -90
  11. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +77 -78
  14. data/lib/selenium/webdriver/atoms/mutationListener.js +55 -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/bidi/log/filter_by.rb +40 -0
  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_inspector.rb +143 -0
  24. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  25. data/lib/selenium/webdriver/bidi/session.rb +51 -0
  26. data/lib/selenium/webdriver/{common/keyboard.rb → bidi.rb} +21 -35
  27. data/lib/selenium/webdriver/chrome/driver.rb +9 -86
  28. data/lib/selenium/webdriver/chrome/features.rb +48 -0
  29. data/lib/selenium/webdriver/chrome/options.rb +9 -158
  30. data/lib/selenium/webdriver/chrome/profile.rb +3 -80
  31. data/lib/selenium/webdriver/chrome/service.rb +7 -29
  32. data/lib/selenium/webdriver/chrome.rb +5 -20
  33. data/lib/selenium/webdriver/chromium/driver.rb +60 -0
  34. data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +48 -17
  35. data/lib/selenium/webdriver/chromium/options.rb +243 -0
  36. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  37. data/lib/selenium/webdriver/chromium.rb +29 -0
  38. data/lib/selenium/webdriver/common/action_builder.rb +126 -238
  39. data/lib/selenium/webdriver/common/child_process.rb +124 -0
  40. data/lib/selenium/webdriver/common/driver.rb +82 -43
  41. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/{has_location.rb → full_page_screenshot.rb} +13 -11
  43. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +49 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +87 -0
  46. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +9 -9
  47. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +86 -0
  48. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +36 -0
  49. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +42 -0
  50. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +41 -0
  52. data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
  53. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +36 -0
  54. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  55. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
  56. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +16 -1
  57. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +69 -0
  58. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -13
  59. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +75 -0
  60. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  61. data/lib/selenium/webdriver/common/driver_finder.rb +45 -0
  62. data/lib/selenium/webdriver/common/element.rb +89 -29
  63. data/lib/selenium/webdriver/common/error.rb +53 -194
  64. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  65. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  66. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
  67. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  68. data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
  69. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  70. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  71. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  72. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +71 -82
  73. data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
  74. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  75. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  76. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  77. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  78. data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
  79. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  80. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  81. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
  82. data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
  83. data/lib/selenium/webdriver/common/keys.rb +1 -0
  84. data/lib/selenium/webdriver/common/local_driver.rb +46 -0
  85. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  86. data/lib/selenium/webdriver/common/logger.rb +119 -19
  87. data/lib/selenium/webdriver/common/manager.rb +11 -38
  88. data/lib/selenium/webdriver/common/options.rb +154 -23
  89. data/lib/selenium/webdriver/common/platform.rb +15 -52
  90. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  91. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  92. data/lib/selenium/webdriver/common/proxy.rb +8 -5
  93. data/lib/selenium/webdriver/common/search_context.rb +7 -9
  94. data/lib/selenium/webdriver/common/selenium_manager.rb +140 -0
  95. data/lib/selenium/webdriver/common/service.rb +26 -143
  96. data/lib/selenium/webdriver/common/service_manager.rb +144 -0
  97. data/lib/selenium/webdriver/common/shadow_root.rb +86 -0
  98. data/lib/selenium/webdriver/common/socket_lock.rb +4 -4
  99. data/lib/selenium/webdriver/common/socket_poller.rb +4 -4
  100. data/lib/selenium/webdriver/common/takes_screenshot.rb +65 -0
  101. data/lib/selenium/webdriver/common/target_locator.rb +31 -4
  102. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  103. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
  104. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
  105. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
  106. data/lib/selenium/webdriver/common/wait.rb +1 -1
  107. data/lib/selenium/webdriver/common/websocket_connection.rb +164 -0
  108. data/lib/selenium/webdriver/common/window.rb +6 -10
  109. data/lib/selenium/webdriver/common/zipper.rb +4 -10
  110. data/lib/selenium/webdriver/common.rb +43 -20
  111. data/lib/selenium/webdriver/devtools/console_event.rb +36 -0
  112. data/lib/selenium/webdriver/devtools/exception_event.rb +34 -0
  113. data/lib/selenium/webdriver/devtools/mutation_event.rb +35 -0
  114. data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
  115. data/lib/selenium/webdriver/devtools/pinned_script.rb +57 -0
  116. data/lib/selenium/webdriver/devtools/request.rb +65 -0
  117. data/lib/selenium/webdriver/devtools/response.rb +64 -0
  118. data/lib/selenium/webdriver/devtools.rb +96 -0
  119. data/lib/selenium/webdriver/edge/driver.rb +11 -27
  120. data/lib/selenium/webdriver/edge/features.rb +48 -0
  121. data/lib/selenium/webdriver/edge/options.rb +18 -43
  122. data/lib/selenium/webdriver/edge/profile.rb +33 -0
  123. data/lib/selenium/webdriver/edge/service.rb +8 -23
  124. data/lib/selenium/webdriver/edge.rb +11 -16
  125. data/lib/selenium/webdriver/firefox/driver.rb +38 -19
  126. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  127. data/lib/selenium/webdriver/firefox/features.rb +70 -0
  128. data/lib/selenium/webdriver/firefox/options.rb +73 -61
  129. data/lib/selenium/webdriver/firefox/profile.rb +20 -72
  130. data/lib/selenium/webdriver/firefox/service.rb +3 -25
  131. data/lib/selenium/webdriver/firefox/util.rb +1 -1
  132. data/lib/selenium/webdriver/firefox.rb +17 -28
  133. data/lib/selenium/webdriver/ie/driver.rb +5 -45
  134. data/lib/selenium/webdriver/ie/features.rb +34 -0
  135. data/lib/selenium/webdriver/ie/options.rb +14 -44
  136. data/lib/selenium/webdriver/ie/service.rb +3 -27
  137. data/lib/selenium/webdriver/ie.rb +4 -16
  138. data/lib/selenium/webdriver/remote/bridge/commands.rb +164 -0
  139. data/lib/selenium/webdriver/remote/bridge.rb +574 -88
  140. data/lib/selenium/webdriver/remote/capabilities.rb +144 -158
  141. data/lib/selenium/webdriver/remote/driver.rb +45 -14
  142. data/lib/selenium/webdriver/remote/features.rb +75 -0
  143. data/lib/selenium/webdriver/remote/http/common.rb +3 -8
  144. data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
  145. data/lib/selenium/webdriver/remote/http/default.rb +24 -33
  146. data/lib/selenium/webdriver/remote/response.rb +17 -49
  147. data/lib/selenium/webdriver/remote/server_error.rb +1 -1
  148. data/lib/selenium/webdriver/remote.rb +15 -12
  149. data/lib/selenium/webdriver/safari/driver.rb +7 -29
  150. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +7 -5
  151. data/lib/selenium/webdriver/safari/options.rb +12 -27
  152. data/lib/selenium/webdriver/safari/service.rb +13 -11
  153. data/lib/selenium/webdriver/safari.rb +14 -20
  154. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  155. data/lib/selenium/webdriver/support/color.rb +24 -24
  156. data/lib/selenium/webdriver/support/event_firing_bridge.rb +5 -5
  157. data/lib/selenium/webdriver/support/guards/guard.rb +90 -0
  158. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +21 -20
  159. data/lib/selenium/webdriver/support/guards.rb +95 -0
  160. data/lib/selenium/webdriver/support/relative_locator.rb +50 -0
  161. data/lib/selenium/webdriver/support/select.rb +6 -4
  162. data/lib/selenium/webdriver/support.rb +1 -0
  163. data/lib/selenium/webdriver/version.rb +1 -1
  164. data/lib/selenium/webdriver.rb +19 -17
  165. data/selenium-webdriver.gemspec +36 -18
  166. metadata +161 -91
  167. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  168. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +0 -58
  169. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  170. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  171. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  172. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  173. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  174. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  175. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  176. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  177. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  178. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  179. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  180. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  181. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  182. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  183. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
  184. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  185. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  186. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  187. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  188. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -0,0 +1,140 @@
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
+ class << self
31
+ attr_writer :bin_path
32
+
33
+ def bin_path
34
+ @bin_path ||= '../../../../../bin'
35
+ end
36
+
37
+ # @param [Options] options browser options.
38
+ # @return [String] the path to the correct driver.
39
+ def driver_path(options)
40
+ command = generate_command(binary, options)
41
+
42
+ output = run(*command)
43
+
44
+ browser_path = Platform.cygwin? ? Platform.cygwin_path(output['browser_path']) : output['browser_path']
45
+ driver_path = Platform.cygwin? ? Platform.cygwin_path(output['driver_path']) : output['driver_path']
46
+ Platform.assert_executable driver_path
47
+
48
+ if options.respond_to?(:binary) && browser_path && !browser_path.empty?
49
+ options.binary = browser_path
50
+ options.browser_version = nil
51
+ end
52
+
53
+ driver_path
54
+ end
55
+
56
+ private
57
+
58
+ def generate_command(binary, options)
59
+ command = [binary, '--browser', options.browser_name]
60
+ if options.browser_version
61
+ command << '--browser-version'
62
+ command << options.browser_version
63
+ end
64
+ if options.respond_to?(:binary) && !options.binary.nil?
65
+ command << '--browser-path'
66
+ command << options.binary.gsub('\\', '\\\\\\')
67
+ end
68
+ if options.proxy
69
+ command << '--proxy'
70
+ command << (options.proxy.ssl || options.proxy.http)
71
+ end
72
+ command
73
+ end
74
+
75
+ # @return [String] the path to the correct selenium manager
76
+ def binary
77
+ @binary ||= begin
78
+ location = ENV.fetch('SE_MANAGER_PATH', begin
79
+ directory = File.expand_path(bin_path, __FILE__)
80
+ if Platform.windows?
81
+ "#{directory}/windows/selenium-manager.exe"
82
+ elsif Platform.mac?
83
+ "#{directory}/macos/selenium-manager"
84
+ elsif Platform.linux?
85
+ "#{directory}/linux/selenium-manager"
86
+ elsif Platform.unix?
87
+ WebDriver.logger.warn('Selenium Manager binary may not be compatible with Unix; verify settings',
88
+ id: %i[selenium_manager unix_binary])
89
+ "#{directory}/linux/selenium-manager"
90
+ end
91
+ rescue Error::WebDriverError => e
92
+ raise Error::WebDriverError, "Unable to obtain Selenium Manager binary for #{e.message}"
93
+ end)
94
+
95
+ validate_location(location)
96
+ location
97
+ end
98
+ end
99
+
100
+ def validate_location(location)
101
+ begin
102
+ Platform.assert_file(location)
103
+ Platform.assert_executable(location)
104
+ rescue TypeError
105
+ raise Error::WebDriverError,
106
+ "Unable to locate or obtain Selenium Manager binary; #{location} is not a valid file object"
107
+ rescue Error::WebDriverError => e
108
+ raise Error::WebDriverError, "Selenium Manager binary located, but #{e.message}"
109
+ end
110
+
111
+ WebDriver.logger.debug("Selenium Manager binary found at #{location}", id: :selenium_manager)
112
+ end
113
+
114
+ def run(*command)
115
+ command += %w[--output json]
116
+ command << '--debug' if WebDriver.logger.debug?
117
+
118
+ WebDriver.logger.debug("Executing Process #{command}", id: :selenium_manager)
119
+
120
+ begin
121
+ stdout, stderr, status = Open3.capture3(*command)
122
+ rescue StandardError => e
123
+ raise Error::WebDriverError, "Unsuccessful command executed: #{command}; #{e.message}"
124
+ end
125
+
126
+ json_output = stdout.empty? ? {} : JSON.parse(stdout)
127
+ (json_output['logs'] || []).each do |log|
128
+ level = log['level'].casecmp('info').zero? ? 'debug' : log['level'].downcase
129
+ WebDriver.logger.send(level, log['message'], id: :selenium_manager)
130
+ end
131
+
132
+ result = json_output['result']
133
+ return result unless status.exitstatus.positive?
134
+
135
+ raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{result}#{stderr}"
136
+ end
137
+ end
138
+ end # SeleniumManager
139
+ end # WebDriver
140
+ end # Selenium
@@ -21,51 +21,31 @@ module Selenium
21
21
  module WebDriver
22
22
  #
23
23
  # Base class implementing default behavior of service object,
24
- # responsible for starting and stopping driver implementations.
24
+ # responsible for storing a service manager configuration.
25
25
  #
26
26
 
27
27
  class Service
28
- START_TIMEOUT = 20
29
- SOCKET_LOCK_TIMEOUT = 45
30
- STOP_TIMEOUT = 20
31
-
32
- @default_port = nil
33
- @driver_path = nil
34
- @executable = nil
35
- @missing_text = nil
36
-
37
28
  class << self
38
- attr_reader :default_port, :driver_path, :executable, :missing_text, :shutdown_supported
29
+ attr_reader :driver_path
39
30
 
40
31
  def chrome(**opts)
41
32
  Chrome::Service.new(**opts)
42
33
  end
43
34
 
44
35
  def firefox(**opts)
45
- binary_path = Firefox::Binary.path
46
- args = opts.delete(:args)
47
- case args
48
- when Hash
49
- args[:binary] ||= binary_path
50
- opts[:args] = args
51
- when Array
52
- opts[:args] = ["--binary=#{binary_path}"]
53
- opts[:args] += args
54
- else
55
- opts[:args] = ["--binary=#{binary_path}"]
56
- end
57
-
58
36
  Firefox::Service.new(**opts)
59
37
  end
60
38
 
61
39
  def ie(**opts)
62
40
  IE::Service.new(**opts)
63
41
  end
64
- alias_method :internet_explorer, :ie
42
+ alias internet_explorer ie
65
43
 
66
44
  def edge(**opts)
67
45
  Edge::Service.new(**opts)
68
46
  end
47
+ alias microsoftedge edge
48
+ alias msedge edge
69
49
 
70
50
  def safari(**opts)
71
51
  Safari::Service.new(**opts)
@@ -77,8 +57,8 @@ module Selenium
77
57
  end
78
58
  end
79
59
 
80
- attr_accessor :host
81
- attr_reader :executable_path
60
+ attr_accessor :host, :executable_path, :port, :log, :args
61
+ alias extra_args args
82
62
 
83
63
  #
84
64
  # End users should use a class method for the desired driver, rather than using this directly.
@@ -86,134 +66,37 @@ module Selenium
86
66
  # @api private
87
67
  #
88
68
 
89
- def initialize(path: nil, port: nil, args: nil)
90
- path ||= self.class.driver_path
91
- port ||= self.class.default_port
69
+ def initialize(path: nil, port: nil, log: nil, args: nil)
70
+ port ||= self.class::DEFAULT_PORT
92
71
  args ||= []
93
72
 
94
- @executable_path = binary_path(path)
73
+ @executable_path = path
95
74
  @host = Platform.localhost
96
75
  @port = Integer(port)
97
-
98
- @extra_args = args.is_a?(Hash) ? extract_service_args(args) : args
76
+ @log = case log
77
+ when :stdout
78
+ $stdout
79
+ when :stderr
80
+ $stderr
81
+ else
82
+ log
83
+ end
84
+ @args = args
99
85
 
100
86
  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
101
87
  end
102
88
 
103
- def start
104
- raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running?
105
-
106
- Platform.exit_hook(&method(:stop)) # make sure we don't leave the server running
107
-
108
- socket_lock.locked do
109
- find_free_port
110
- start_process
111
- connect_until_stable
112
- end
113
- end
114
-
115
- def stop
116
- return unless self.class.shutdown_supported
117
-
118
- stop_server
119
- @process.poll_for_exit STOP_TIMEOUT
120
- rescue ChildProcess::TimeoutError
121
- nil # noop
122
- ensure
123
- stop_process
124
- end
125
-
126
- def uri
127
- @uri ||= URI.parse("http://#{@host}:#{@port}")
128
- end
129
-
130
- private
131
-
132
- def binary_path(path = nil)
133
- path = path.call if path.is_a?(Proc)
134
- path ||= Platform.find_binary(self.class.executable)
135
-
136
- raise Error::WebDriverError, self.class.missing_text unless path
137
-
138
- Platform.assert_executable path
139
- path
140
- end
141
-
142
- def build_process(*command)
143
- WebDriver.logger.debug("Executing Process #{command}")
144
- @process = ChildProcess.build(*command)
145
- if WebDriver.logger.debug?
146
- @process.io.stdout = @process.io.stderr = WebDriver.logger.io
147
- elsif Platform.jruby?
148
- # Apparently we need to read the output of drivers on JRuby.
149
- @process.io.stdout = @process.io.stderr = File.new(Platform.null_device, 'w')
150
- end
151
-
152
- @process
153
- end
154
-
155
- def connect_to_server
156
- Net::HTTP.start(@host, @port) do |http|
157
- http.open_timeout = STOP_TIMEOUT / 2
158
- http.read_timeout = STOP_TIMEOUT / 2
159
-
160
- yield http
89
+ def launch
90
+ @executable_path ||= begin
91
+ default_options = WebDriver.const_get("#{self.class.name.split('::')[2]}::Options").new
92
+ DriverFinder.path(default_options, self.class)
161
93
  end
94
+ ServiceManager.new(self).tap(&:start)
162
95
  end
163
96
 
164
- def find_free_port
165
- @port = PortProber.above(@port)
97
+ def shutdown_supported
98
+ self.class::SHUTDOWN_SUPPORTED
166
99
  end
167
-
168
- def start_process
169
- @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
170
- # Note: this is a bug only in Windows 7
171
- @process.leader = true unless Platform.windows?
172
- @process.start
173
- end
174
-
175
- def stop_process
176
- return if process_exited?
177
-
178
- @process.stop STOP_TIMEOUT
179
- @process.io.stdout.close if Platform.jruby? && !WebDriver.logger.debug?
180
- end
181
-
182
- def stop_server
183
- return if process_exited?
184
-
185
- connect_to_server { |http| http.get('/shutdown') }
186
- end
187
-
188
- def process_running?
189
- defined?(@process) && @process&.alive?
190
- end
191
-
192
- def process_exited?
193
- @process.nil? || @process.exited?
194
- end
195
-
196
- def connect_until_stable
197
- socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
198
- return if socket_poller.connected?
199
-
200
- raise Error::WebDriverError, cannot_connect_error_text
201
- end
202
-
203
- def cannot_connect_error_text
204
- "unable to connect to #{self.class.executable} #{@host}:#{@port}"
205
- end
206
-
207
- def socket_lock
208
- @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
209
- end
210
-
211
- protected
212
-
213
- def extract_service_args(driver_opts)
214
- driver_opts.key?(:args) ? driver_opts.delete(:args) : []
215
- end
216
-
217
100
  end # Service
218
101
  end # WebDriver
219
102
  end # Selenium
@@ -0,0 +1,144 @@
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
+ module Selenium
21
+ module WebDriver
22
+ #
23
+ # Base class implementing default behavior of service_manager object,
24
+ # responsible for starting and stopping driver implementations.
25
+ #
26
+ # @api private
27
+ #
28
+ class ServiceManager
29
+ START_TIMEOUT = 20
30
+ SOCKET_LOCK_TIMEOUT = 45
31
+ STOP_TIMEOUT = 20
32
+
33
+ #
34
+ # End users should use a class method for the desired driver, rather than using this directly.
35
+ #
36
+ # @api private
37
+ #
38
+
39
+ def initialize(config)
40
+ @executable_path = config.executable_path
41
+ @host = Platform.localhost
42
+ @port = config.port
43
+ @io = config.log
44
+ @extra_args = config.args
45
+ @shutdown_supported = config.shutdown_supported
46
+
47
+ raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
48
+ end
49
+
50
+ def start
51
+ raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running?
52
+
53
+ Platform.exit_hook { stop } # make sure we don't leave the server running
54
+
55
+ socket_lock.locked do
56
+ find_free_port
57
+ start_process
58
+ connect_until_stable
59
+ end
60
+ end
61
+
62
+ def stop
63
+ return unless @shutdown_supported
64
+ return if process_exited?
65
+
66
+ stop_server
67
+ @process.poll_for_exit STOP_TIMEOUT
68
+ rescue ChildProcess::TimeoutError, Errno::ECONNREFUSED
69
+ nil # noop
70
+ ensure
71
+ stop_process
72
+ end
73
+
74
+ def uri
75
+ @uri ||= URI.parse("http://#{@host}:#{@port}")
76
+ end
77
+
78
+ private
79
+
80
+ def build_process(*command)
81
+ WebDriver.logger.debug("Executing Process #{command}", id: :driver_service)
82
+ @process = ChildProcess.build(*command)
83
+ @io ||= WebDriver.logger.io if WebDriver.logger.debug?
84
+ @process.io = @io if @io
85
+
86
+ @process
87
+ end
88
+
89
+ def connect_to_server
90
+ Net::HTTP.start(@host, @port) do |http|
91
+ http.open_timeout = STOP_TIMEOUT / 2
92
+ http.read_timeout = STOP_TIMEOUT / 2
93
+
94
+ yield http
95
+ end
96
+ end
97
+
98
+ def find_free_port
99
+ @port = PortProber.above(@port)
100
+ end
101
+
102
+ def start_process
103
+ @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
104
+ @process.start
105
+ end
106
+
107
+ def stop_process
108
+ return if process_exited?
109
+
110
+ @process.stop STOP_TIMEOUT
111
+ end
112
+
113
+ def stop_server
114
+ connect_to_server do |http|
115
+ headers = WebDriver::Remote::Http::Common::DEFAULT_HEADERS.dup
116
+ http.get('/shutdown', headers)
117
+ end
118
+ end
119
+
120
+ def process_running?
121
+ defined?(@process) && @process&.alive?
122
+ end
123
+
124
+ def process_exited?
125
+ @process.nil? || @process.exited?
126
+ end
127
+
128
+ def connect_until_stable
129
+ socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
130
+ return if socket_poller.connected?
131
+
132
+ raise Error::WebDriverError, cannot_connect_error_text
133
+ end
134
+
135
+ def cannot_connect_error_text
136
+ "unable to connect to #{@executable_path} #{@host}:#{@port}"
137
+ end
138
+
139
+ def socket_lock
140
+ @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
141
+ end
142
+ end # Service
143
+ end # WebDriver
144
+ end # Selenium
@@ -0,0 +1,86 @@
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
+ module Selenium
21
+ module WebDriver
22
+ class ShadowRoot
23
+ ROOT_KEY = 'shadow-6066-11e4-a52e-4f735466cecf'
24
+
25
+ include SearchContext
26
+
27
+ #
28
+ # Creates a new shadow root
29
+ #
30
+ # @api private
31
+ #
32
+
33
+ def initialize(bridge, id)
34
+ @bridge = bridge
35
+ @id = id
36
+ end
37
+
38
+ def inspect
39
+ format '#<%<class>s:0x%<hash>x id=%<id>s>', class: self.class, hash: hash * 2, id: @id.inspect
40
+ end
41
+
42
+ def ==(other)
43
+ other.is_a?(self.class) && ref == other.ref
44
+ end
45
+ alias eql? ==
46
+
47
+ def hash
48
+ [@id, @bridge].hash
49
+ end
50
+
51
+ #
52
+ # @api private
53
+ # @see SearchContext
54
+ #
55
+
56
+ def ref
57
+ [:shadow_root, @id]
58
+ end
59
+
60
+ #
61
+ # Convert to a ShadowRoot JSON Object for transmission over the wire.
62
+ # @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#basic-terms-and-concepts
63
+ #
64
+ # @api private
65
+ #
66
+
67
+ def to_json(*)
68
+ JSON.generate as_json
69
+ end
70
+
71
+ #
72
+ # For Rails 3 - http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/
73
+ #
74
+ # @api private
75
+ #
76
+
77
+ def as_json(*)
78
+ {ROOT_KEY => @id}
79
+ end
80
+
81
+ private
82
+
83
+ attr_reader :bridge
84
+ end # ShadowRoot
85
+ end # WebDriver
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,11 +67,10 @@ 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
- rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => ex
73
- WebDriver.logger.debug("#{self}: #{ex.message}")
72
+ rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => e
73
+ WebDriver.logger.debug("#{self}: #{e.message}", id: :driver_service)
74
74
  false
75
75
  end
76
76
 
@@ -66,8 +66,8 @@ module Selenium
66
66
  }.freeze
67
67
 
68
68
  if Platform.jruby?
69
- # we use a plain TCPSocket here since JRuby has issues select()ing on a connecting socket
70
- # see http://jira.codehaus.org/browse/JRUBY-5165
69
+ # we use a plain TCPSocket here since JRuby has issues closing socket
70
+ # see https://github.com/jruby/jruby/issues/5709
71
71
  def listening?
72
72
  TCPSocket.new(@host, @port).close
73
73
  true
@@ -93,13 +93,13 @@ module Selenium
93
93
  true
94
94
  rescue *NOT_CONNECTED_ERRORS
95
95
  sock&.close
96
- WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
96
+ WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}", id: :driver_service)
97
97
  false
98
98
  end
99
99
  end
100
100
 
101
101
  def socket_writable?(sock)
102
- IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
102
+ sock.wait_writable(CONNECT_TIMEOUT)
103
103
  end
104
104
 
105
105
  def conn_completed?(sock)