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
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
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://code.google.com/p/chromium/downloads/list and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver."

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executable_path, port) ⇒ 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.



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

def initialize(executable_path, port)
  @uri           = URI.parse "http://#{Platform.localhost}:#{port}"
  server_command = [executable_path, "--port=#{port}"]

  @process       = ChildProcess.build(*server_command)
  @socket_poller = SocketPoller.new Platform.localhost, port, START_TIMEOUT

  @process.io.inherit! if $DEBUG == true
end

Instance Attribute Details

#uriObject (readonly)

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.



14
15
16
# File 'lib/selenium/webdriver/chrome/service.rb', line 14

def uri
  @uri
end

Class Method Details

.default_serviceObject

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.



31
32
33
# File 'lib/selenium/webdriver/chrome/service.rb', line 31

def self.default_service
  new executable_path, PortProber.random
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.



16
17
18
19
20
21
22
23
24
# File 'lib/selenium/webdriver/chrome/service.rb', line 16

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.



26
27
28
29
# File 'lib/selenium/webdriver/chrome/service.rb', line 26

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

Instance Method Details

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



45
46
47
48
49
50
51
52
53
# File 'lib/selenium/webdriver/chrome/service.rb', line 45

def start
  @process.start

  unless @socket_poller.connected?
    raise Error::WebDriverError, "unable to connect to chromedriver #{@uri}"
  end

  Platform.exit_hook { stop } # make sure we don't leave the server running
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.



55
56
57
58
59
60
61
62
63
# File 'lib/selenium/webdriver/chrome/service.rb', line 55

def stop
  return if @process.nil? || @process.exited?

  Net::HTTP.get uri.host, '/shutdown', uri.port
  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
  # ok, force quit
  @process.stop STOP_TIMEOUT
end