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:SeleniumHQ Selenium ImmutableCapabilities

From Leeroopedia
Knowledge Sources
Domains WebDriver, Capabilities
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for representing a read-only, thread-safe set of browser capabilities provided by the Selenium WebDriver library.

Description

ImmutableCapabilities is an immutable implementation of the Capabilities interface that wraps capability key-value pairs in an unmodifiable TreeMap. It pre-computes its hash code at construction time for efficient use in hash-based collections. The class provides multiple convenience constructors accepting from zero up to five key-value pairs, as well as constructors from an existing Capabilities instance or a Map, and a static copyOf factory method that avoids redundant copying when the input is already immutable.

Usage

Import and use ImmutableCapabilities when you need a guaranteed-immutable snapshot of capabilities, for example when storing capabilities as map keys, passing them across threads, or when a method contract requires that capabilities cannot be modified after creation.

Code Reference

Source Location

Signature

public class ImmutableCapabilities implements Capabilities

Import

import org.openqa.selenium.ImmutableCapabilities;

I/O Contract

Inputs

Name Type Required Description
(none) No No-arg constructor creates an empty immutable capabilities instance
k, v String, Object Yes Single key-value pair constructor (up to 5 pairs supported via overloaded constructors)
other Capabilities Yes Copy constructor; creates an immutable snapshot from an existing Capabilities instance
capabilities Map<?, ?> Yes Map constructor; keys must be String instances, values must be non-null

Outputs

Name Type Description
getCapability(name) Object (nullable) Returns the value for the given capability name, or null if not present
asMap() Map<String, Object> Returns the unmodifiable internal map of all capabilities
copyOf(capabilities) ImmutableCapabilities Static factory that returns the input if already immutable, otherwise creates a new copy

Usage Examples

// Create with key-value pairs
ImmutableCapabilities caps = new ImmutableCapabilities(
    "browserName", "chrome",
    "platformName", "LINUX"
);

// Create from an existing Capabilities object
MutableCapabilities mutable = new MutableCapabilities();
mutable.setCapability("browserName", "firefox");
ImmutableCapabilities snapshot = new ImmutableCapabilities(mutable);

// Use the static copyOf factory (avoids redundant copying)
ImmutableCapabilities copy = ImmutableCapabilities.copyOf(snapshot);
// copy == snapshot (same instance, since already immutable)

// Create from a Map
Map<String, Object> map = Map.of("browserName", "edge");
ImmutableCapabilities fromMap = new ImmutableCapabilities(map);

Related Pages

Page Connections

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