class Selenium::WebDriver::ServiceManager
Base class implementing default behavior of service_manager object, responsible for starting and stopping driver implementations.
@api private
Constants
- SOCKET_LOCK_TIMEOUT
- START_TIMEOUT
- STOP_TIMEOUT
Public Class Methods
new(config)
click to toggle source
End users should use a class method for the desired driver, rather than using this directly.
@api private
# File lib/selenium/webdriver/common/service_manager.rb, line 39 def initialize(config) @executable_path = config.executable_path @host = Platform.localhost @port = config.port @io = config.log @extra_args = config.args @shutdown_supported = config.shutdown_supported raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1 end
Public Instance Methods
start()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 50 def start raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running? Platform.exit_hook { stop } # make sure we don't leave the server running socket_lock.locked do find_free_port start_process connect_until_stable end end
stop()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 62 def stop return unless @shutdown_supported return if process_exited? stop_server @process.poll_for_exit STOP_TIMEOUT rescue ChildProcess::TimeoutError, Errno::ECONNREFUSED nil # noop ensure stop_process end
uri()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 74 def uri @uri ||= URI.parse("http://#{@host}:#{@port}") end
Private Instance Methods
build_process(*command)
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 80 def build_process(*command) WebDriver.logger.debug("Executing Process #{command}", id: :driver_service) @process = ChildProcess.build(*command) @io ||= WebDriver.logger.io if WebDriver.logger.debug? @process.io = @io if @io @process end
cannot_connect_error_text()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 136 def cannot_connect_error_text "unable to connect to #{@executable_path} #{@host}:#{@port}" end
connect_to_server() { |http| ... }
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 89 def connect_to_server Net::HTTP.start(@host, @port) do |http| http.open_timeout = STOP_TIMEOUT / 2 http.read_timeout = STOP_TIMEOUT / 2 yield http end end
connect_until_stable()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 129 def connect_until_stable socket_poller = SocketPoller.new @host, @port, START_TIMEOUT return if socket_poller.connected? raise Error::WebDriverError, cannot_connect_error_text end
find_free_port()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 98 def find_free_port @port = PortProber.above(@port) end
process_exited?()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 125 def process_exited? @process.nil? || @process.exited? end
process_running?()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 121 def process_running? defined?(@process) && @process&.alive? end
socket_lock()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 140 def socket_lock @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT) end
start_process()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 102 def start_process @process = build_process(@executable_path, "--port=#{@port}", *@extra_args) @process.start end
stop_process()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 107 def stop_process return if process_exited? @process.stop STOP_TIMEOUT end
stop_server()
click to toggle source
# File lib/selenium/webdriver/common/service_manager.rb, line 113 def stop_server connect_to_server do |http| headers = WebDriver::Remote::Http::Common::DEFAULT_HEADERS.dup WebDriver.logger.debug('Sending shutdown request to server', id: :driver_service) http.get('/shutdown', headers) end end