Tech Corner

How to use Docker for Automation Testing?

Engati Team
.
last edited on
.
September 5, 2023
4-5 mins

Table of contents

Automate your business at $5/day with Engati

REQUEST A DEMO
Try Engati for WhatsApp Marketing: Meta's Tech Partner of the year 2024
Book a Demo
Automation Testing

We've talked about the importance of software testing earlier but how do we implement this? Our preferred method is by using Docker. Learn how to test softwares with virtual environments in this blog.

What is Docker?

Docker is a Platform as a Service that provides OS-level virtualization. It makes it easy to create, deploy, and run applications using containers. Containers act as a freshly installed OS, each with its own software, libraries, and configurations.

They communicate with each other through well-defined channels. Docker helps with the creation of these containers over your own Operating System. While “Docker Engine” software hosts the containers.

What are images and containers in docker?

In Docker, everything is based on images. Images are lightweight, standalone, executable packages of software that are equipped with everything needed to run an application. 

A container, on the other hand, are runtime instances of the image, i.e container images become containers at runtime.

How to install Docker?

  • Go on Docker Docs
  • Check if your system supports Docker by going through the hardware prerequisites.

Docker Desktop for Mac
Installing Docker for Mac

  • Download and install Docker
  • Once installed you will see the icon on your system, click on the icon and it will appear in your task manager.
  • Initial status will be Docker Desktop is starting and eventually it will turn to Docker Desktop Running.
  • To confirm, run $docker --version in command prompt.

Exploring DockerHub

DockerHub is a service provided by Docker for finding and sharing container images with your team. You can sign up for it here.

It provides the following major features:

  • RepositoriesRepositories push and pull container images.
  • Teams and OrganizationsThis feature allows you to manage access to private repositories of container images.
  • Official ImagesOfficial images pulls and uses high-quality container images provided by Docker.
  • Publisher ImagesPublisher images pulls and uses high- quality container images provided by external vendors.
  • BuildsAutomatically build container images from GitHub and Bitbucket and push them to Docker Hub with Builds.
  • WebhooksTrigger actions after a successful push to a repository to integrate DockerHub with other services using Webhooks.

Dockerhub Signup
Dockerhub Signup


Setting up Docker Container for automation tests

1

Getting Selenium images

Selenium, to make our jobs easier, has already put all selenium-related images on Docker Hub. We can directly pull the images from Dockerhub and use those in our machines.

2

Download image into our machine

Here are some important commands to keep in mind.

To check if you already have any containers running

$docker ps

To pull an image

$docker pull <image name=""></image>

Example:

docker pull selenium/standalone-chrome

To list out the images

$docker images

Downloading image into Docker
Downloading images into Docker


3

Deploy image to the container

$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest

Explanation

  • docker run:Starts a new container in machine
  • -d:Runs the container in background
  • -p 4444:4444:Running port for test cases in local : container portEssentially, it redirects all the test case runs to the container
  • -v /dev/shm:/dev/shm:To use hosts shared memory
  • selenium/standalone-chrome:Image name
  • latest:Image version

Deploy image on container
Deploy image on container


We can use similar steps to create containers for other browsers as well.

Tip for you:Remember that only one container can run on a port at one time



4

Stop the container

$docker stop <container id=""></container>

Docker + Selenium (testNG)

In order to run test cases remotely, we need to import the RemoteWebdriver class. This class takes the URL of 2 arguments (port in which test case will be running) and desired capabilities (browser).

This is a simple test case which will run in the container we created above.

Test case run in container
Test case run in container


Docker + Selenium Grid

Selenium grid is a tool that helps to run our test cases in different operating systems and on different browsers.

It follows Hub and node architecture as shown in image below. There is a common Hub to which all the nodes are connected. The main disadvantage of this is that we need many Virtual Machines for this.

By using docker with Selenium Grid , instead of VM’s we will use containers and all the nodes will be on the same OS.

Selenium Grid with and without Docker
Selenium Grid with and without Docker


How to create a hub and node -- Docker compose file?

We can directly create nodes and hubs required using a single file called the “Docker compose file,” which is saved under the .yaml extension.

You have to deploy selenium/hub as the image in the container to create a hub in this file.

Then we have 2 nodes for each browser in our example- one for chrome and the other for Firefox. They both are connected to the hub using depends_on.

Create a hub and node
Create a hub and node


Save this file on your system and go to the path on cmd and run the given command:

$docker-compose -f <file_name> up</file_name>

To validate that the nodes are up and running, go to the url given under Nodes should register to in the above image after we run the docker compose file.


validate nodes
Validate nodes

Grid console
Grid console


Now, if you wish to run 3 test cases on chrome but there is a single chrome node we can run the command below to scale up the nodes and make it to 5 nodes.

$docker-compose scale=5

Now, all the test cases will run on different nodes at the same time hence saving time of Execution.

Grid Console
Revisiting Grid Console

Docker Chrome Testing
Docker Chrome Testing

Do more with Docker x Selenium

This fusion of Docker with selenium can help automation testers in a couple of ways. You can use Docker to:

  • Run test cases on your systems if you don’t have the architecture you need
  • Run automation test cases in parallel on various browsers
  • Eliminate the need to manage jars and downloading
  • Run tests at a scale due to its ease and flexibility

With Engati, you can serve and support your customers in the way they want to be served via live chat and chatbot, over 14 chat platforms. Get started for free today!

Engati Team

At the forefront for digital customer experience, Engati helps you reimagine the customer journey through engagement-first solutions, spanning automation and live chat.

Close Icon
Request a Demo!
Get started on Engati with the help of a personalised demo.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
*only for sharing demo link on WhatsApp
Thanks for the information.
We will be shortly getting in touch with you.
Oops! something went wrong!
For any query reach out to us on contact@engati.com
Close Icon
Congratulations! Your demo is recorded.

Select an option on how Engati can help you.

I am looking for a conversational AI engagement solution for the web and other channels.

I would like for a conversational AI engagement solution for WhatsApp as the primary channel

I am an e-commerce store with Shopify. I am looking for a conversational AI engagement solution for my business

I am looking to partner with Engati to build conversational AI solutions for other businesses

continue
Finish
Close Icon
You're a step away from building your Al chatbot

How many customers do you expect to engage in a month?

Less Than 2000

2000-5000

More than 5000

Finish
Close Icon
Thanks for the information.

We will be shortly getting in touch with you.

Close Icon

Contact Us

Please fill in your details and we will contact you shortly.

This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
Thanks for the information.
We will be shortly getting in touch with you.
Oops! Looks like there is a problem.
Never mind, drop us a mail at contact@engati.com