class Selenium::WebDriver::Firefox::Launcher

@api private

Constants

SOCKET_LOCK_TIMEOUT
STABLE_CONNECTION_TIMEOUT

Public Class Methods

new(binary, port, profile = nil) click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 28
def initialize(binary, port, profile = nil)
  @binary = binary
  @port   = Integer(port)

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

  if profile.is_a? Profile
    @profile = profile
  else
    @profile_name = profile
    @profile = nil
  end

  @host = '127.0.0.1'
end

Public Instance Methods

assert_profile() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 101
def assert_profile
  raise Error::WebDriverError, 'must create_profile first' unless @profile && @profile_dir
end
connect_until_stable() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 83
def connect_until_stable
  poller = SocketPoller.new(@host, @port, STABLE_CONNECTION_TIMEOUT)

  return if poller.connected?

  @binary.quit
  error = "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
  raise Error::WebDriverError, error
end
create_profile() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 68
def create_profile
  fetch_profile unless @profile

  @profile.add_webdriver_extension
  @profile.port = @port

  @profile_dir = @profile.layout_on_disk
  FileReaper << @profile_dir
end
fetch_profile() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 93
def fetch_profile
  @profile = if @profile_name
               Profile.from_name @profile_name
             else
               Profile.new
             end
end
find_free_port() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 64
def find_free_port
  @port = PortProber.above @port
end
launch() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 48
def launch
  socket_lock.locked do
    find_free_port
    create_profile
    start
    connect_until_stable
  end

  self
end
quit() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 59
def quit
  @binary.quit
  FileReaper.reap(@profile_dir) if @profile_dir
end
socket_lock() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 105
def socket_lock
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
end
start() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 78
def start
  assert_profile
  @binary.start_with @profile, @profile_dir, '-foreground'
end
url() click to toggle source
# File lib/selenium/webdriver/firefox/launcher.rb, line 44
def url
  "http://#{@host}:#{@port}/hub"
end