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 up you 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 - docker-compose up
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_INSTANCES
andNODE_MAX_SESSION
to the Docker services
-
Dynamically increasing the nodes: using Docker scale command, you can also dynamically add more nodes -
docker-compose up --scale firefox=3
this will total 3 nodes for Firefox
Conclusion
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 docker-compose up
Check out the video below to learn more about how to setup Selenium Grid with Docker Compose –
📧 Subscribe to my mailing list to get access to more content like this as well as free access to a Private Facebook community
👍 You can follow my content here as well -
...
I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -
You can also support me by liking and sharing this content.
Top comments (0)