Careeroza
Selenium Grid and CI
What is Selenium Grid 4 and what are its components?
Grid runs tests on remote machines and browsers in parallel. Grid 4 can run as standalone (all in one), hub and node, or fully distributed with these components:
| Component | Role |
|---|---|
| Router | entry point; forwards requests |
| Distributor | assigns a new session to a node with free slots |
| Session Map | remembers which node owns which session |
| New Session Queue | holds requests while all slots are busy |
| Event Bus | messages between components |
| Node | runs the browsers |
Example
java -jar selenium-server-4.25.0.jar standaloneExample output
INFO [Standalone.execute] - Started Selenium Standalone 4.25.0 (revision 8a8aea2337): http://192.168.1.10:4444
How do you run a test on Grid?
ChromeOptions options = new ChromeOptions();
options.setPlatformName("linux");
WebDriver driver = new RemoteWebDriver(URI.create("http://grid.qa.local:4444").toURL(), options);
driver.get("https://shopease.example.com");Use RemoteWebDriver with the Grid URL and browser options. For parallel runs, keep the driver in a ThreadLocal and set parallel and thread-count in testng.xml. Docker images (selenium/hub, selenium/node-chrome) are the easiest way to host a Grid.
How do you run Selenium tests in a CI pipeline?
- The pipeline checks out the code, sets up JDK and Maven, and runs
mvn clean test -DsuiteXml=testng-smoke.xml -Dheadless=true. - Browsers run headless on the agent, or on a Selenium Grid / cloud grid via
RemoteWebDriver. - Secrets (passwords, access keys) come from CI secrets as environment variables.
- Reports and screenshots are archived (
upload-artifact/publishHTML) even on failure. - Triggers: smoke on every pull request, full regression on a nightly
cron.