123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::BiDi::Transport Private

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/bidi/transport.rb

Overview

The seam between the generated Protocol layer and the websocket: serializes a command's params, sends it, and parses the reply into its declared type.

Class Method Summary

Instance Attribute Summary

  • #connection readonly Internal use only

    The websocket the transport sends over.

Instance Method Summary

Constructor Details

.new(connection) ⇒ Transport

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/transport.rb', line 33

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connection (readonly)

The websocket the transport sends over. Exposed so a domain can build a sibling domain (e.g. a vendor variant) over the same connection without Transport ever becoming a public constructor argument.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/transport.rb', line 31

attr_reader :connection

Instance Method Details

#error_for(reply) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/transport.rb', line 51

def error_for(reply)
  Protocol::ErrorCode.for(reply['error']).new("#{reply['message']}\n#{reply['stacktrace']}")
end

#execute(cmd:, params: nil, result: nil)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/transport.rb', line 37

def execute(cmd:, params: nil, result: nil)
  reply = @connection.send_cmd(method: cmd, params: serialize(params))
  raise error_for(reply) if reply['error']

  value = reply['result']
  result ? result.from_json(value) : value
end

#serialize(params) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/transport.rb', line 47

def serialize(params)
  params&.as_json || {}
end