SDET Unicorns

Selenium Grid with Docker Compose

Table of Content

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  — 

1*4nN3gCg3MDW1DTpeElLm Q
Selenium Grid Docker Compose file

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

1*7H1N3LG6NtIOfv8wpF6fwQ

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 and NODE_MAX_SESSION to the Docker services 
1*gRM1Gqom3IJbieSrIBN1YQ
NODE_MAX_INSTANCES & NODE_MAX_SESSION
  • 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
1*C334

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 –

Thanks for reading.

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

Functional vs Regression Testing

Functional Testing vs Regression Testing: Main Differences

Testing has increasingly become a requirement in the software development lifecycle in recent years. The realization that development is no longer a focal point for stakeholders but saving costs by catching defects early in their application makes it necessary to learn different testing types.

Read More »