docker.recipes

Selenium Grid Testing Farm

intermediate

Browser testing infrastructure with Selenium Grid and multiple browsers.

Overview

Selenium Grid is a distributed testing framework that allows automated browser tests to run simultaneously across multiple machines and browsers. Originally developed to solve the scalability limitations of single-instance Selenium WebDriver testing, Selenium Grid operates on a hub-node architecture where the selenium-hub acts as a central registry and router, while browser nodes (chrome-node, firefox-node, edge-node) provide actual browser automation capabilities. This distributed approach enables massive parallel test execution and cross-browser validation at scale. This Selenium Grid stack creates a robust browser testing farm with dedicated Chrome, Firefox, and Edge nodes connected through an event bus system. The selenium-hub coordinates test distribution using ports 4442 and 4443 for internal communication, while exposing the grid interface on port 4444. Each browser node can handle multiple concurrent sessions, with Chrome and Firefox nodes scaled to two replicas each for increased throughput. The integrated video recording service captures test execution footage for debugging and compliance purposes. Development teams managing large test suites, QA departments requiring cross-browser validation, and organizations implementing continuous integration pipelines will benefit from this infrastructure. The configuration supports up to 16 simultaneous sessions across multiple browser types, making it ideal for teams that need to validate web applications across different browser engines simultaneously. This setup eliminates the bottleneck of sequential browser testing while providing visual feedback through recorded test sessions.

Key Features

  • Event bus architecture with dedicated publish/subscribe ports for efficient test distribution
  • Multi-browser node support with Chrome, Firefox, and Edge automation capabilities
  • Session-based load balancing with configurable maximum sessions per node
  • Horizontal scaling through Docker replicas for Chrome and Firefox nodes
  • Integrated video recording with automatic file naming for test session capture
  • Grid web interface for real-time monitoring of node status and active sessions
  • Timeout management with 300-second session limits to prevent hanging tests
  • Independent browser engine isolation preventing cross-contamination between test runs

Common Use Cases

  • 1Cross-browser compatibility testing for web applications across Chrome, Firefox, and Edge
  • 2Parallel execution of large Selenium test suites to reduce CI/CD pipeline duration
  • 3Remote browser automation for teams working with headless server environments
  • 4Load testing web applications with multiple concurrent browser sessions
  • 5Automated regression testing with video evidence for bug reproduction
  • 6Multi-tenant testing infrastructure for development teams sharing browser resources
  • 7Integration testing for web applications requiring multiple browser contexts simultaneously

Prerequisites

  • Docker Engine with at least 8GB RAM available for multiple browser node containers
  • Network ports 4442, 4443, and 4444 available for Selenium Grid communication
  • Understanding of Selenium WebDriver RemoteWebDriver configuration and capabilities
  • Sufficient disk space in ./videos directory for video recording storage
  • Basic knowledge of browser automation and test framework integration
  • Docker Compose version supporting deploy.replicas for node scaling

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 selenium-hub:
3 image: selenium/hub:latest
4 ports:
5 - "4442:4442"
6 - "4443:4443"
7 - "4444:4444"
8 environment:
9 - GRID_MAX_SESSION=16
10 - GRID_TIMEOUT=300
11 networks:
12 - selenium_net
13
14 chrome:
15 image: selenium/node-chrome:latest
16 environment:
17 - SE_EVENT_BUS_HOST=selenium-hub
18 - SE_EVENT_BUS_PUBLISH_PORT=4442
19 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
20 - SE_NODE_MAX_SESSIONS=4
21 depends_on:
22 - selenium-hub
23 networks:
24 - selenium_net
25 deploy:
26 replicas: 2
27
28 firefox:
29 image: selenium/node-firefox:latest
30 environment:
31 - SE_EVENT_BUS_HOST=selenium-hub
32 - SE_EVENT_BUS_PUBLISH_PORT=4442
33 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
34 - SE_NODE_MAX_SESSIONS=4
35 depends_on:
36 - selenium-hub
37 networks:
38 - selenium_net
39 deploy:
40 replicas: 2
41
42 edge:
43 image: selenium/node-edge:latest
44 environment:
45 - SE_EVENT_BUS_HOST=selenium-hub
46 - SE_EVENT_BUS_PUBLISH_PORT=4442
47 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
48 - SE_NODE_MAX_SESSIONS=4
49 depends_on:
50 - selenium-hub
51 networks:
52 - selenium_net
53
54 video:
55 image: selenium/video:latest
56 environment:
57 - DISPLAY_CONTAINER_NAME=chrome
58 - SE_VIDEO_FILE_NAME=auto
59 volumes:
60 - ./videos:/videos
61 depends_on:
62 - chrome
63 networks:
64 - selenium_net
65
66networks:
67 selenium_net:

.env Template

.env
1# Selenium Grid
2# Hub at http://localhost:4444
3# Grid console at http://localhost:4444/ui

Usage Notes

  1. 1Grid UI at http://localhost:4444/ui
  2. 2Connect tests to http://localhost:4444
  3. 3Chrome, Firefox, Edge nodes
  4. 4Video recording available
  5. 5Scale nodes as needed

