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

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implements the browsingContext Module of the WebDriver-BiDi specification

Constant Summary collapse

READINESS_STATE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'none' => 'none',
  'eager' => 'interactive',
  'normal' => 'complete'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(bridge) ⇒ BrowsingContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: store current window handle in bridge object instead of always calling it



35
36
37
38
39
40
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 35

def initialize(bridge)
  @bridge = bridge
  @bidi = @bridge.bidi
  page_load_strategy = bridge.capabilities[:page_load_strategy]
  @readiness = READINESS_STATE[page_load_strategy]
end

Instance Method Details

#close(context_id: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Closes the browsing context.

Parameters:

  • context_id (String) (defaults to: nil)

    The ID of the context to close. Defaults to the window handle of the current context.



78
79
80
81
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 78

def close(context_id: nil)
  context_id ||= @bridge.window_handle
  @bidi.send_cmd('browsingContext.close', context: context_id)
end

#create(type: nil, context_id: nil) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new browsing context.

Parameters:

  • type (Symbol) (defaults to: nil)

    The type of browsing context to create. Valid options are :tab and :window with :window being the default

  • context_id (String) (defaults to: nil)

    The reference context for the new browsing context. Defaults to the current window handle.

Returns:

  • (String)

    The context ID of the created browsing context.



91
92
93
94
95
96
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 91

def create(type: nil, context_id: nil)
  type ||= :window
  context_id ||= @bridge.window_handle
  result = @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: context_id)
  result['context']
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Navigates to the specified URL in the given browsing context.

Parameters:

  • url (String)

    The URL to navigate to.

  • context_id (String, NilClass) (defaults to: nil)

    The ID of the browsing context to navigate in. Defaults to the window handle of the current context.



47
48
49
50
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 47

def navigate(url, context_id: nil)
  context_id ||= @bridge.window_handle
  @bidi.send_cmd('browsingContext.navigate', context: context_id, url: url, wait: @readiness)
end

#reload(context_id: nil, ignore_cache: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reloads the browsing context.

Parameters:

  • context_id (String, NilClass) (defaults to: nil)

    The ID of the context to reload. Defaults to the window handle of the current context.

  • ignore_cache (Boolean) (defaults to: false)

    Whether to bypass the cache when reloading. Defaults to false.



68
69
70
71
72
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 68

def reload(context_id: nil, ignore_cache: false)
  context_id ||= @bridge.window_handle
  params = {context: context_id, ignore_cache: ignore_cache, wait: @readiness}
  @bidi.send_cmd('browsingContext.reload', **params)
end

#traverse_history(delta, context_id: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Traverses the browsing context history by a given delta.

Parameters:

  • delta (Integer)

    The number of steps to traverse. Positive values go forwards, negative values go backwards.

  • context_id (String, NilClass) (defaults to: nil)

    The ID of the context to traverse. Defaults to the window handle of the current context.



58
59
60
61
# File 'lib/selenium/webdriver/bidi/browsing_context.rb', line 58

def traverse_history(delta, context_id: nil)
  context_id ||= @bridge.window_handle
  @bidi.send_cmd('browsingContext.traverseHistory', context: context_id, delta: delta)
end