Class: Selenium::WebDriver::Firefox::Service Private

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

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.

Constant Summary collapse

START_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.

20
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.

45
STOP_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.

5
DEFAULT_PORT =

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.

4444
MISSING_TEXT =

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.

"Unable to find geckodriver. Please download the executable from https://github.com/mozilla/geckodriver/releases"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executable_path, port, *extra_args) ⇒ Service

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 Service.



53
54
55
56
57
58
59
60
61
# File 'lib/selenium/webdriver/firefox/service.rb', line 53

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

Class Method Details

.default_service(*extra_args) ⇒ Object

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.



49
50
51
# File 'lib/selenium/webdriver/firefox/service.rb', line 49

def self.default_service(*extra_args)
  new executable_path, DEFAULT_PORT, *extra_args
end

.executable_pathObject

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.



34
35
36
37
38
39
40
41
42
# File 'lib/selenium/webdriver/firefox/service.rb', line 34

def self.executable_path
  @executable_path ||= (
    path = Platform.find_binary("geckodriver*") || Platform.find_binary("wires*")
    path or raise Error::WebDriverError, MISSING_TEXT
    Platform.assert_executable path

    path
  )
end

.executable_path=(path) ⇒ Object

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.



44
45
46
47
# File 'lib/selenium/webdriver/firefox/service.rb', line 44

def self.executable_path=(path)
  Platform.assert_executable path
  @executable_path = path
end

Instance Method Details

#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.



108
109
110
111
112
113
114
# File 'lib/selenium/webdriver/firefox/service.rb', line 108

def connect_until_stable
  @socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

  unless @socket_poller.connected?
    raise Error::WebDriverError, "unable to connect to Mozilla geckodriver #{@host}:#{@port}"
  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.



90
91
92
# File 'lib/selenium/webdriver/firefox/service.rb', line 90

def find_free_port
  @port = PortProber.above @port
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.



116
117
118
# File 'lib/selenium/webdriver/firefox/service.rb', line 116

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.



63
64
65
66
67
68
69
70
71
# File 'lib/selenium/webdriver/firefox/service.rb', line 63

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_processObject

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.



94
95
96
97
98
99
100
# File 'lib/selenium/webdriver/firefox/service.rb', line 94

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

#stopObject

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.



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/selenium/webdriver/firefox/service.rb', line 73

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
ensure
  stop_process
end

#stop_processObject

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.



102
103
104
105
106
# File 'lib/selenium/webdriver/firefox/service.rb', line 102

def stop_process
  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
  @process.stop STOP_TIMEOUT
end

#uriObject

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.



86
87
88
# File 'lib/selenium/webdriver/firefox/service.rb', line 86

def uri
  URI.parse "http://#{@host}:#{@port}"
end