class Selenium::WebDriver::BiDi::BrowsingContext

Implements the browsingContext Module of the WebDriver-BiDi specification

@api private

Constants

READINESS_STATE

Public Class Methods

new(bridge) click to toggle source

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

# 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

Public Instance Methods

close(context_id: nil) click to toggle source

Closes the browsing context.

@param [String] context_id The ID of the context to close.

Defaults to the window handle of the current context.
# 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) click to toggle source

Create a new browsing context.

@param [Symbol] type The type of browsing context to create.

Valid options are :tab and :window with :window being the default

@param [String] context_id The reference context for the new browsing context.

Defaults to the current window handle.

@return [String] The context ID of the created browsing context.

# 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
navigate(url, context_id: nil) click to toggle source

Navigates to the specified URL in the given browsing context.

@param url [String] The URL to navigate to. @param context_id [String, NilClass] The ID of the browsing context to navigate in.

Defaults to the window handle of the current context.
reload(context_id: nil, ignore_cache: false) click to toggle source

Reloads the browsing context. @param [String, NilClass] context_id The ID of the context to reload.

Defaults to the window handle of the current context.

@param [Boolean] ignore_cache Whether to bypass the cache when reloading.

Defaults to false.
# 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) click to toggle source

Traverses the browsing context history by a given delta.

@param delta [Integer] The number of steps to traverse.

Positive values go forwards, negative values go backwards.

@param context_id [String, NilClass] The ID of the context to traverse.

Defaults to the window handle of the current context.
# 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