In the last lesson I explained the standard setup but you can also advance this with a more advanced and distributed Selenium Grid 4 setup using Docker Compose, including components like Selenium Router, Distributor, Session Map, and Event Bus, alongside Nodes, you’ll utilize Docker Compose to define and run these services. This setup provides better scalability and management for large-scale and distributed testing environments.

Here’s how you can configure it:

Docker Compose Setup for Selenium Grid 4

The advanced setup of Selenium Grid 4 with Docker involves multiple components. Each plays a specific role in managing sessions, routing commands, and distributing tasks.

Create a docker-compose.yml File:

Create this file in your project directory. This file will define the Selenium Grid services including the Hub (composed of the Router, Distributor, Session Map, and Event Bus) and Nodes. For a more advanced and distributed Selenium Grid 4 setup using Docker Compose, including components like Selenium Router, Distributor, Session Map, and Event Bus, alongside Nodes, you’ll utilize Docker Compose to define and run these services. This setup provides better scalability and management for large-scale and distributed testing environments. Here’s how you can configure it:

Docker Compose Setup for Selenium Grid 4

The advanced setup of Selenium Grid 4 with Docker involves multiple components. Each plays a specific role in managing sessions, routing commands, and distributing tasks.

Create a docker-compose.yml File:

Create this file in your project directory. This file will define the Selenium Grid services including the Hub (composed of the Router, Distributor, Session Map, and Event Bus) and Nodes.

version: '3.7'
services:
 selenium-event-bus:
 image: selenium/event-bus:4.0.0
 container_name: selenium-event-bus
 ports:
 - "4442:4442"
 - "4443:4443"

 selenium-router:
 image: selenium/router:4.0.0
 container_name: selenium-router
 depends_on:
 - selenium-event-bus
 ports:
 - "4444:4444"
 environment:
 SE_EVENT_BUS_HOST: selenium-event-bus
 SE_EVENT_BUS_PUBLISH_PORT: 4442
 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

 selenium-distributor:
 image: selenium/distributor:4.0.0
 container_name: selenium-distributor
 depends_on:
 - selenium-event-bus
 environment:
 SE_EVENT_BUS_HOST: selenium-event-bus
 SE_EVENT_BUS_PUBLISH_PORT: 4442
 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

 selenium-session-map:
 image: selenium/session-map:4.0.0
 container_name: selenium-session-map
 depends_on:
 - selenium-event-bus
 environment:
 SE_EVENT_BUS_HOST: selenium-event-bus
 SE_EVENT_BUS_PUBLISH_PORT: 4442
 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

 selenium-node-chrome:
 image: selenium/node-chrome:4.0.0
 depends_on:
 - selenium-event-bus
 volumes:
 - /dev/shm:/dev/shm
 environment:
 SE_EVENT_BUS_HOST: selenium-event-bus
 SE_EVENT_BUS_PUBLISH_PORT: 4442
 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

 selenium-node-firefox:
 image: selenium/node-firefox:4.0.0
 depends_on:
 - selenium-event-bus
 volumes:
 - /dev/shm:/dev/shm
 environment:
 SE_EVENT_BUS_HOST: selenium-event-bus
 SE_EVENT_BUS_PUBLISH_PORT: 4442
 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

Running Your Grid:

docker-compose up -d

This command will download the necessary Docker images (if not already present) and start the services defined in your Docker Compose file.

Video Recording in a Distributed Docker Setup

For video recording in this distributed setup, you have two primary options:

  1. Use Debug Images: Selenium provides -debug versions of browser node images that include VNC support (e.g., selenium/node-chrome-debug). These allow for live monitoring of tests but don’t directly record videos. For actual video recording, proceed to the next option.
  2. Integrate with a Recording Solution: Implement a custom solution or integrate an existing one. One approach is to extend the node Docker images to include ffmpeg and scripts that start/stop video recording around your tests. Another approach is to use a tool like Zalenium, which supports video recording out of the box, but note its compatibility with the latest Selenium versions and Docker setups. Remember, adding video recording increases the complexity of your setup. You’ll need to manage the recording lifecycle and ensure videos are stored where they can be easily accessed, potentially integrating with cloud storage solutions or shared volumes in Docker.

Conclusion

This advanced setup with Docker Compose for Selenium Grid 4 leverages the full suite of Grid 4 components for a scalable and distributed testing infrastructure. Video recording capabilities can be integrated, enhancing the ability to debug and review tests, albeit with additional setup and resource considerations.