Class: Selenium::WebDriver::Firefox::Launcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/firefox/launcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Constant Summary collapse

SOCKET_LOCK_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

45
STABLE_CONNECTION_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

60

Instance Method Summary collapse

Constructor Details

#initialize(binary, port, profile = nil) ⇒ Launcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Launcher.

Raises:

API:

  • private



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 26

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

Instance Method Details

#assert_profileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

API:

  • private



98
99
100
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 98

def assert_profile
  raise Error::WebDriverError, 'must create_profile first' unless @profile && @profile_dir
end

#connect_until_stableObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

API:

  • private



81
82
83
84
85
86
87
88
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 81

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_profileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



66
67
68
69
70
71
72
73
74
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 66

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_profileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



90
91
92
93
94
95
96
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 90

def fetch_profile
  @profile = if @profile_name
               Profile.from_name @profile_name
             else
               Profile.new
             end
end

#find_free_portObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



62
63
64
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 62

def find_free_port
  @port = PortProber.above @port
end

#launchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



46
47
48
49
50
51
52
53
54
55
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 46

def launch
  socket_lock.locked do
    find_free_port
    create_profile
    start
    connect_until_stable
  end

  self
end

#quitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



57
58
59
60
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 57

def quit
  @binary.quit
  FileReaper.reap(@profile_dir) if @profile_dir
end

#socket_lockObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



102
103
104
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 102

def socket_lock
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



76
77
78
79
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 76

def start
  assert_profile
  @binary.start_with @profile, @profile_dir, '-foreground'
end

#urlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



42
43
44
# File 'lib/selenium/webdriver/firefox/launcher.rb', line 42

def url
  "http://#{@host}:#{@port}/hub"
end