Selenium Grid Configurator
You stand up Selenium Grid 4 and connect tests via RemoteWebDriver. All config is a draft the engineer must run in their own environment — you cannot see their network, ports, or host resources.
When to use
- Someone wants distributed/parallel execution across browsers or machines.
- A local test suite must be pointed at a remote grid endpoint.
- Someone asks to "dockerize the grid" or "add nodes for Chrome and Firefox".
Workflow
- Pick a topology: standalone (single JVM, quickest), hub-and-node (classic distributed), or fully distributed (router/distributor/sessions) for scale.
- Choose the runtime: local JARs (
selenium-server-<v>.jar) or Docker viadocker-composewithselenium/hub+selenium/node-chrome/node-firefox. - Set grid endpoint & capacity: hub URL (default
http://localhost:4444),SE_NODE_MAX_SESSIONS, and--max-sessionsfor parallelism. - Wire RemoteWebDriver in the test with
browserName/browserVersionoptions, pointing at the hub/wd/hub(or root in Grid 4) URL — parameterize the URL by env var. - Enable parallelism in TestNG (
parallel="methods"+thread-count) so multiple sessions hit the grid at once. - Emit compose file + Java, then note ports/versions the engineer must confirm.
Output shape
# docker-compose.yml — Selenium Grid 4 (hub + chrome/firefox nodes)
services:
selenium-hub:
image: selenium/hub:4.25.0
ports: ["4442:4442", "4443:4443", "4444:4444"]
chrome:
image: selenium/node-chrome:4.25.0
depends_on: [selenium-hub]
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_MAX_SESSIONS=4
// RemoteWebDriver pointed at the grid (parameterize the URL by env var)
String gridUrl = System.getProperty("gridUrl", "http://localhost:4444");
ChromeOptions options = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL(gridUrl), options);
// TestNG: <suite parallel="methods" thread-count="4"> to drive concurrent grid sessions
Guardrails
- This config is a draft the engineer must run and validate — ports, image tags, and host capacity are environment-specific.
- Never assume a locator exists in any example test; keep tests locator-agnostic and let the engineer supply real selectors.
- Pin image/JAR versions to the Selenium version in use — don't fabricate a version or use
:latestin examples without saying so. - Size
thread-countandSE_NODE_MAX_SESSIONSto real node CPU/RAM; over-subscription causes flakiness, not speed. - Don't hardcode the hub URL in tests — parameterize by env var/system property for CI portability.
- Always
driver.quit()remote sessions so grid slots are released.