Class: Selenium::WebDriver::Edge::Service Private

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

17556
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 MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver."

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.



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

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.



50
51
52
# File 'lib/selenium/webdriver/edge/service.rb', line 50

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.



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

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



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

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.



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

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

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



91
92
93
# File 'lib/selenium/webdriver/edge/service.rb', line 91

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.



117
118
119
# File 'lib/selenium/webdriver/edge/service.rb', line 117

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.



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

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.



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

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.



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

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.



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

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.



87
88
89
# File 'lib/selenium/webdriver/edge/service.rb', line 87

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