Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Teamcapybara Capybara Edge Driver Specialization

From Leeroopedia
Knowledge Sources
Domains Testing, Driver_Architecture
Last Updated 2026-02-12 00:00 GMT

Overview

Edge browser-specific WebDriver specializations provided by Capybara::Selenium::Driver::EdgeDriver, handling fullscreen window management, window resizing, session reset with CDP-based storage clearing, and download path configuration.

Description

Capybara::Selenium::Driver::EdgeDriver is a Ruby module that is extended onto the Selenium driver instance when the browser type is :edge or :edge_chrome, registered via Driver.register_specialization.

On extension (self.extended), it extends the driver's bridge with IsDisplayed support if the bridge does not already support the :is_element_displayed command, and defaults native_displayed to false.

Key method overrides:

  • fullscreen_window(handle) -- For EdgeDriver version >= 75, wraps the call in within_given_window and falls back to a direct HTTP POST to /session/:id/window/fullscreen if full_screen_window raises NoMethodError.
  • resize_window_to(handle, width, height) -- Catches UnknownError with "failed to change window state" (caused by EdgeDriver not waiting long enough when exiting fullscreen), sleeps 0.25 seconds, and retries.
  • reset! -- For EdgeDriver version >= 75, switches to the first window, closes all others, clears storage (unless on about: pages), navigates to about:blank, waits for empty page, handles unhandled alert dismissal, and finishes with CDP Storage.clearDataForOrigin for cookies and optionally local storage.
  • download_path=(path) -- Delegates to @browser.download_path= if available, otherwise uses CDP Page.setDownloadBehavior with behavior: 'allow'.
  • execute_cdp(cmd, params) -- Wraps CDP command execution, delegating to browser.execute_cdp if available or falling back to a direct HTTP POST to /session/:id/ms/cdp/execute.

Private helpers manage storage clearing logic: storage_types_to_clear builds a comma-separated list of cookies and optionally local_storage, uniform_storage_clear? checks if storage clearing options are uniform, clear_storage skips clearing on about: URLs to avoid EdgeDriver crashes, and delete_all_cookies uses CDP Network.clearBrowserCookies for EdgeDriver >= 75.

The build_node method creates EdgeNode instances, and edgedriver_version extracts the version from browser capabilities via caps['msedge'].

Usage

Automatic. When Capybara creates a Selenium driver with :edge or :edge_chrome browser, this module is extended onto the driver instance during specialize_driver.

Code Reference

Source Location

  • Repository: capybara
  • File: lib/capybara/selenium/driver_specializations/edge_driver.rb (128 lines)

Signature

module Capybara::Selenium::Driver::EdgeDriver
  def self.extended(base)
    # Sets up IsDisplayed bridge extension and native_displayed default
  end

  def fullscreen_window(handle)
    # @param handle [String] Window handle
    # Falls back to HTTP POST for EdgeDriver >= 75
  end

  def resize_window_to(handle, width, height)
    # @param handle [String] Window handle
    # @param width [Integer] Target width
    # @param height [Integer] Target height
    # Retries after 0.25s sleep on state change failure
  end

  def reset!
    # Closes extra windows, clears storage, navigates to about:blank
    # Uses CDP Storage.clearDataForOrigin for thorough clearing
  end

  def download_path=(path)
    # @param path [String] Filesystem path for downloads
    # Falls back to CDP Page.setDownloadBehavior
  end

  def execute_cdp(cmd, params = {})
    # @param cmd [String] CDP command (e.g., "Storage.clearDataForOrigin")
    # @param params [Hash] CDP command parameters
    # @return [Object] CDP command result value
  end
end

# Registration
Capybara::Selenium::Driver.register_specialization :edge, Capybara::Selenium::Driver::EdgeDriver
Capybara::Selenium::Driver.register_specialization :edge_chrome, Capybara::Selenium::Driver::EdgeDriver

Import

require 'capybara/selenium/nodes/edge_node'
# Auto-loaded when driver specialization is applied

I/O Contract

Inputs

Name Type Required Description
handle String Yes Window handle for fullscreen_window and resize_window_to
width Integer Yes Target window width for resize_window_to
height Integer Yes Target window height for resize_window_to
path String Yes Download directory path for download_path=
cmd String Yes CDP command name for execute_cdp
params Hash No CDP command parameters for execute_cdp

Outputs

Name Type Description
CDP result Object Return value from CDP command execution
EdgeNode Capybara::Selenium::EdgeNode Edge-specific node wrapper from build_node

Internal Details

Storage Clearing Logic

Method Description
storage_types_to_clear Returns comma-separated string of cookies and optionally local_storage
clear_all_storage? True when neither :clear_session_storage nor :clear_local_storage is false
uniform_storage_clear? True when storage clearing options have at most one unique truthiness value
storage_clears Returns [clear_session_storage, clear_local_storage] option values
clear_storage Skips super when URL is nil or starts with about: to prevent EdgeDriver crashes

Version-Gated Behavior

Several methods gate their behavior on edgedriver_version, which reads from browser.capabilities['msedge']. For versions below 75, the methods fall through to super (the base Selenium driver behavior).

Usage Examples

Automatic Specialization

# EdgeDriver specialization is applied automatically
Capybara.register_driver :edge do |app|
  Capybara::Selenium::Driver.new(app, browser: :edge)
end

# The driver instance now has EdgeDriver methods mixed in
# reset!, fullscreen_window, resize_window_to, etc. are Edge-specific

Setting Download Path

page.driver.download_path = '/tmp/downloads'
# Uses CDP Page.setDownloadBehavior if browser API not available

Executing CDP Commands

page.driver.execute_cdp('Network.clearBrowserCookies')
page.driver.execute_cdp('Storage.clearDataForOrigin',
  origin: '*',
  storageTypes: 'cookies,local_storage'
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment