
Selenium webdriver is a tool that is pretty flexible and powerful and enables us to run functional tests on web applications which saves us a lot of time.
To brush up on the previous discussions let’s recall that selenium is an open source tool that automates web browsers and web applications and it runs across multiple browsers and OS while also supporting various programming language.
Traditional Selenium Grid
Some of the benefits grid brings to us are:
- Free and Portable
- Flexible and accessible as it supports many languages
- Supports many browser types and various platforms
- Aids continuous integration
Although selenium brings many benefits to the table, it does have certain limitations too. Few limitations of selenium grid:
- Downloading and setting up all the dependencies for each node.
- Java processes will eventually run out-of-memory.
- Manually restarting the nodes in case of issues.
- Maintenance is expensive.
- Scalability issues.
Reasons to use selenium with Docker
- Capacity to scale
- Runs tests locally
- Easy to start docker with Selenium
- Very helpful in case of crash
- More secure
- Resource Usage
Apart from the above mentioned points there are few more benefits that make selenium dockers partnership even more promising for example:
- Since, the entire selenium hub configuration happens within container, we don’t have to manage any dependencies around selenium server jars separately.
- There is no need to download browser drivers and set classpath as that too is automatically done within container.
- Since, everything is bound within the docker container, this makes it environment and platform independent hence making it readily available and useable for other teams.
- A temporary or transient grid can be set up with the help of Dockers which makes setting up and even disposing of grid all the more convenient post test execution.
How to Configure Selenium using Docker?
Setting up docker on server machine
Steps to install docker depend on the operation system being used. This can be done with the help of https://docs.docker.com/install/. We have to make sure that the user is added to the ‘docker’ user group.
Fetching images from docker hub
After installing docker we need to download following images from docker hub
- docker pull selenium/hub — For Image for selenium Grid Hub
- docker pull selenium/node-chrome-debug — VNC enabled Chrome browser
- docker pull selenium/node-firefox-debug — VNC enabled Firefox browser
For specific versions pull images by mentioning version as
docker pull selenium/node-chrome-debug:3.141.59
Versions can be found at https://hub.docker.com
Creating Selenium Grid and Configuring Nodes
First, we need docker network so that hub and nodes are in same network and can communicate with each other using their container names.
- docker network create grid
- docker run -d -p 4444:4444 -net grid -name selenium-hub selenium/hub
- docker run -d -net grid -e HUB_HOST=selenium-hub selenium/node-chrome-debug
- docker run -d -net grid -e HUB_HOST=selenium-hub selenium/node-firefox-debug
Making sure the grid is up and running
Here, at this juncture we need to make sure out set up is in place and need to see if our grid is up and running. To check that, navigate to http://localhost:4444/grid/console, and we should see a grid with two configured nodes, one chrome and one firefox.

Increase the browser instances
In order to increase the browser instances we need to run the node configuration command from step 3 to configure the nodes with these additional parameters -e NODE_MAX_INSTANCES=5 -e NODE_MAX_SESSION=5. This will configure 5 instances of Chrome and 5 Instances of Firefox.

Configuring multiple nodes
To configure multiple nodes we execute the command mentioned in step 3 multiple times. It will spin up multiple Chrome and Firefox containers.

Running Tests on Grid
Now that the selenium grid is configured, running tests on the grid is simply configuring the code to point selenium webdriver to http://localhost:4444/wd/hub and passing the browser configuration using capabilities.
So far so good! However there is no doubt that this process is tedious and time consuming with constant manual intervention hence we ought to be looking for something a little more convenient.
Hence folks, in next content is going to revolve around a simpler and scalable approach using docker-compose.
Originally published at https://www.qekafe.com on November 4, 2019.
