Selenium WebDriver containers for Testcontainers - provides lightweight, throwaway instances of Selenium browsers running in Docker containers for automated testing
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.
import org.testcontainers.containers.SeleniumUtils;
import java.util.jar.Manifest;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:
Extracts Selenium version information from a JAR manifest.
public static String getSeleniumVersionFromManifest(Manifest manifest);Parameters:
manifest: JAR manifest object to inspectReturns: 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:
Build-Info section, Selenium-Version attribute (legacy format)Selenium section, Selenium-Version attribute (Selenium 3.x+ format)public static final String DEFAULT_SELENIUM_VERSION = "2.45.0";The fallback version used when Selenium version cannot be determined from the classpath.
The SeleniumUtils class is automatically used by BrowserWebDriverContainer during container configuration to:
Based on the detected Selenium version, the container automatically selects:
Selenium 4.x and later:
selenium/standalone-chrome, selenium/standalone-firefox, selenium/standalone-edgeSelenium 3.x and earlier:
selenium/standalone-chrome-debug, selenium/standalone-firefox-debug| Selenium Version | Chrome | Firefox | Edge | VNC 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 |
When version detection fails:
When multiple Selenium versions are found on classpath:
The utility class uses SLF4J logging for:
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 capabilitiespublic final class SeleniumUtils {
private SeleniumUtils(); // Private constructor - utility class
}The class is designed as a utility class with:
Install with Tessl CLI
npx tessl i tessl/maven-org-testcontainers--selenium