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 Platform

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

Overview

Enum representing known and supported operating system platforms that Selenium WebDriver can run on, providing platform detection, family-based matching, and version extraction from Java system properties.

Description

The Platform enum models the operating system landscape relevant to Selenium WebDriver. It is closely related to, but not identical with, the underlying operating system; it captures platform characteristics such as program locations and line endings. Each enum constant declares one or more OS name fragments (matched case-insensitively against Java's os.name system property) and belongs to an optional family() hierarchy. Family relationships enable heuristic matching: for example, LINUX.is(UNIX) returns true because LINUX belongs to the UNIX family, and WIN10.is(WINDOWS) returns true because WIN10 belongs to the WINDOWS family. The special constant ANY matches only itself and acts as a wildcard when requesting a browser on any operating system. Platform detection uses extractFromSysProperty which applies a best-match heuristic across all enum constants, with special-case handling for Android (detected via the Dalvik VM name) and Windows 8/8.1 (detected by combining os.name and os.version). The enum also tracks major and minor version numbers parsed from the os.version system property.

The platform families are:

  • WINDOWS family: XP, VISTA, WIN7, WIN8, WIN8_1, WIN10, WIN11
  • MAC family: SNOW_LEOPARD, MOUNTAIN_LION, MAVERICKS, YOSEMITE, EL_CAPITAN, SIERRA, HIGH_SIERRA, MOJAVE, CATALINA, BIG_SUR, MONTEREY, VENTURA, SONOMA, SEQUOIA
  • UNIX family: LINUX
  • Standalone: ANDROID, IOS, ANY

Usage

Use this enum when you need to detect the current platform, compare platforms in capability matching (e.g., Selenium Grid node/session matching), or specify a target platform in DesiredCapabilities. It is commonly used in conditional test logic that must behave differently across operating systems, and in Selenium Grid to match requested capabilities against available node platforms.

Code Reference

Source Location

Signature

public enum Platform {

    // Platform families (family() returns null)
    WINDOWS("windows"),
    MAC("mac", "darwin", "macOS", "mac os x", "os x"),
    UNIX("solaris", "bsd"),
    ANDROID("android", "dalvik"),
    IOS("iOS"),
    ANY(""),

    // Windows family members (family() returns WINDOWS)
    XP("Windows Server 2003", "xp", "windows", "winnt", "windows_nt", "windows nt"),
    VISTA("windows vista", "Windows Server 2008"),
    WIN7("windows 7", "win7"),
    WIN8("Windows Server 2012", "windows 8", "win8"),
    WIN8_1("windows 8.1", "win8.1"),
    WIN10("windows 10", "win10"),
    WIN11("windows 11", "win11"),

    // MAC family members (family() returns MAC)
    SNOW_LEOPARD("snow leopard", "os x 10.6", "macos 10.6"),
    MOUNTAIN_LION("mountain lion", "os x 10.8", "macos 10.8"),
    MAVERICKS("mavericks", "os x 10.9", "macos 10.9"),
    YOSEMITE("yosemite", "os x 10.10", "macos 10.10"),
    EL_CAPITAN("el capitan", "os x 10.11", "macos 10.11"),
    SIERRA("sierra", "os x 10.12", "macos 10.12"),
    HIGH_SIERRA("high sierra", "os x 10.13", "macos 10.13"),
    MOJAVE("mojave", "os x 10.14", "macos 10.14"),
    CATALINA("catalina", "os x 10.15", "macos 10.15"),
    BIG_SUR("big sur", "os x 11.0", "macos 11.0"),
    MONTEREY("monterey", "os x 12.0", "macos 12.0"),
    VENTURA("ventura", "os x 13.0", "macos 13.0"),
    SONOMA("sonoma", "os x 14.0", "macos 14.0"),
    SEQUOIA("sequoia", "os x 15.0", "macos 15.0"),

    // UNIX family member (family() returns UNIX)
    LINUX("linux");

    // Key methods
    public static Platform getCurrent();
    public static Platform extractFromSysProperty(String osName);
    public static Platform extractFromSysProperty(String osName, String osVersion);
    public static Platform fromString(String name);
    public boolean is(Platform compareWith);
    public abstract Platform family();
    public String[] getPartOfOsName();
    public int getMajorVersion();
    public int getMinorVersion();
}

Import

import org.openqa.selenium.Platform;

I/O Contract

Static Methods

Method Input Return Type Description
getCurrent() none Platform Detects and caches the current platform from os.name and os.version system properties
extractFromSysProperty(osName) String osName Platform Determines the platform from an OS name string using heuristic matching; defaults to UNIX if unrecognized
extractFromSysProperty(osName, osVersion) String osName, String osVersion Platform Determines the platform from OS name and version strings; handles special cases for WIN8 (6.2) and WIN8_1 (6.3)
fromString(name) String name Platform Looks up a Platform by its toString() value or any of its OS name fragments; throws WebDriverException if unrecognized

Instance Methods

Method Return Type Description
family() Platform or null Returns the parent platform family (e.g., WINDOWS for WIN10, MAC for CATALINA), or null if this constant is itself a family root
is(compareWith) boolean Returns true if this platform is the same as, or belongs to the family of, the given platform; ANY matches only itself
getPartOfOsName() String[] Returns a defensive copy of the OS name fragments used for matching
getMajorVersion() int Returns the major OS version number (populated only on the instance returned by getCurrent())
getMinorVersion() int Returns the minor OS version number (populated only on the instance returned by getCurrent())

Usage Examples

Detecting the Current Platform

import org.openqa.selenium.Platform;

Platform current = Platform.getCurrent();
System.out.println("Running on: " + current);
System.out.println("Version: " + current.getMajorVersion() + "." + current.getMinorVersion());

Platform Family Comparison

import org.openqa.selenium.Platform;

Platform current = Platform.getCurrent();

if (current.is(Platform.WINDOWS)) {
    // Runs on any Windows variant: XP, VISTA, WIN7, WIN8, WIN8_1, WIN10, WIN11
    System.out.println("Windows platform detected");
} else if (current.is(Platform.MAC)) {
    // Runs on any macOS variant
    System.out.println("macOS platform detected");
} else if (current.is(Platform.UNIX)) {
    // Runs on LINUX, Solaris, BSD
    System.out.println("UNIX-like platform detected");
}

Extracting Platform from a String

import org.openqa.selenium.Platform;

// From an OS name (e.g., received in capabilities)
Platform p = Platform.extractFromSysProperty("Windows 10");
System.out.println(p);           // "Windows 10"
System.out.println(p.family());  // WINDOWS

// From a known string identifier
Platform mac = Platform.fromString("mac");
System.out.println(mac.is(Platform.MAC)); // true

Using Platform in Desired Capabilities

import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;

DesiredCapabilities caps = new DesiredCapabilities();
caps.setPlatform(Platform.WINDOWS);
// Grid will match any Windows node (XP, WIN7, WIN10, WIN11, etc.)

Related Pages

Implements Principle

Page Connections

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