Containerized Automated Tests using Google Cloud Platform

Continuous Testing in a serverless setup using Cloud Build, Container Registry and Cloud Storage

In this article, we will talk about how one can easily containerize and run automated test cases as part of CI — CD using Google Cloud Platform ‍🚀

I won’t discuss too much on why we should containerize our automated tests. That’s a topic which I have covered extensively in one of my previous articles. You can read it here.

Here we will directly dig deep into the Google Cloud services that we can use and see how we can effectively use them.

What we need :

  1. Google Cloud Source Repository — This is the version control system where you can check in your test automation code. [Details]
  2. Google Cloud Build — This is a serverless CI/CD platform used for building/testing the code. [Details]
  3. Google Container Registry — This is where we store, manage and deploy containers. [Details]
  4. Google Cloud Storage — This is where we store data and artifacts. [Details]
  5. Google Kubernetes Engine — This is a secure and managed Kubernetes service. [Details].

Using Google Kubernetes Engine service we will deploy Selenium Grid, in our case Zalenium. I have explained a detailed step by step procedure in a separate article which you can read from here :

The workflow to be discussed is as follows :

Step 1 : Create your automated tests and push the code to Google Cloud Source Repositories

Log on to GCP console → Search for Source Repositories → Click on [Add repository] → Fill details → Click [Create]

Steps to create Google Cloud Source Repository

Install Google Cloud SDK on your local machine to access Google Services using command line

To push your code to Source Repository, use regular git commands :

git add .
git commit -m "Your_Commit_Message"
git push

Your file structure should tentatively have these 3 important files, however you can make modifications according to your needs :

(root directory name)
|-- cloudbuild.yml
|-- Dockerfile
|-- docker-compose.yml

We will deal with the details of the cloudbuild.yml in Step 4 and docker-compose.yml in Step 5.

Step 2: Create a Bucket in Google Cloud Storage for storing build artifacts (Test Execution Reports)

Go to GCP console → Search for Cloud Storage→ Click on [ Create bucket] → Fill details → Click [ Create]

Steps to create Google Cloud Storage Bucket

Step 3: Create a Google Container Registry for storing the automated test images

Go to GCP console→ Search for Container Registry→ Click on [Create repository] → Fill details → Click [ Create]

Container Registry : testautomation is created

Step 4: Set up a Google Cloud Build for building docker image for automated test and push it to Container Registry.

Before setting up the Cloud Build, we should take a step back and look at the cloudbuild.yml, I briefly mentioned above. The Cloud Build requires a yaml file which should contain the details of the activities that are expected to be performed during the ‘build’ process. Our cloudbuild.yml should look somewhat like this :

steps:# Build a docker image
- name: ''
args: [ 'build', '-t', '$PROJECT_ID/testautomation', '--cache-from', '$PROJECT_ID/testautomation', '.' ]
# Push the docker image to container registry
- name: ''
args: ['push', '$PROJECT_ID/testautomation']
# Execute the tests by invoking docker compose
- name: 'docker/compose:1.15.0'
args: ['run', 'automation']
# Store the Test Results in cloud storage
location: 'gs://testautomationbuildartifacts/ExecutionResults'
paths: ['Results/Latest/*.txt','Results/Latest/summary.html']
- '$PROJECT_ID/testautomation'

As obvious from the cloudbuild.yml above, there are 4 important activities that we are performing :

  1. In 1st Step, we are building the test automation image and tagging it
  2. In 2nd Step, we are pushing the image to GCR
  3. In 3rd Step, we are executing the tests by invoking docker compose
  4. In 4th Step, we are publishing the test results and pushing them to Cloud Storage

If we observe carefully in the cloudbuild.yml, we are using some environment variables like ${_PROJ}, ${_RELEASE} etc. We will define these variables shortly.

So lets go ahead and create the Cloud Build.

Go to GCP console → Search for Cloud Build→ Click on [Triggers] → Click on [CREATE TRIGGER] → Fill details (Some important configurations are listed below)→ Click [CREATE] → To run the trigger, click [Run]

  1. Trigger Name and Description
  2. Event : Push to a branch
  3. Source
    Repository : Name of the Cloud Source Repository
    Branch : master (or the name of the branch where your latest code is)

4. Build Configuration : Specify the yaml configuration file

5. Add Variables : Define the environment variables here

Environment Variables and their corresponding values

Please note, the Selenium GRID URL details can be obtained by following the steps mentioned in this article.

If everything goes well, your Cloud Build will succeed and you will be able to see the following:

Outcomes of the build stage

Furthermore, to view the execution logs of the tests you can navigate to the execution details of the build :

To view the test execution videos, you can navigate to the Zalenium Dashboard which, as referred earlier, can be set up following this article.


You have successfully set up a complete end to end containerized automated test execution using Google Cloud Services.

Happy testing!😊

Checkout the following GitHub link to view the code and the files used in the above setup:

Test Automation Consultant @Cognizant. Tech enthusiast. Innovation champion.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store