Distribute your API automated test reports using Azure Blob Storage

Mohammed Ali El Malhouf
YounitedTech
Published in
4 min readApr 20, 2020
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.
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:

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:

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
YounitedTech

Published in 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 ? https://careers.younited-credit.com/