class Selenium::WebDriver::Chrome::Service

@api private

Constants

MISSING_TEXT
START_TIMEOUT
STOP_TIMEOUT

Attributes

uri[R]

Public Class Methods

default_service() click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 27
def self.default_service
  new executable_path, PortProber.random
end
executable_path() click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 16
def self.executable_path
  @executable_path ||= (
    Platform.find_binary "chromedriver" or raise Error::WebDriverError, MISSING_TEXT
  )
end
executable_path=(path) click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 22
def self.executable_path=(path)
  Platform.assert_executable path
  @executable_path = path
end
new(executable_path, port) click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 31
def initialize(executable_path, port)
  @uri           = URI.parse "http://#{Platform.localhost}:#{port}"
  server_command = [executable_path, "--port=#{port}"]

  @process       = ChildProcess.build(*server_command)
  @socket_poller = SocketPoller.new Platform.localhost, port, START_TIMEOUT

  @process.io.inherit! if $DEBUG == true
end

Public Instance Methods

start() click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 41
def start
  @process.start

  unless @socket_poller.connected?
    raise Error::WebDriverError, "unable to connect to chromedriver #{@uri}"
  end

  Platform.exit_hook { stop } # make sure we don't leave the server running
end
stop() click to toggle source
# File lib/selenium/webdriver/chrome/service.rb, line 51
def stop
  return if @process.nil? || @process.exited?

  Net::HTTP.get uri.host, '/shutdown', uri.port
  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
  # ok, force quit
  @process.stop STOP_TIMEOUT
end