Class: Selenium::WebDriver::Chrome::Service Private

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/chrome/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.

9515
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 the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver."

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/chrome/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/chrome/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/chrome/service.rb', line 34

def self.executable_path
  @executable_path ||= (
    path = Platform.find_binary "chromedriver"
    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/chrome/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.



105
106
107
108
109
110
111
# File 'lib/selenium/webdriver/chrome/service.rb', line 105

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

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



93
94
95
# File 'lib/selenium/webdriver/chrome/service.rb', line 93

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.



113
114
115
# File 'lib/selenium/webdriver/chrome/service.rb', line 113

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/chrome/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.



97
98
99
100
101
102
103
# File 'lib/selenium/webdriver/chrome/service.rb', line 97

def start_process
  server_command = [@executable_path, "--port=#{@port}", *@extra_args]
  @process       = ChildProcess.build(*server_command)

  @process.io.inherit! if $DEBUG == true
  @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
85
86
87
# File 'lib/selenium/webdriver/chrome/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

  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
  # ok, force quit
  @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.



89
90
91
# File 'lib/selenium/webdriver/chrome/service.rb', line 89

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