Selenium dockerization, and integration in CI

Hamid Mahmood
Sep 16 · 4 min read

Selenium is a well known and widely used open source framework which provides the power of browser automation. It can serve any purpose as far as browser automation is concerned, but it is mainly and very effectively been used in testing domain for test automation purposes.

Problem Statement:

Problem arises when you think of running your tests in distributed environment, which means you want to distribute your tests on several machines in parallel i.e. on different browsers / OS.

Which leads to the question; does Selenium itself supports running tests in distributed environment? Yes, it does with the help of Selenium-Grid.

Other part of the problem is; to prepare infrastructure to be able to run tests in distributed environment. For that sake, a number of (physical / virtual) machines with different OS and browsers are needed.

There are generally two approaches, as far as infrastructure for distributed environment is concerned; either you create your own distributed environment or use one of commercial solutions.

Let’s say creating own distributed environment is the option for now, which requires having several (physical / virtual) machines with different OS and browsers.

Apart from the (hardware, software & operational) cost itself, It’s a cumbersome job to prepare and maintain that sort of infrastructure.


Docker solves the problem, by making it possible to prepare the scaleable distributed environment on the go using containers, without even thinking about the hardware part of it.

Proof Of Concept:

Let’s try to prepare selenium-grid environment using docker containers, and run some UI tests on Storytel web using it, by following step-by-step approach.

Step 1: Prepare selenium-grid environment;

  • Install docker on machine on which test scripts are going to run.
  • Create a docker-compose file, and configure it to have a selenium-hub and two selenium-nodes, one with Chrome and one with Firefox.
  • Create and run selenium-grid using docker-compose.
Run selenium-grid
See if grid is up and running

Step 2: Prepare selenium test scripts;

Selenium has binding in different languages (Java, C#, Ruby, Python, Javascript) for its client drivers. Let’s consider Java as an option here.

  • Create a maven project and add following dependencies in pom file.

Step 3: Hook up everything in Jenkins CI;

  • Create a Jenkins job and configure it with your code repo.
  • Add a Build Step to start selenium-grid and run test scripts.
Build Step: Start grid and run project
  • Add a Post Build Task to stop and vanish selenium-grid.
Post Build Task: Shut down grid
  • Add another Post Build Task to generate allure report.
Post Build Task: Allure Report
  • See test results for builds. Following are some screenshots of test results.
Test Suites and Scenarios

Potential Improvements:

  • Scale the grid with more OS and browsers.
  • Add screenshots / videos in test reports (at least for failures)
  • Kubernetes the tests, automation with docker on GCP.

Thanks to David Božjak

Hamid Mahmood

Written by

Test Engineer | QA & Automation

Storytel Tech

Storytel Tech Blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade