### Home Classes Methods

### In Files

- firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb

### Parent

Object

### Methods

- ::new
- #assert_profile
- #can_connect?
- #connect_until_stable
- #create_profile
- #fetch_profile
- #find_free_port
- #free_port?
- #launch
- #start
- #start_silent_and_wait
- #url
- #with_lock

### Class/Module Index

Quicksearch

- Selenium
- Selenium::WebDriver
- Selenium::WebDriver::BridgeHelper
- Selenium::WebDriver::ChildProcess
- Selenium::WebDriver::ChildProcess::IronRubyProcess
- Selenium::WebDriver::ChildProcess::JRubyProcess
- Selenium::WebDriver::ChildProcess::WindowsProcess
- Selenium::WebDriver::Chrome
- Selenium::WebDriver::Chrome::Bridge
- Selenium::WebDriver::Chrome::CommandExecutor
- Selenium::WebDriver::Chrome::Launcher
- Selenium::WebDriver::Chrome::Launcher::MacOSXLauncher
- Selenium::WebDriver::Chrome::Launcher::UnixLauncher
- Selenium::WebDriver::Chrome::Launcher::WindowsLauncher
- Selenium::WebDriver::Driver
- Selenium::WebDriver::DriverExtensions
- Selenium::WebDriver::DriverExtensions::TakesScreenshot
- Selenium::WebDriver::Element
- Selenium::WebDriver::Error
- Selenium::WebDriver::Error::ElementNotDisplayedError
- Selenium::WebDriver::Error::ElementNotEnabledError
- Selenium::WebDriver::Error::ElementNotSelectableError
- Selenium::WebDriver::Error::ExpectedError
- Selenium::WebDriver::Error::IndexOutOfBoundsError
- Selenium::WebDriver::Error::InvalidCookieDomainError
- Selenium::WebDriver::Error::NoCollectionError
- Selenium::WebDriver::Error::NoScriptResultError
- Selenium::WebDriver::Error::NoStringError
- Selenium::WebDriver::Error::NoStringLengthError
- Selenium::WebDriver::Error::NoStringWrapperError
- Selenium::WebDriver::Error::NoSuchCollectionError
- Selenium::WebDriver::Error::NoSuchDocumentError
- Selenium::WebDriver::Error::NoSuchDriverError
- Selenium::WebDriver::Error::NoSuchElementError
- Selenium::WebDriver::Error::NoSuchFrameError
- Selenium::WebDriver::Error::NoSuchWindowError
- Selenium::WebDriver::Error::NullPointerError
- Selenium::WebDriver::Error::ObsoleteElementError
- Selenium::WebDriver::Error::ServerError
- Selenium::WebDriver::Error::TimeOutError
- Selenium::WebDriver::Error::UnableToSetCookieError
- Selenium::WebDriver::Error::UnexpectedJavascriptError
- Selenium::WebDriver::Error::UnhandledError
- Selenium::WebDriver::Error::UnknownCommandError
- Selenium::WebDriver::Error::UnknownScriptResultError
- Selenium::WebDriver::Error::UnsupportedOperationError
- Selenium::WebDriver::Error::WebDriverError
- Selenium::WebDriver::FileReaper
- Selenium::WebDriver::Find
- Selenium::WebDriver::Firefox
- Selenium::WebDriver::Firefox::Binary
- Selenium::WebDriver::Firefox::Bridge
- Selenium::WebDriver::Firefox::Launcher
- Selenium::WebDriver::Firefox::Profile
- Selenium::WebDriver::Firefox::ProfilesIni
- Selenium::WebDriver::Firefox::Util
- Selenium::WebDriver::IE
- Selenium::WebDriver::IE::Bridge
- Selenium::WebDriver::IE::Kernel32
- Selenium::WebDriver::IE::Lib
- Selenium::WebDriver::IE::Util
- Selenium::WebDriver::Keys
- Selenium::WebDriver::Navigation
- Selenium::WebDriver::Options
- Selenium::WebDriver::Platform
- Selenium::WebDriver::Remote
- Selenium::WebDriver::Remote::Bridge
- Selenium::WebDriver::Remote::Capabilities
- Selenium::WebDriver::Remote::Http
- Selenium::WebDriver::Remote::Http::Common
- Selenium::WebDriver::Remote::Http::Curb
- Selenium::WebDriver::Remote::Http::Default
- Selenium::WebDriver::Remote::Response
- Selenium::WebDriver::TargetLocator
- Selenium::WebDriver::Timeouts
- Dir
- SocketError
- String

No matching classes.

# Selenium::WebDriver::Firefox::Launcher

@private

### Constants

SOCKET_LOCK_TIMEOUT
STABLE_CONNECTION_TIMEOUT

### Public Class Methods

new(binary, port = DEFAULT_PORT, profile = DEFAULT_PROFILE_NAME) click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 13
    def initialize(binary, port = DEFAULT_PORT, profile = DEFAULT_PROFILE_NAME)
      @binary       = binary
      @port         = port.to_i

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

      # need to be really specific about what host to use
      #
      # on os x, "localhost" will resolve to 3 different addresses (see /etc/hosts)
      # Ruby will loop over these and happily bind to the same port on each one,
      # making it completely unusable for our purposes.
      #
      @host = "127.0.0.1"
    end

### Public Instance Methods

assert_profile() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 146
    def assert_profile
      raise "must create_profile first" if @profile.nil?
    end

can_connect?() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 117
    def can_connect?
      TCPSocket.new(@host, @port).close
      true
    rescue Errno::ECONNREFUSED, Errno::ENOTCONN, SocketError => e
      $stderr.puts "#{e.message} for #{@host}:#{@port}" if $DEBUG
      false
    end

connect_until_stable() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 106
    def connect_until_stable
      max_time = Time.now + STABLE_CONNECTION_TIMEOUT

      until Time.now >= max_time
        return if can_connect?
        sleep 0.25
      end

      raise Error::WebDriverError, "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds"
    end

create_profile() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 81
    def create_profile
      unless @profile
        fetch_profile
        if @profile.nil?
          raise Error, WebDriverError, "could not find or create profile: #{profile.inspect}"
        end
      end

      @profile.delete_extensions_cache
      @profile.port = @port
      @profile.add_webdriver_extension(true)
      @profile.update_user_prefs
    end

fetch_profile() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 133
    def fetch_profile
      existing = Profile.from_name @profile_name

      unless existing
        @binary.create_base_profile @profile_name
        Profile.ini.refresh
        existing = Profile.from_name @profile_name
        raise "unable to find or create new profile" unless existing
      end

      @profile = existing
    end

find_free_port() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 71
    def find_free_port
      port = @port

      until free_port?(port)
        port += 1
      end

      @port = port
    end

free_port?(port) click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 125
    def free_port?(port)
      s = TCPServer.new(@host, port)
      s.close
      true
    rescue SocketError, Errno::EADDRINUSE
      false
    end

launch() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 37
    def launch
      with_lock do
        find_free_port
        create_profile
        start_silent_and_wait
        start
        connect_until_stable
      end

      self
    end

start() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 95
    def start
      assert_profile
      @binary.start_with @profile
    end

start_silent_and_wait() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 100
    def start_silent_and_wait
      assert_profile
      @binary.start_with @profile, "--silent"
      @binary.wait
    end

url() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 33
    def url
      "http://#{@host}:#{@port}/hub"
    end

with_lock() click to toggle source

    # File firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb, line 49
    def with_lock
      max_time = Time.now + SOCKET_LOCK_TIMEOUT
      locking_port = @port - 1

      until Time.now > max_time
        begin
          socket_lock = TCPServer.new(@host, locking_port)
          # make sure the fd is not inherited by firefox
          socket_lock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC

          yield
          return
        rescue SocketError, Errno::EADDRINUSE
          sleep 0.1
        end
      end

      raise Error::WebDriverError, "unable to bind to locking port #{locking_port} within #{SOCKET_LOCK_TIMEOUT} seconds"
    ensure
      socket_lock.close if socket_lock
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.