123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::BiDi::BrowsingContext

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

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(driver:, browsing_context_id: nil, type: nil, reference_context: nil) ⇒ BrowsingContext

[ GitHub ]

  
# File 'rb/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

Instance Attribute Details

#id (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/browsing_context.rb', line 27

attr_accessor :id

Instance Method Details

#close

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/browsing_context.rb', line 76

def close
  @bidi.send_cmd('browsingContext.close', context: @id)
end

#create(type, reference_context) (private)

[ GitHub ]

  
# File 'rb/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

#get_tree(max_depth: nil)

[ GitHub ]

  
# File 'rb/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