- 1 year ago
Setting up multiple machines to be in selenium grid using Docker compose
Setting up a Selenium Grid with multiple machines using Docker Compose involves creating Docker containers for each Selenium node and hub. Docker Compose simplifies the process by allowing you to define and manage multiple containers in a single configuration file. Here's how you can set up a Selenium Grid with Docker Compose:
Install Docker and Docker Compose:
Ensure you have Docker and Docker Compose installed on your machine.Create a Docker Compose Configuration File:
Create a file nameddocker-compose.yml
in your project directory. This file will define your Selenium Grid setup.Configure Selenium Hub:
Define a service for the Selenium Hub. You can use the official Selenium Hub image from Docker Hub.yamlversion: "3"
services:
hub:
image: selenium/hub:3.141.59
ports:
- "4444:4444"
Configure Selenium Nodes:
Define services for each Selenium node. You can configure multiple nodes by replicating the node service definition.yamlversion: "3"
services:
hub:
image: selenium/hub:3.141.59
ports:
- "4444:4444"
node-chrome:
image: selenium/node-chrome:3.141.59
environment:
- HUB_HOST=hub
depends_on:
- hub
node-firefox:
image: selenium/node-firefox:3.141.59
environment:
- HUB_HOST=hub
depends_on:
- hub
In this example, two node services (
node-chrome
andnode-firefox
) are configured to connect to the Selenium Hub.Run Docker Compose:
Open a terminal/command prompt and navigate to the directory containing thedocker-compose.yml
file. Run the following command to start the Selenium Grid:shdocker-compose up
Docker Compose will start the Selenium Hub and the specified nodes.
Access Selenium Grid Console:
Open a web browser and navigate tohttp://localhost:4444/grid/console
. You should see the Selenium Grid console where you can monitor the connected nodes and perform tests.Run Selenium Tests:
You can now use your preferred test framework (e.g., WebDriver for Java, Python, etc.) to connect to the Selenium Grid and run tests on different browsers and nodes.
Remember that you can customize the Docker Compose configuration based on your requirements, such as specifying node capabilities, scaling the number of nodes, and using different browser versions.
After you're done with testing, you can stop the Selenium Grid by running:
shdocker-compose down
This is a basic setup, and there are more advanced configurations you can explore, such as scaling nodes, using Docker networks, and setting node capabilities.