class Selenium::WebDriver::Firefox::Service

@api private

Constants

DEFAULT_PORT
MISSING_TEXT
SOCKET_LOCK_TIMEOUT
START_TIMEOUT
STOP_TIMEOUT

Public Class Methods

default_service(*extra_args) click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 48
def self.default_service(*extra_args)
  new executable_path, DEFAULT_PORT, *extra_args
end
executable_path() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 33
def self.executable_path
  @executable_path ||= (
    path = Platform.find_binary "wires"
    path or raise Error::WebDriverError, MISSING_TEXT
    Platform.assert_executable path

    path
  )
end
executable_path=(path) click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 43
def self.executable_path=(path)
  Platform.assert_executable path
  @executable_path = path
end
new(executable_path, port, *extra_args) click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 52
def initialize(executable_path, port, *extra_args)
  @executable_path = executable_path
  @host            = Platform.localhost
  @port            = Integer(port)

  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1

  @extra_args = extra_args
end

Public Instance Methods

connect_until_stable() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 104
def connect_until_stable
  @socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

  unless @socket_poller.connected?
    raise Error::WebDriverError, "unable to connect to Mozilla Wires #{@host}:#{@port}"
  end
end
find_free_port() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 92
def find_free_port
  @port = PortProber.above @port
end
socket_lock() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 112
def socket_lock
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
end
start() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 62
def start
  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() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 96
def start_process
  server_command = [@executable_path, "--binary=#{Firefox::Binary.path}", "--webdriver-port=#{@port}", *@extra_args]
  @process       = ChildProcess.build(*server_command)

  @process.io.inherit! if $DEBUG || Platform.os == :windows
  @process.start
end
stop() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 72
def stop
  return if @process.nil? || @process.exited?

  Net::HTTP.start(@host, @port) do |http|
    http.open_timeout = STOP_TIMEOUT / 2
    http.read_timeout = STOP_TIMEOUT / 2

    http.head("/shutdown")
  end

  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
  # ok, force quit
  @process.stop STOP_TIMEOUT
end
uri() click to toggle source
# File lib/selenium/webdriver/firefox/service.rb, line 88
def uri
  URI.parse "http://#{@host}:#{@port}"
end