Table of Contents
1
Abstract
2
Introduction
3
Software and hardware Requirements
4
Steps to configure Selenium Grid using Docker
5
Benefits of using Docker with Selenium Grid
6
Case study
7
Conclusion
8
Contributors
Abstract
Abstract

- Benefits of using Docker for test automation
- Detailed instructions for setting up Docker on local or dedicated automation servers to improve scalability of automation infrastructure.
- Frequent challenges encountered and how to overcome them
- A case study where it was implemented, and the results achieved
- How Docker can be implemented with various cloud providers (AWS, Azure, GCP)?
- Parallel execution to share early feedback
- Cross-browser test coverage
- Easy maintenance of infrastructure
- Open-source tech stack for test automation
Introduction
Introduction

Software and hardware Requirements
Software and hardware Requirements

- Docker – Software for deploying docker containers and managing infrastructure.
- Servers – One or more servers based on the elasticity that is needed for infrastructure.
- All the software that is used for selenium automation like IDE for coding and programming language libraries like Java/Python etc.
- Jenkins for continuous integration.
- Git for source control.
- Automation Framework, which is developed to support selenium grid executions.
Selenium Grid
Selenium Grid is a hub-nodes architecture proxy server. The server will act as the Hub. It facilitates parallel execution of test scripts where one can configure different OS or browsers. Those are called nodes. Tests contact the hub to obtain access to remote browser instances. The Hub takes the requests from test scripts and then sends them to nodes based on the browser configuration.
The below image shows how selenium works:
Below image shows how the selenium grid works:
For deploying a selenium grid, Docker needs to be pre-installed on a server. There are multiple ways to deploy based on the requirement. For example, if only one server is used and smaller number of test cases need to run in parallel, the entire selenium grid can be deployed in one server.
If the requirement is to run multiple tests in parallel and there is a need for scalable selenium grid infrastructure, one can distribute docker containers across multiple servers. At the moment the docker swarm is being used by us to maintain the grid setup.
Steps to configure Selenium Grid using Docker
Steps to configure Selenium Grid using Docker

$ Docker pull selenium/hub
2 . Run the below command to pull the node container that would have a Chrome browser$ Docker pull selenium/node-chrome
3 . Run the below command to pull the node container that would have a Firefox browser$ Docker pull selenium/node-firefox
$ docker images
1.1 On Local Machine
The entire selenium grid infrastructure can be deployed in a single machine. This can be done by using the docker swarm and the above docker-compose file. Here a single machine will act as both manager and node. Below are the steps for the setup.1 . First, one needs to initialize the docker swarm by using the below command. This command will initialize the docker swarm, and a selenium gid can be deployed into the swarm.docker swarm init
Now the stack needs to be deployed by using the below command. In the below command, one needs to specify the path of compose file and the name they want to give to the stack.docker stack deploy –compose-file=docker-compose.yml selenium
3 . Now they can verify if the stack is deployed or not by using the below command. This will display all deployed services. In this case, selenium hub and selenium chrome nodes. It will display the count of replicas of a particular service.docker service ls
1.2 On Multiple Servers
If the need is to deploy selenium grid across multiple servers, multiple servers can be used as managers and nodes. Below are the steps to configure it in multiple servers.1 . First, teams need to go to the manager node they want to use as a manager and run the below command. When this command is executed, a command is generated that starts with Docker join as an output.docker swarm init
2 . Copy docker joins command from the output of the above command and runs it in node servers. Now all the nodes will be part of the docker swarm. Status and nodes connected to the manager can be verified by using the command below in the manager node.docker node ls
The stack can be deployed by using the below command. In the below command, the path of compose file and the name of the stack need to be specified.docker stack deploy –compose-file=docker-compose.yml selenium
3 . This will distribute all the replicas across multiple nodes instead of having them in only one server. The size of the selenium grid can be increased by just modifying the replicas count in compose file.Step3 : After deploying the selenium grid, the grid can be verified by opening the below URL in the browser. http://docker stack rm selenium
Benefits of using Docker with Selenium Grid
Benefits of using Docker with Selenium Grid

- Easily scalable automation infrastructure.
- Reduced cost for resources like servers, multiple VMs etc.
- Easy to deploy in multiple servers.
- There entire infra can be made open source and c Windows/Linux servers can be used.
Case study
Case study

Conclusion
Conclusion
To scale up test execution of Selenium scripts, Docker is very handy, easy to use, and cost-free.
Contributors

Geetha Pavani Achutuni
Senior Manager, Project Delivery

Sai Pawan Lingutla
Senior Software Engineer, Project Delivery