QA
Mid-level QASeleniumFree question

What is Selenium Grid 4? How do you run it with Docker?

60-second answer

Selenium Grid lets me run tests on multiple machines, browsers and OS combinations in parallel by sending commands to a central endpoint that routes each session to a free node. Grid 4 was redesigned with components like router, distributor, session map, session queue, event bus and nodes, and can run in standalone, hub-and-node, or fully distributed mode. It supports Docker and Kubernetes natively. With the official docker-selenium images I can start a hub and Chrome and Firefox nodes using docker compose, and point RemoteWebDriver at port 4444.

Explanation

  • Standalone: everything in one process, good for local use.
  • Hub and node: the classic setup.
  • Distributed: each component separately, for large scale.
  • Grid UI at http://localhost:4444/ui shows sessions and capacity; supports live VNC view.
  • SE_NODE_MAX_SESSIONS controls concurrent sessions per node.
  • Alternatives: cloud providers, Selenoid, Moon, Kubernetes with KEDA autoscaling.

Example

CI spins up a Grid with docker compose, runs 6 Chrome and 2 Firefox sessions in parallel, then tears it down, so no permanent Grid servers are needed.

Sample code

services:
  selenium-hub:
    image: selenium/hub:4.25.0
    ports: ["4442:4442", "4443:4443", "4444:4444"]
  chrome:
    image: selenium/node-chrome:4.25.0
    shm_size: 2gb
    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
  firefox:
    image: selenium/node-firefox:4.25.0
    shm_size: 2gb
    depends_on: [selenium-hub]
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443