Class: Selenium::WebDriver::Service Private

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

Base class implementing default behavior of service object, responsible for starting and stopping driver implementations.

Subclasses must implement the following private methods:

* #start_process
* #stop_server
* #cannot_connect_error_text

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.

20

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

def initialize(executable_path, port, driver_opts)
  @executable_path = binary_path(executable_path)
  @host            = Platform.localhost
  @port            = Integer(port)
  @extra_args      = extract_service_args(driver_opts)

  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
end

Class Attribute Details

.executableObject (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.



41
42
43
# File 'lib/selenium/webdriver/common/service.rb', line 41

def executable
  @executable
end

.missing_textObject (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.



41
42
43
# File 'lib/selenium/webdriver/common/service.rb', line 41

def missing_text
  @missing_text
end

Instance Attribute Details

#hostObject

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
# File 'lib/selenium/webdriver/common/service.rb', line 44

def host
  @host
end

Instance Method Details

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



55
56
57
58
59
60
# File 'lib/selenium/webdriver/common/service.rb', line 55

def binary_path(path)
  path = Platform.find_binary(self.class.executable) if path.nil?
  raise Error::WebDriverError, self.class.missing_text unless path
  Platform.assert_executable path
  path
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.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/selenium/webdriver/common/service.rb', line 62

def start
  if process_running?
    raise "already started: #{uri.inspect} #{@executable_path.inspect}"
  end

  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

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



76
77
78
79
80
81
82
# File 'lib/selenium/webdriver/common/service.rb', line 76

def stop
  stop_server
  @process.poll_for_exit STOP_TIMEOUT
rescue ChildProcess::TimeoutError
ensure
  stop_process
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.



84
85
86
# File 'lib/selenium/webdriver/common/service.rb', line 84

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