A Practical Guide to Dockerized Testing of Mobile and Web Apps

0
768

Research by Sumit Gerela

Suppose you have an idea for mobile or web app. Today, there are plenty of resources available to help you quickly build and deploy one. However, for maintenance and scalability, the next step is to consistently update and test the app. Building a test automation framework or
outsourcing it to cloud services such as Sauce Labs can be costly and time-consuming. Docker provides methodologies to DIY the automation and test environment which can be easily scaled as your app grows.

What is Docker?
Docker is a containerization platform. A container is an isolated environment for your app and it doesn’t rely on underlying operating system. When you set up a container, it will contain all the information including the OS required and associated app code to run in isolation. Containers are light weight and easily portable and ensure uniformity of development environment.

How de we automate testing of apps?
The most popular open source framework for writing automation is Selenium, with its mobile counter part Appium. They allow you to simulate real user flow by letting you write scripts for automating user interaction across the app. These scripts are executed on web browsers on
web app and/or native mobile apps. Selenium consists of a Selenium Grid, which comprises of a central Hub server which orchestrates execution of tests on Node servers based on defined capability needs. Appium runs app on native apps such as on Android by using ADB (Android
1 A Practical Guide to Dockerized Testing of Mobile and Web Apps Research by Sumit Gerela August 17, 2023 Debug Bridge) + UIAutomator, or on iOS by using XCUI Test framework. We can easily package these dependencies into a Docker container.

How do we use Docker for Testing?
Docker container will have all required dependencies including base OS, frameworks based on web or mobile app along with the actual automation scripts. This will be the
Docker image for running simple tests. Additionally we will have a Docker image for Selenium Hub and separate images for Node servers based on requirement. We will have a Docker compose YAML, which is a tool for defining and running multiple Docker containers. 

This will be used to spawn up or tear down the whole test infrastructure consisting of application under test and Selenium/ Appium Hub and Nodes.

How do we deploy and scale these Docker containers?
Once the developer pushes the code to a repository, we can use a continuous integration and delivery system such as Jenkins to build and deploy multiple docker containers using Docker compose. Selenium Hub container will
communicate with Node server containers to propagate automation requests. Auto-scaling capability can be added to this implementation to readily spin up or down the required number of nodes based on test load. We can further leverage multiple open source systems for tomating deployment, scaling, and management of containers such as Google’s Kubernetes, Amazon’s AWS, or opt for inhouse servers or cloud setup. I have successfully implemented this end-to-end strategy during my tenure as a Software Engineer, and it greatly reduced the time to build, deploy, and test apps.