In this tutorial, we will cover how to set up Selenium Grid with Docker Compose. We will talk about why we need Docker Compose and look into how to implement a Docker Compose file. We will also cover how to set up parallel execution with Docker Compose & Selenium Grid.
Why use Docker Compose?
- No need to remember Docker commands: With Docker compose, you don’t need to remember all different types of docker commands which we covered in our previous post
- Run multiple containers together: Docker compose allow you to run multiple containers together as a service instead of spinning up each one-by-one
- Spin up Grid with multiple browsers using a single command: With just one command
docker-compose upyou can spin up Selenium Grid with multiple browsers integrated with it
Docker Compose makes it really easy for anyone to get started with Docker, even if they are not familiar with how Docker works.
Setting up Docker Compose file
To set up Selenium Grid, we will use the Docker Compose file provided in the Selenium GitHub repository —
This command is equivalent to the Docker network command we used in the previous post. It will spin up a Selenium Hub on port 4444 and will have Chrome and Firefox instances set up as well.
Run Docker Compose file
To run the Docker Compose file, simply run the following command on the terminal —
There you go, you just spun Selenium Grid with Chrome and Firefox with just one single command. That’s the magic of using Docker Compose.
Setup Parallel Execution with Docker Compose
There are 2 ways to set up parallel execution for Selenium Grid using Docker Compose –
- Updating Docker Compose file: Add
NODE_MAX_SESSIONto the Docker services
- Dynamically increasing the nodes: using Docker scale command, you can also dynamically add more nodes —
docker-compose up --scale firefox=3this will total 3 nodes for Firefox
Docker Compose is a great way to run Selenium Grid locally. This will allow anyone in your team to spin up a grid and start running tests on any specified browser by just using a single command
Check out the video below to learn more about how to setup Selenium Grid with Docker Compose –
Thanks for reading.