Class: Selenium::WebDriver::ServiceManager Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/service_manager.rb |
Overview
Base class implementing default behavior of service_manager object, responsible for starting and stopping driver implementations.
Constant Summary
-
SOCKET_LOCK_TIMEOUT =
# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 3045
-
START_TIMEOUT =
# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 2920
-
STOP_TIMEOUT =
# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 3120
Class Method Summary
-
.new(config) ⇒ ServiceManager
constructor
Internal use only
End users should use a class method for the desired driver, rather than using this directly.
Instance Attribute Summary
- #process_exited? ⇒ Boolean readonly private Internal use only
- #process_running? ⇒ Boolean readonly private Internal use only
Instance Method Summary
- #start Internal use only
- #stop Internal use only
- #uri Internal use only
- #build_process(*command) private Internal use only
- #cannot_connect_error_text private Internal use only
- #connect_to_server private Internal use only
- #connect_until_stable private Internal use only
- #find_free_port private Internal use only
- #socket_lock private Internal use only
- #start_process private Internal use only
- #stop_process private Internal use only
- #stop_server private Internal use only
Constructor Details
.new(config) ⇒ ServiceManager
End users should use a class method for the desired driver, rather than using this directly.
# File 'rb/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
Instance Attribute Details
#process_exited? ⇒ Boolean
(readonly, private)
# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 125
def process_exited? @process.nil? || @process.exited? end
#process_running? ⇒ Boolean
(readonly, private)
# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 121
def process_running? defined?(@process) && @process&.alive? end
Instance Method Details
#build_process(*command) (private)
[ GitHub ]# File 'rb/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 (private)
[ GitHub ]# File 'rb/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 (private)
[ GitHub ]# File 'rb/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 (private)
# File 'rb/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 (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 98
def find_free_port @port = PortProber.above(@port) end
#socket_lock (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 140
def socket_lock @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT) end
#start
[ GitHub ]# File 'rb/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
#start_process (private)
[ GitHub ]# File 'rb/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
[ GitHub ]# File 'rb/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
#stop_process (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 107
def stop_process return if process_exited? @process.stop STOP_TIMEOUT end
#stop_server (private)
[ GitHub ]# File 'rb/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
#uri
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/service_manager.rb', line 74
def uri @uri ||= URI.parse("http://#{@host}:#{@port}") end