Selenium Grid is a distributed testing infrastructure that allows running WebDriver tests in parallel across multiple machines and browsers.
—
Selenium Grid provides a comprehensive command-line interface for starting and managing grid components, with built-in help system, configuration support, and extensible command framework.
The primary entry point for all grid operations via command-line interface.
/**
* Main class providing CLI entry point for Selenium Grid
*/
class Main {
/** Main method that processes command-line arguments and executes commands */
public static void main(String[] args);
/** Internal constructor for testing */
Main(PrintStream out, PrintStream err, String[] args);
/** Execute the main logic - used internally */
void go();
/** Load available CLI commands using ServiceLoader */
private static Set<CliCommand> loadCommands(ClassLoader loader);
}Usage Examples:
# Start standalone grid (combined hub and node)
java -jar selenium-server-4.33.0.jar standalone
# Start hub component
java -jar selenium-server-4.33.0.jar hub
# Start node and register with hub
java -jar selenium-server-4.33.0.jar node --hub http://hub.example.com:4444
# Get help information
java -jar selenium-server-4.33.0.jar info
# Show version information
java -jar selenium-server-4.33.0.jar --version
# Show help for specific command
java -jar selenium-server-4.33.0.jar hub --helpStarts the hub component that coordinates session distribution and node management.
/**
* CLI command for starting Selenium Grid hub
*/
@AutoService(CliCommand.class)
class Hub extends TemplateGridServerCommand {
/** Get command name for CLI */
String getName();
/** Get roles this command configures */
Set<Role> getConfigurableRoles();
/** Get command-line flag objects */
Set<Object> getFlagObjects();
/** Get default configuration for this command */
Config getDefaultConfig();
/** Create HTTP handlers for the hub */
Handlers<Route> createHandlers(Config config);
}Hub Configuration:
# Basic hub startup
java -jar selenium-server-4.33.0.jar hub
# Hub with custom configuration
java -jar selenium-server-4.33.0.jar hub \
--port 4444 \
--host 0.0.0.0 \
--session-timeout 300 \
--session-request-timeout 300 \
--healthcheck-interval 120
# Hub with configuration file
java -jar selenium-server-4.33.0.jar hub \
--config hub-config.tomlStarts a standalone grid that combines hub and node functionality in a single process.
/**
* CLI command for starting Selenium Grid in standalone mode
*/
@AutoService(CliCommand.class)
class Standalone extends TemplateGridServerCommand {
String getName();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
/** Additional standalone-specific configuration */
StandaloneConfig getStandaloneConfig();
}Standalone Configuration:
# Basic standalone startup (auto-detects browsers)
java -jar selenium-server-4.33.0.jar standalone
# Standalone with specific browsers
java -jar selenium-server-4.33.0.jar standalone \
--detect-drivers \
--max-sessions 4
# Standalone with custom capabilities
java -jar selenium-server-4.33.0.jar standalone \
--config standalone-config.tomlStarts a node component that executes WebDriver sessions and registers with a hub.
/**
* CLI command for starting Selenium Grid node
*/
@AutoService(CliCommand.class)
class NodeServer extends TemplateGridServerCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
}Node Configuration:
# Basic node startup
java -jar selenium-server-4.33.0.jar node \
--hub http://hub.example.com:4444
# Node with specific configuration
java -jar selenium-server-4.33.0.jar node \
--hub http://hub.example.com:4444 \
--port 5555 \
--max-sessions 2 \
--detect-drivers
# Node with custom capabilities
java -jar selenium-server-4.33.0.jar node \
--hub http://hub.example.com:4444 \
--config node-config.tomlDisplays system information and grid configuration details.
/**
* CLI command for displaying grid information
*/
@AutoService(CliCommand.class)
class InfoCommand extends TemplateGridCommand {
String getName();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
/** Configure and return executable for info display */
Executable configure(PrintStream out, PrintStream err, String... args);
}Info Command Usage:
# Display system information
java -jar selenium-server-4.33.0.jar info
# Output includes:
# - Selenium version
# - Java version and vendor
# - Operating system details
# - Available WebDriver binaries
# - Default configuration valuesStarts a standalone event bus server for distributed grid communication.
/**
* CLI command for starting standalone event bus
*/
@AutoService(CliCommand.class)
class EventBusCommand extends TemplateGridCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
boolean isShown(); // Returns false - hidden command
/** Configure and return executable for event bus */
Executable configure(PrintStream out, PrintStream err, String... args);
}Event Bus Configuration:
# Start standalone event bus (hidden command)
java -jar selenium-server-4.33.0.jar event-bus
# Event bus with custom ports
java -jar selenium-server-4.33.0.jar event-bus \
--port 5557 \
--publish tcp://*:4442 \
--subscribe tcp://*:4443Generates shell autocompletion scripts for the selenium CLI.
/**
* CLI command for generating shell autocompletions
*/
@AutoService(CliCommand.class)
class CompletionCommand implements CliCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
/** Configure and return executable for completion generation */
Executable configure(PrintStream out, PrintStream err, String... args);
}Completion Usage:
# Generate bash completion script
java -jar selenium-server-4.33.0.jar completion bash
# Generate zsh completion script
java -jar selenium-server-4.33.0.jar completion zsh
# Generate fish completion script
java -jar selenium-server-4.33.0.jar completion fishStarts a standalone distributor component for session distribution and node management.
/**
* CLI command for starting standalone distributor server
*/
@AutoService(CliCommand.class)
class DistributorServer extends TemplateGridServerCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
}Starts a standalone router component for routing WebDriver requests.
/**
* CLI command for starting standalone router server
*/
@AutoService(CliCommand.class)
class RouterServer extends TemplateGridServerCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
}Starts a standalone session map server for session tracking.
/**
* CLI command for starting standalone session map server
*/
@AutoService(CliCommand.class)
class SessionMapServer extends TemplateGridServerCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
}Starts a standalone session queue server for request queuing.
/**
* CLI command for starting standalone session queue server
*/
@AutoService(CliCommand.class)
class NewSessionQueueServer extends TemplateGridServerCommand {
String getName();
String getDescription();
Set<Role> getConfigurableRoles();
Set<Object> getFlagObjects();
Config getDefaultConfig();
Handlers<Route> createHandlers(Config config);
}Abstract base classes that provide common functionality for grid commands.
/**
* Base class for all grid CLI commands
*/
abstract class TemplateGridCommand implements CliCommand {
/** Get command name for CLI parsing */
abstract String getName();
/** Get help text for this command */
String getDescription();
/** Get roles this command can configure */
Set<Role> getConfigurableRoles();
/** Get command-line flag definition objects */
Set<Object> getFlagObjects();
/** Get default configuration for this command */
Config getDefaultConfig();
/** Configure command with parsed arguments */
Executable configure(PrintStream out, PrintStream err, String... args);
/** Common configuration processing */
protected Config buildConfig(String... args);
}
/**
* Base class for server-type grid commands (hub, standalone)
*/
abstract class TemplateGridServerCommand extends TemplateGridCommand {
/** Create HTTP route handlers for this server */
abstract Handlers<Route> createHandlers(Config config);
/** Start the server with configured handlers */
@Override
Executable configure(PrintStream out, PrintStream err, String... args);
/** Common server startup logic */
protected Server<?> startServer(Config config, Handlers<Route> handlers);
}Commands integrate with the configuration system for flexible setup.
/**
* Default configuration providers for each command type
*/
class DefaultHubConfig implements Config {
// Provides default hub configuration values
}
class DefaultStandaloneConfig implements Config {
// Provides default standalone configuration values
}
class DefaultNodeConfig implements Config {
// Provides default node configuration values
}
class DefaultDistributorConfig implements Config {
// Provides default distributor configuration values
}
class DefaultSessionMapConfig implements Config {
// Provides default session map configuration values
}
class DefaultRouterConfig implements Config {
// Provides default router configuration values
}
class DefaultNewSessionQueueConfig implements Config {
// Provides default session queue configuration values
}
/**
* Command-line flag definitions
*/
class StandaloneFlags {
@Parameter(names = {"--port", "-p"}, description = "Port to listen on")
int port = 4444;
@Parameter(names = {"--host"}, description = "IP or hostname to bind to")
String host = "0.0.0.0";
@Parameter(names = {"--max-sessions"}, description = "Maximum concurrent sessions")
int maxSessions = Runtime.getRuntime().availableProcessors();
@Parameter(names = {"--detect-drivers"}, description = "Auto-detect WebDriver executables")
boolean detectDrivers = true;
}
class InfoFlags {
@Parameter(names = {"--config-help"}, description = "Show configuration options")
boolean configHelp = false;
}// Create custom grid commands
@AutoService(CliCommand.class)
public class CustomGridCommand extends TemplateGridCommand {
@Override
public String getName() {
return "custom";
}
@Override
public String getDescription() {
return "Custom grid command for specialized operations";
}
@Override
public Set<Role> getConfigurableRoles() {
return Set.of(Role.of("custom"));
}
@Override
public Executable configure(PrintStream out, PrintStream err, String... args) {
Config config = buildConfig(args);
return () -> {
// Custom command logic
out.println("Executing custom grid command");
performCustomOperation(config);
};
}
private void performCustomOperation(Config config) {
// Implementation specific to custom command
}
}// Bootstrap support for loading custom commands from JARs
public class Bootstrap {
/** Main method that supports loading extension JARs */
public static void main(String[] args);
/** Load commands from external JAR files */
static Set<CliCommand> loadPluginCommands(Path... jarPaths);
/** Bootstrap with custom ClassLoader for extensions */
static void bootstrapWithPlugins(String[] args, Path... extensionJars);
}Plugin Usage:
# Load custom commands from extension JARs
java -cp selenium-server-4.33.0.jar:my-extension.jar \
org.openqa.selenium.grid.Bootstrap custom --option value
# Extension JARs can contain additional @AutoService(CliCommand.class) implementations# hub-config.toml
[server]
port = 4444
host = "0.0.0.0"
max-threads = 24
[distributor]
healthcheck-interval = "120s"
reject-unsupported-caps = true
[sessionmap]
implementation = "org.openqa.selenium.grid.sessionmap.redis.RedisSessionMap"
[sessionqueue]
implementation = "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue"
request-timeout = "300s"
[events]
implementation = "org.openqa.selenium.events.zeromq.ZeroMqEventBus"
publish = "tcp://*:4442"
subscribe = "tcp://*:4443"{
"server": {
"port": 5555,
"host": "0.0.0.0"
},
"node": {
"max-sessions": 2,
"session-timeout": "300s",
"heartbeat-period": "60s"
},
"docker": {
"images": {
"chrome": "selenium/node-chrome:latest",
"firefox": "selenium/node-firefox:latest"
}
}
}# Global help
java -jar selenium-server-4.33.0.jar --help
# Command-specific help
java -jar selenium-server-4.33.0.jar hub --help
java -jar selenium-server-4.33.0.jar node --help
java -jar selenium-server-4.33.0.jar standalone --help
# Configuration help
java -jar selenium-server-4.33.0.jar info --config-help
# Version information
java -jar selenium-server-4.33.0.jar --version# Common environment variables used by commands
SE_PORT=4444 # Server port
SE_HOST=0.0.0.0 # Server host
SE_MAX_SESSIONS=4 # Maximum concurrent sessions
SE_SESSION_TIMEOUT=300 # Session timeout in seconds
SE_REGISTRATION_SECRET=secret # Node registration secret
SE_HUB_URL=http://hub:4444 # Hub URL for node registration
# Configuration file location
SE_CONFIG_FILE=/etc/selenium/grid.toml
# Java system properties can also be used
java -Dselenium.grid.port=4444 -jar selenium-server-4.33.0.jar hub# Start as background daemon
nohup java -jar selenium-server-4.33.0.jar hub > hub.log 2>&1 &
# With systemd service
systemctl start selenium-hub
systemctl enable selenium-hub
# Docker deployment
docker run -d -p 4444:4444 selenium/hub:4.33.0
# Docker compose for full grid
docker-compose up -d hub chrome firefoxInstall with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-grid