CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-testcontainers--selenium

Selenium WebDriver containers for Testcontainers - provides lightweight, throwaway instances of Selenium browsers running in Docker containers for automated testing

Overview
Eval results
Files

selenium-utils.mddocs/

Selenium Version Detection

The SeleniumUtils class provides utilities for detecting the Selenium version from the classpath and ensuring browser image compatibility. This is essential for automatic Docker image selection based on the Selenium API version in use.

Imports

import org.testcontainers.containers.SeleniumUtils;
import java.util.jar.Manifest;

Version Detection

Classpath Selenium Version Detection

Automatically detects the Selenium version from JARs on the classpath.

public static String determineClasspathSeleniumVersion();

Returns: String representing the detected Selenium version, or DEFAULT_SELENIUM_VERSION if detection fails

Usage:

import org.testcontainers.containers.SeleniumUtils;

String seleniumVersion = SeleniumUtils.determineClasspathSeleniumVersion();
System.out.println("Detected Selenium version: " + seleniumVersion);
// Output: "Detected Selenium version: 4.15.0"

Detection Process:

  1. Scans all META-INF/MANIFEST.MF files on the classpath
  2. Looks for Selenium version information in manifest attributes
  3. Returns the first valid version found
  4. Falls back to DEFAULT_SELENIUM_VERSION if no version is detected

Manifest Version Extraction

Extracts Selenium version information from a JAR manifest.

public static String getSeleniumVersionFromManifest(Manifest manifest);

Parameters:

  • manifest: JAR manifest object to inspect

Returns: String representing the Selenium version, or null if not found

Usage:

import java.util.jar.Manifest;
import java.util.jar.JarFile;

JarFile jarFile = new JarFile("selenium-api-4.15.0.jar");
Manifest manifest = jarFile.getManifest();
String version = SeleniumUtils.getSeleniumVersionFromManifest(manifest);

Manifest Attribute Lookup: The method checks manifest attributes in the following order:

  1. Build-Info section, Selenium-Version attribute (legacy format)
  2. Selenium section, Selenium-Version attribute (Selenium 3.x+ format)

Constants

Default Version

public static final String DEFAULT_SELENIUM_VERSION = "2.45.0";

The fallback version used when Selenium version cannot be determined from the classpath.

Integration with Browser Containers

The SeleniumUtils class is automatically used by BrowserWebDriverContainer during container configuration to:

  1. Detect Selenium Version: Determine the Selenium API version in use
  2. Select Compatible Images: Choose appropriate browser Docker images
  3. Handle Version Compatibility: Ensure browser images work with the detected Selenium version

Automatic Image Selection

Based on the detected Selenium version, the container automatically selects:

Selenium 4.x and later:

  • Standard images: selenium/standalone-chrome, selenium/standalone-firefox, selenium/standalone-edge
  • VNC support is built into standard images

Selenium 3.x and earlier:

  • Debug images: selenium/standalone-chrome-debug, selenium/standalone-firefox-debug
  • Edge is not supported in older versions
  • Separate debug images required for VNC support

Version Compatibility Matrix

Selenium VersionChromeFirefoxEdgeVNC Support
4.x+✅ Standard/Debug✅ Standard/Debug✅ Standard✅ Built-in
3.x✅ Debug only✅ Debug only❌ Not supported✅ Debug images
2.x✅ Debug only✅ Debug only❌ Not supported✅ Debug images

Error Handling

Version Detection Failures

When version detection fails:

  1. Warning is logged about using default version
  2. DEFAULT_SELENIUM_VERSION is returned
  3. Container continues with fallback configuration

Multiple Versions Detected

When multiple Selenium versions are found on classpath:

  1. Warning is logged about version ambiguity
  2. First detected version is used
  3. May result in compatibility issues

Logging

The utility class uses SLF4J logging for:

  • INFO: Successfully detected versions
  • WARN: Fallback to default version, multiple versions detected
  • DEBUG: Detailed failure information

Usage in Container Configuration

The version detection is automatically used when creating browser containers:

// Automatic version detection and image selection
BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
    .withCapabilities(new ChromeOptions());

// The container automatically:
// 1. Calls SeleniumUtils.determineClasspathSeleniumVersion()
// 2. Selects appropriate Chrome image based on version
// 3. Configures VNC recording based on version capabilities

Utility Class Design

public final class SeleniumUtils {
    private SeleniumUtils(); // Private constructor - utility class
}

The class is designed as a utility class with:

  • Private constructor to prevent instantiation
  • All methods are static
  • No instance state
  • Thread-safe operations

Install with Tessl CLI

npx tessl i tessl/maven-org-testcontainers--selenium

docs

browser-container.md

index.md

selenium-utils.md

video-recording.md

tile.json