Selenium WebDriver – How To Run Multiple Test Suites Using Docker Compose – Part 2

Overview:

The modern cloud infrastructure, continuous integration & deployment processes etc have completely changed the way how applications are deployed in production nowadays. In order to release new features faster in Production, you need to reduce time we take in the each phase of the SDLC. As an automation lead/architect, It could be your responsibility to have a proper infrastructure to speed up the automated test execution! When it comes to infrastructure automation, Docker plays a major role there!

Testautomationguru already hasfew docker and selenium related articles which talks about setting up the dockerized selenium grid & running a docker container with a test.

Before continuing this article, I would request you to read the above 2 first! I am explaining few things here assuming that you have already read them.

This article is going to explain how to combine above 2 articles – ie running all regression testcases with multiple test suites & selenium grid with a single docker-compose file.

Test Suites:

We have thousands of automated tests for my application. I categorize / group them, based on the application business functionality / module and create multiple test suites. So that any change in specific module can trigger corresponding test suites.

Lets assume – in our sample application for this article, we have 3 modules.

Registration Module

Search Module

Order Module

Lets also assume that, each module has hundreds of automated test cases already. In order to get my automated results as early as possible, We need to have multiple hosts + Selenium Grid set up as shown here to run the entire regression test suites!!

Setting up all the above machines with all the dependencies is a nightmare!

Lets see how we could set up the above entire infrastructure in a single compose file and execute the tests!!

Sample Project:

For the demo, I have created a simple project as shown here. This sample project is available in Github.

Page Objects:

Above project has 2 page objects

SearchPage – acts as a page object for the search module (this is actually a page object for google search).

OrderPage – acts as a page object for order module (this is actually a page object for demoqa site).

Test Classes:

BaseTest – a base test which contains the logic for driver instantiation.

In order to do the complete regression testing for the application, Lets assume that we need to invoke the tests for both modules as given below.

order module testing on chrome

search module testing on firefox

Dockerfile:

I create the below Dockerfile which creates an image which contains all the dependencies to the run the test including the testNG suite files. [I have already explained this here– Please read the article if you have not already]

Now the very complex selenium grid + hosts to run the java tests became very simple which you could define it in a text file. A single command creates the infrastructure in a second on a single host (you can also do that in multiple hosts) and disposes once everything is complete!

GitHub:

Summary:

Docker compose made our life very easier! With a single command, we create Virtual Machines (containers are light weight VMs) with required browsers, tests and executes the test. Again with another command, we bring the entire infrastructure down!!

No more environment specific issues like ‘the test is not working in the machine’ 🙂

By implementing docker in your project, you become 100% awesome as Barney!!

Happy Testing & Subscribe 🙂

Share This:

6 comments

First of all thank you very much for the article. It is very helpful.
I was trying to run your github code with small modifications to it. I was able to successfully run mvn test and also successfully get image, The problem appeared when I tried running the image created.
I am constantly getting configuration failures.

Hi Vinoth,
Really useful article… Thanks for writing these…
May I know where you are passing the chrome driver executable file here …? how the chrome instance configured with the hub will be invoked as it must definitely need to have the executable file ….
also will you be able to visually see the browser automation when the tests are happening in the container..

When you do mvn clean package….mvn is executing your tests already and it creates the test jar for you…. and later when mvn runs the docker plugin it utilizes the test jar and making an image… the image can be run on any machine where docker is installed…
So for the first time , is your tests is not done on docker…?
or is it also done on docker… in that case the tests will be happening two times as mvn already executed the tests in its test phase… pls clarrify….