Class: Selenium::WebDriver::Chrome::CommandExecutor Private

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

HTML_TEMPLATE =

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.

"HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s"
JSON_TEMPLATE =

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.

"HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n%s"

Instance Method Summary collapse

Constructor Details

#initializeCommandExecutor

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



10
11
12
13
14
15
16
17
18
19
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 10

def initialize
  @server       = TCPServer.new(localhost, 0)
  @queue        = Queue.new

  @accepted_any = false
  @next_socket  = nil
  @listening    = true

  Thread.new { start_run_loop }
end

Instance Method Details

#closeObject

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.



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

def close
  stop_listening
  close_sockets
  @server.close unless @server.closed?
rescue IOError
  nil
end

#execute(command) ⇒ 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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 21

def execute(command)
  until accepted_any?
    Thread.pass
    sleep 0.01
  end

  json = command.to_json
  data = JSON_TEMPLATE % [json.length, json]

  @next_socket.write data
  @next_socket.close

  JSON.parse read_response(@queue.pop)
end

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



44
45
46
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 44

def port
  @server.addr[1]
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.



48
49
50
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 48

def uri
  "http://#{Platform.localhost}:#{port}/chromeCommandExecutor"
end