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



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

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.



43
44
45
# File 'lib/selenium/webdriver/common/service.rb', line 43

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.



43
44
45
# File 'lib/selenium/webdriver/common/service.rb', line 43

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.



46
47
48
# File 'lib/selenium/webdriver/common/service.rb', line 46

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.



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

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.



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

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.



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

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.



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

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