Class: Selenium::WebDriver::Chrome::CommandExecutor
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Chrome::CommandExecutor
- Defined in:
- lib/selenium/webdriver/chrome/command_executor.rb
Constant Summary collapse
- HTML_TEMPLATE =
"HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s"
- JSON_TEMPLATE =
"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
- #close ⇒ Object
- #execute(command) ⇒ Object
-
#initialize ⇒ CommandExecutor
constructor
A new instance of CommandExecutor.
- #port ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize ⇒ CommandExecutor
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
#close ⇒ Object
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
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 |
#port ⇒ Object
44 45 46 |
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 44 def port @server.addr[1] end |
#uri ⇒ Object
48 49 50 |
# File 'lib/selenium/webdriver/chrome/command_executor.rb', line 48 def uri "http://localhost:#{port}/chromeCommandExecutor" end |