The docker-compose.yml
defines the full stack:
- Selenium Grid Hub + Chrome Nodes: Parallel test execution using containers.
- InfluxDB: Stores time-series performance metrics.
- Grafana: Visualizes metrics in real-time dashboards.
Key highlights from the compose file:
selenium-hub
: Exposes ports 4442-4444 for communication.chrome1
tochrome4
: Connect to the hub and offer isolated Chrome browser instances.influxdb
: Configured with authentication and volume for persistent data.grafana
: Reads data from InfluxDB and runs on port 3000.
You can scale Chrome nodes by increasing the number of node services or using
--scale
with Docker Compose.
version: '3.8'
services:
influxdb:
image: influxdb:1.8
container_name: influxdb
ports:
- "8086:8086"
environment:
- INFLUXDB_DB=metrics
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=admin123
- INFLUXDB_HTTP_AUTH_ENABLED=true
volumes:
- influxdb_data:/var/lib/influxdb
networks:
- monitoring
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin123
- GF_USERS_ALLOW_SIGN_UP=false
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- influxdb
networks:
- monitoring
selenium-hub:
image: seleniarm/hub:4.16.1
platform: linux/arm64
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
networks:
- monitoring
chrome1:
image: seleniarm/node-chromium:4.16.1
platform: linux/arm64
container_name: chrome1
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_HOST=chrome1
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_NODE_GRID_URL=http://selenium-hub:4444
ports:
- "5901:5900"
networks:
- monitoring
chrome2:
image: seleniarm/node-chromium:4.16.1
platform: linux/arm64
container_name: chrome2
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_HOST=chrome2
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_NODE_GRID_URL=http://selenium-hub:4444
ports:
- "5902:5900"
networks:
- monitoring
chrome3:
image: seleniarm/node-chromium:4.16.1
platform: linux/arm64
container_name: chrome3
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_HOST=chrome3
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_NODE_GRID_URL=http://selenium-hub:4444
ports:
- "5903:5900"
networks:
- monitoring
chrome4:
image: seleniarm/node-chromium:4.16.1
platform: linux/arm64
container_name: chrome4
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_HOST=chrome4
- SE_NODE_MAX_SESSIONS=1
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_NODE_GRID_URL=http://selenium-hub:4444
ports:
- "5904:5900"
networks:
- monitoring
volumes:
influxdb_data:
grafana_data:
networks:
monitoring:
driver: bridge
Launch Services with Docker Compose
- Open a terminal in your project folder.
- Run the following command:
docker-compose up -d
This will pull the necessary images (if not already available), create the network, and start all containers in detached mode.
- To confirm services are running:
docker ps
After the stack is running:
- **Selenium Grid UI**: http://localhost:4444/ui – shows registered nodes and active sessions.
- **InfluxDB**: Accessible on port 8086 (API). Default DB: `metrics`.
- **Grafana**: Visit http://localhost:3000 (user: `admin`, password: `admin123`)
- Add InfluxDB as a data source (URL: `http://influxdb:8086`, DB: `metrics`).
- Create dashboards to track latency, test pass/fail rate, request timing, and more.
This configuration sets up Selenium Grid with one Hub and two Nodes (one Chrome and one Firefox). The Hub acts as the central point where test commands are received and distributed to the nodes.
## Step 2: Start Selenium Grid
With the docker-compose.yml file in place, start the Grid by running the following command in
```javascript
docker-compose up -d
The -d flag runs the containers in detached mode, allowing you to continue using the terminal.
Step 3: Verify the Installation
To ensure that Selenium Grid is running correctly:
- Open a web browser and navigate to http://localhost:4444. This should open the Selenium Grid console, showing the Hub and connected Nodes.
- Check the Docker containers by running docker ps. You should see the containers for the Selenium Hub and Nodes running.
Optional Steps
Scaling Nodes
You can easily scale the number of Chrome or Firefox nodes by using the docker-compose up –scale command. For example, to increase the number of Chrome nodes to 3:
docker-compose up -d --scale chrome-node=3
Custom Configuration
You can customize the Selenium Grid setup by modifying the docker-compose.yml file. For instance, you can add more node types, like Opera or Edge, by including additional services in the docker-compose.yml file using the respective Docker images (selenium/node-opera or selenium/node-edge).
Setting up Selenium Grid 4 can also be accomplished through manual installations or by leveraging cloud services like AWS Fargate. Each method suits different needs based on the scale, complexity, and resource availability of your project. But again for learning this course Docker compose is by far the easiest method to spin up a grid.
Conclusion
Using Docker Compose to install and run Selenium Grid 4 simplifies the process of setting up a scalable test environment. It allows you to easily manage the Grid and scale up or down as required. This setup is ideal for development teams looking to automate their testing processes and improve the efficiency of running tests across different browsers and environments.