Distribute your API automated test reports using Azure Blob Storage

Alee
Alee
Apr 20 · 4 min read
Image for post
Image for post
Remember: Sharing is caring

This is a basic example of uploading a newman HTML report to Azure Blob storage. It might help you if you are running your API tests programmatically and would like to share the report within your organisation.

I assume you already have:

  • An Azure account
  • Sufficient privileges in your organization to read/update an Azure Blob Storage
  • Basic knowledge of Postman and newman to run your API tests

Azure Credentials

When an application makes a request to Azure Storage, it must be authorized. To authorize a request, add your storage account credentials to the application as a connection string. View your storage account credentials by following these steps:

  1. Sign in to the Azure portal.
  2. Locate your storage account.
  3. In the Settings section of the storage account overview, select Access keys. Here, you can view your account access keys and the complete connection string for each key.
  4. Find the Connection string value under key1, and click the Copy button to copy the connection string. You will add the connection string to the environment file in future steps.
Image for post
Image for post
Storage account in Azure Portal

Change the container access level

The goal is that everyone from your team could view the reports. Whether it is sent by email, Slack message or other messaging system. This is the reason why we should make the uploaded report publicly accessible. Follow these steps to achieve this:

  1. Go to the storage account you accessed earlier in Azure Portal
  2. In the Blob service section of the storage account overview, select Containers
  3. Select the container to host your reports
  4. Click on Change access level button
  5. Choose Blob
How to change container access level

Run tests and upload report

Clone the code from the following repository : https://github.com/wmedali/upload-newman-report-to-azure-storage

At the root directory of your repository :

  • Run npm installin the terminal
  • Create an .env file and add your azure connection string in the following format: CONNECTION_STRING=THE_CONNECTION_STRING_YOU_COPIED

In the script.js file, change the CONTAINER_NAME variable value with your actual container name.

For this example, I am using the Postman Echo collection. It is a public Postman collection that includes multiple tests.

I have created a publicly accessible link of the collection in my workspace. This link could be changed in the future, so I strongly advise one of the following options to go further:

  1. Export a collection in JSON to save the collection file in your local disk.
  2. Generate a link to get a public accessible link for your collection.
  3. Use the Postman API to get a secured link for your collection.

Then update the collection value in the code below with the path/url of your collection:

Sample code of the executing the collection and uploading the test report

In your terminal run the following command:

npm start

This will run the collection and generate an HTML report using the html-extra package. It is a custom newman reporter to generate beautiful API test reports.

Once the execution finishes, an HTML report file will be created in the local disk. I preferred to delete the file after the upload successfully finishes. You can comment the fs.unlink() instruction to override this behavior.

The report is something that looks like this:

Image for post
Image for post
Test report sample

You can access it through the link in the console log directly or download it from your Blob storage in the Azure Portal:

Image for post
Image for post
Download directly the uploaded report from Azure Storage

This procedure also works for other automated test tools, like cypress or other JavaScript-based frameworks. If you are using another cloud provider like AWS, this is an example to do the same with S3 bucket.

Do not hesitate to check out my previous posts about API test automation and follow me to stay tuned for more good stuff.

YounitedTech

Le blog Tech de Younited, où l’on parle de développement…

Alee

Written by

Alee

QA Engineer @ Younited Credit

YounitedTech

Le blog Tech de Younited, où l’on parle de développement, d’architecture, de microservices, de cloud, de data… Et de comment on s’organise pour faire tout ça. Ah, et on recrute aussi, on vous a dit ?

Alee

Written by

Alee

QA Engineer @ Younited Credit

YounitedTech

Le blog Tech de Younited, où l’on parle de développement, d’architecture, de microservices, de cloud, de data… Et de comment on s’organise pour faire tout ça. Ah, et on recrute aussi, on vous a dit ?

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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