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

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/bidi/browsing_context.rb

Constant Summary collapse

READINESS_STATE =
{
  none: 'none',
  interactive: 'interactive',
  complete: 'complete'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver:, browsing_context_id: nil, type: nil, reference_context: nil) ⇒ BrowsingContext

Returns a new instance of BrowsingContext.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#closeObject



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

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

#get_tree(max_depth: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# 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


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'rb/lib/selenium/webdriver/bidi/browsing_context.rb', line 50

def navigate(url:, readiness_state: nil)
  unless readiness_state.nil? || READINESS_STATE.key?(readiness_state)
    raise ArgumentError,
          "Valid readiness states are :none, :interactive & :complete. Received: #{readiness_state.inspect}"
  end

  navigate_result = @bidi.send_cmd('browsingContext.navigate', context: @id, url: url,
                                                               wait: READINESS_STATE[readiness_state])

  NavigateResult.new(
    url: navigate_result['url'],
    navigation_id: navigate_result['navigation']
  )
end