Individual Services(5 services)

Copy individual services to mix and match with your existing compose files.

selenium-hub
selenium-hub:
  image: selenium/hub:latest
  ports:
    - "4442:4442"
    - "4443:4443"
    - "4444:4444"
  environment:
    - GRID_MAX_SESSION=16
    - GRID_TIMEOUT=300
  networks:
    - selenium_net
chrome
chrome:
  image: selenium/node-chrome:latest
  environment:
    - SE_EVENT_BUS_HOST=selenium-hub
    - SE_EVENT_BUS_PUBLISH_PORT=4442
    - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    - SE_NODE_MAX_SESSIONS=4
  depends_on:
    - selenium-hub
  networks:
    - selenium_net
  deploy:
    replicas: 2
firefox
firefox:
  image: selenium/node-firefox:latest
  environment:
    - SE_EVENT_BUS_HOST=selenium-hub
    - SE_EVENT_BUS_PUBLISH_PORT=4442
    - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    - SE_NODE_MAX_SESSIONS=4
  depends_on:
    - selenium-hub
  networks:
    - selenium_net
  deploy:
    replicas: 2
edge
edge:
  image: selenium/node-edge:latest
  environment:
    - SE_EVENT_BUS_HOST=selenium-hub
    - SE_EVENT_BUS_PUBLISH_PORT=4442
    - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    - SE_NODE_MAX_SESSIONS=4
  depends_on:
    - selenium-hub
  networks:
    - selenium_net
video
video:
  image: selenium/video:latest
  environment:
    - DISPLAY_CONTAINER_NAME=chrome
    - SE_VIDEO_FILE_NAME=auto
  volumes:
    - ./videos:/videos
  depends_on:
    - chrome
  networks:
    - selenium_net

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 selenium-hub:
5 image: selenium/hub:latest
6 ports:
7 - "4442:4442"
8 - "4443:4443"
9 - "4444:4444"
10 environment:
11 - GRID_MAX_SESSION=16
12 - GRID_TIMEOUT=300
13 networks:
14 - selenium_net
15
16 chrome:
17 image: selenium/node-chrome:latest
18 environment:
19 - SE_EVENT_BUS_HOST=selenium-hub
20 - SE_EVENT_BUS_PUBLISH_PORT=4442
21 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
22 - SE_NODE_MAX_SESSIONS=4
23 depends_on:
24 - selenium-hub
25 networks:
26 - selenium_net
27 deploy:
28 replicas: 2
29
30 firefox:
31 image: selenium/node-firefox:latest
32 environment:
33 - SE_EVENT_BUS_HOST=selenium-hub
34 - SE_EVENT_BUS_PUBLISH_PORT=4442
35 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
36 - SE_NODE_MAX_SESSIONS=4
37 depends_on:
38 - selenium-hub
39 networks:
40 - selenium_net
41 deploy:
42 replicas: 2
43
44 edge:
45 image: selenium/node-edge:latest
46 environment:
47 - SE_EVENT_BUS_HOST=selenium-hub
48 - SE_EVENT_BUS_PUBLISH_PORT=4442
49 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
50 - SE_NODE_MAX_SESSIONS=4
51 depends_on:
52 - selenium-hub
53 networks:
54 - selenium_net
55
56 video:
57 image: selenium/video:latest
58 environment:
59 - DISPLAY_CONTAINER_NAME=chrome
60 - SE_VIDEO_FILE_NAME=auto
61 volumes:
62 - ./videos:/videos
63 depends_on:
64 - chrome
65 networks:
66 - selenium_net
67
68networks:
69 selenium_net:
70EOF
71
72# 2. Create the .env file
73cat > .env << 'EOF'
74# Selenium Grid
75# Hub at http://localhost:4444
76# Grid console at http://localhost:4444/ui
77EOF
78
79# 3. Start the services
80docker compose up -d
81
82# 4. View logs
83docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/selenium-grid-complete/run | bash

Troubleshooting

  • Browser node shows 'Unable to connect to hub' error: Verify selenium-hub container is running and SE_EVENT_BUS_HOST environment variable matches service name
  • Tests fail with 'SessionNotCreatedException': Check node capacity by visiting grid UI at localhost:4444 and verify SE_NODE_MAX_SESSIONS settings
  • Video recording produces empty files: Ensure DISPLAY_CONTAINER_NAME matches actual browser container name and ./videos directory has write permissions
  • Grid timeout errors during long-running tests: Increase GRID_TIMEOUT environment variable beyond default 300 seconds
  • Chrome or Firefox nodes fail to start: Verify sufficient system memory and check Docker logs for browser initialization errors
  • Hub becomes unresponsive under load: Reduce GRID_MAX_SESSION value or increase Docker memory limits for selenium-hub container

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Components

selenium-hubchrome-nodefirefox-nodeedge-node

Tags

#selenium#testing#browser#automation#grid

Category

Development Tools
Ad Space