Selenium WebDriver – Running Dockerizied Automated Tests using Portainer

Overview:

TestAutomationGuru has already released few articles on creating a docker image with your tests + all the dependencies and running them on a docker container as and when we want!

  1. Running Automated Tests Inside A Docker Container
  2. Running Multiple Test Suites using Docker Compose

In the above articles, even if we had automated the process of creating a docker image etc, we were still running/managing docker containers manually.  We could automate that using a shell script etc & manage the execution through Jenkins. It is a fair point!   But if you need to do a lot of docker stuff and you / your team members, are not comfortable with command-line, then you could use a GUI tool which abstracts these docker commands.

This article is going to explain one such GUI tool – Portainer – for docker. I am going to re-use some of the artifacts I had created as part of above articles. So, Please read above articles if you have not already!

Portainer:

Portainer is a simple tool with a nice GUI to manage docker containers, images, networks, volumes etc on a host! Portainer itself is running as a docker container (portainer image is only 10MB).

Run the below command once & you are set!

sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer

Now access the portainer dashboard using http://[ip address]/:9000

portainer-dashboard

Now you could use those tabs on the left navigation to manage docker containers, images, networks, volumes etc.

Lets see how we could use it to run our tests!

Docker Image:

I had created a docker image which contains our selenium tests as part of this article – Running Multiple Test Suites using Docker Compose

  • Image name: vinsdocker/containertest:demo
  • Input Parameters / Environment variables:
    • SELENIUM_HUB : hostname / ipaddress of selenium grid hub
    • BROWSER : chrome / firefox
    • MODULE : order-module.xml /  search-module.xml

 

It is basically a single image – based on the module name we pass as environment variable, it executes the different modules.

Container Setup:

  • Go to container tab in Portainer. [It will show all the running / stopped containers]
  • Click on ‘Add Container’
  • Based on the above docker image info, create 2 containers as shown here.
    • order-module
    • search-module

create-container-oder

  • Our test results will be stored inside the docker container ‘/test-output‘ directory – I use volume to map the container directory to our local ‘/home/qa/result’ directory on the host. Basically once the container is done with the test execution, all the results would be available in my ‘/home/qa/result‘ directory.

create-container-oder-volume

  • Click on ‘Create’ to start the container test execution.

create-container-oder-running

  • Portainer has nice GUI to check the container log, CPU/Memory utilization etc.  We could even attach ourselves with the running container & execute commands directly inside the container.

create-container-oder-stats

create-container-log

  • With Portainer, you could start these containers as when we want.

create-container-start

 

Summary:

Now all the team members do not need special access to the server to run the commands to manage containers – Instead with Portainer’s GUI, the team could manage docker containers and executes the test as and when it is required! No need to memorize all the docker commands!

 

Happy Testing & Subscribe 🙂

 

Share This:

Categories: Articles, CI / CD / DevOps, Docker, Selenium

2 comments

    • vIns

      Hi Das,
      In this sample project, I used testng framework which creates a HTML report which shows pass/fail status. Once container is done with the testing, it exits automatically. The results will be stored in the host machine under the directory we have mapped. in this example, I wanted to store the results in ‘/home/qa/results’ directory. All the testng results were stored there.

Leave a Reply

Your email address will not be published. Required fields are marked *