class Selenium::WebDriver::BiDi::BrowsingContext

Constants

READINESS_STATE

Attributes

id[RW]

Public Class Methods

new(driver:, browsing_context_id: nil, type: nil, reference_context: nil) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 35
def initialize(driver:, browsing_context_id: nil, type: nil, reference_context: nil)
  unless driver.capabilities.web_socket_url
    raise Error::WebDriverError,
          'WebDriver instance must support BiDi protocol'
  end

  unless type.nil? || %i[window tab].include?(type)
    raise ArgumentError,
          "Valid types are :window & :tab. Received: #{type.inspect}"
  end

  @bidi = driver.bidi
  @id = browsing_context_id.nil? ? create(type, reference_context)['context'] : browsing_context_id
end

Public Instance Methods

close() click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 76
def close
  @bidi.send_cmd('browsingContext.close', context: @id)
end
get_tree(max_depth: nil) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 65
def get_tree(max_depth: nil)
  result = @bidi.send_cmd('browsingContext.getTree', root: @id, maxDepth: max_depth).dig('contexts', 0)

  BrowsingContextInfo.new(
    id: result['context'],
    url: result['url'],
    children: result['children'],
    parent_context: result['parent']
  )
end
navigate(url:, readiness_state: nil) click to toggle source

Private Instance Methods

create(type, reference_context) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 82
def create(type, reference_context)
  @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: reference_context)
end