class Selenium::WebDriver::BiDi::BrowsingContext

Implements the BrowsingContext Module of the WebDriver-BiDi specification Continue to use functionality from existing ‘driver.navigate` method

@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 36
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

activate(context_id: nil) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 109
def activate(context_id: nil)
  context_id ||= @bridge.window_handle
  @bidi.send_cmd('browsingContext.activate', context: context_id)
end
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 79
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 92
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
handle_user_prompt(context_id, accept: true, text: nil) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 105
def handle_user_prompt(context_id, accept: true, text: nil)
  @bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text)
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 69
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
set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: nil) click to toggle source
# File lib/selenium/webdriver/bidi/browsing_context.rb, line 99
def set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: nil)
  context_id ||= @bridge.window_handle
  params = {context: context_id, viewport: {width:, height:}, device_pixel_ratio:}
  @bidi.send_cmd('browsingContext.setViewport', **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 59
def traverse_history(delta, context_id: nil)
  context_id ||= @bridge.window_handle
  @bidi.send_cmd('browsingContext.traverseHistory', context: context_id, delta: delta)
end