Class: Selenium::WebDriver::WebSocketConnection
- Inherits:
-
Object
- Object
- Selenium::WebDriver::WebSocketConnection
- Defined in:
- lib/selenium/webdriver/common/websocket_connection.rb
Constant Summary collapse
- RESPONSE_WAIT_TIMEOUT =
30
- RESPONSE_WAIT_INTERVAL =
0.1
Instance Method Summary collapse
- #callbacks ⇒ Object
- #close ⇒ Object
-
#initialize(url:) ⇒ WebSocketConnection
constructor
A new instance of WebSocketConnection.
- #send_cmd(**payload) ⇒ Object
Constructor Details
#initialize(url:) ⇒ WebSocketConnection
Returns a new instance of WebSocketConnection.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/selenium/webdriver/common/websocket_connection.rb', line 28 def initialize(url:) @callback_threads = ThreadGroup.new @messages = [] @session_id = nil @url = url process_handshake @socket_thread = attach_socket_listener end |
Instance Method Details
#callbacks ⇒ Object
45 46 47 |
# File 'lib/selenium/webdriver/common/websocket_connection.rb', line 45 def callbacks @callbacks ||= Hash.new { |callbacks, event| callbacks[event] = [] } end |
#close ⇒ Object
39 40 41 42 43 |
# File 'lib/selenium/webdriver/common/websocket_connection.rb', line 39 def close @callback_threads.list.each(&:exit) @socket_thread.exit socket.close end |
#send_cmd(**payload) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/selenium/webdriver/common/websocket_connection.rb', line 49 def send_cmd(**payload) id = next_id data = payload.merge(id: id) data = JSON.generate(data) WebDriver.logger.debug "WebSocket -> #{data}" out_frame = WebSocket::Frame::Outgoing::Client.new(version: ws.version, data: data, type: 'text') socket.write(out_frame.to_s) wait.until { @messages.find { |m| m['id'] == id } } end |