Selenium Grid is a distributed testing infrastructure that allows running WebDriver tests in parallel across multiple machines and browsers.
—
Selenium Grid's configuration system provides flexible, multi-source configuration management with role-based access and type-safe value retrieval.
The main configuration interface for accessing configuration values from multiple sources.
/**
* Main configuration interface providing access to configuration sections and options
*/
interface Config {
/** Get all available configuration section names */
Set<String> getSectionNames();
/** Get all options available in a specific section */
Set<String> getOptions(String section);
/** Get all values for a section/option pair (supports multi-value options) */
Optional<List<String>> getAll(String section, String option);
/** Get single string value for a section/option pair */
Optional<String> get(String section, String option);
/** Get integer value with automatic type conversion */
Optional<Integer> getInt(String section, String option);
/** Get boolean value with automatic type conversion */
Optional<Boolean> getBool(String section, String option);
/** Get array values (nested lists) */
Optional<List<List<String>>> getArray(String section, String option);
/** Get class instance with automatic instantiation */
<X> X getClass(String section, String option, Class<X> typeOfClass, String defaultClazz);
}Usage Example:
Config config = new TomlConfig(Paths.get("grid.toml"));
// Get string values
Optional<String> hubHost = config.get("server", "host");
String host = hubHost.orElse("localhost");
// Get typed values
int port = config.getInt("server", "port").orElse(4444);
boolean enableTracing = config.getBool("tracing", "enable").orElse(false);
// Instantiate classes
EventBus eventBus = config.getClass("events", "implementation",
EventBus.class, "org.openqa.selenium.events.local.GuavaEventBus");Grid roles define component responsibilities and configuration scopes.
/**
* Represents a grid component role (e.g., hub, node, distributor)
*/
class Role implements Comparable<Role> {
/** Create a new role with the specified name */
Role(String roleName);
/** Factory method to create or retrieve a role */
static Role of(String name);
/** Get the role name */
String getRoleName();
/** Compare roles for ordering */
int compareTo(Role o);
// Standard equals/hashCode implementations
boolean equals(Object o);
int hashCode();
}
/**
* Standard grid roles used by default components
*/
class StandardGridRoles {
static final Role DISTRIBUTOR_ROLE = Role.of("distributor");
static final Role EVENT_BUS_ROLE = Role.of("events");
static final Role HTTPD_ROLE = Role.of("server");
static final Role NODE_ROLE = Role.of("node");
static final Role ROUTER_ROLE = Role.of("router");
static final Role SESSION_MAP_ROLE = Role.of("sessions");
static final Role SESSION_QUEUE_ROLE = Role.of("sessionqueue");
/** Complete set of all standard roles */
static final Set<Role> ALL_ROLES = Set.of(
DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, NODE_ROLE,
ROUTER_ROLE, SESSION_MAP_ROLE, SESSION_QUEUE_ROLE
);
}
/**
* Interface for components that have associated roles
*/
interface HasRoles {
/** Get the roles this component is associated with */
Set<Role> getRoles();
}Multiple configuration sources that can be combined or used independently.
/**
* Environment variable-based configuration
*/
class EnvConfig implements Config {
EnvConfig();
// Reads from system environment variables with SE_ prefix
}
/**
* Map-based configuration for programmatic setup
*/
class MapConfig implements Config {
MapConfig(Map<String, Object> raw);
}
/**
* JSON file-based configuration
*/
class JsonConfig implements Config {
JsonConfig(Path path) throws IOException;
JsonConfig(Reader reader) throws IOException;
}
/**
* TOML file-based configuration
*/
class TomlConfig implements Config {
TomlConfig(Path path) throws IOException;
TomlConfig(Reader reader) throws IOException;
}
/**
* Annotation-based configuration using reflection
*/
class AnnotatedConfig implements Config {
AnnotatedConfig(Object annotatedObject);
}
/**
* Combines multiple configuration sources with precedence
*/
class CompoundConfig implements Config {
CompoundConfig(Config... configs);
// First config in array has highest precedence
}
/**
* Caching wrapper that memoizes configuration values
*/
class MemoizedConfig implements Config {
MemoizedConfig(Config delegate);
}Usage Example:
// Combine multiple configuration sources
Config config = new MemoizedConfig(
new CompoundConfig(
new EnvConfig(), // Highest precedence
new TomlConfig(Paths.get("grid.toml")),
new MapConfig(defaultValues) // Lowest precedence
)
);Helper classes for command-line integration and error handling.
/**
* Exception thrown for configuration-related problems
*/
class ConfigException extends RuntimeException {
ConfigException(String message);
ConfigException(String message, Throwable cause);
}
/**
* Command-line flags for configuration options
*/
class ConfigFlags {
@Parameter(names = {"--config"}, description = "Path to configuration file")
List<String> configPaths = new ArrayList<>();
Config getConfig();
}[server]
host = "0.0.0.0"
port = 4444
max-threads = 24
[distributor]
implementation = "org.openqa.selenium.grid.distributor.local.LocalDistributor"
healthcheck-interval = "120s"
[sessionmap]
implementation = "org.openqa.selenium.grid.sessionmap.redis.RedisSessionMap"
[sessionmap.redis]
host = "redis.example.com"
port = 6379{
"server": {
"host": "0.0.0.0",
"port": 4444,
"max-threads": 24
},
"distributor": {
"implementation": "org.openqa.selenium.grid.distributor.local.LocalDistributor",
"healthcheck-interval": "120s"
}
}SE_SERVER_HOST=0.0.0.0
SE_SERVER_PORT=4444
SE_DISTRIBUTOR_IMPLEMENTATION=org.openqa.selenium.grid.distributor.local.LocalDistributorInstall with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-grid