Distribute your API automated test reports using Azure Blob Storage
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:
- Sign in to the Azure portal.
- Locate your storage account.
- 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.
- 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.
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:
- Go to the storage account you accessed earlier in Azure Portal
- In the Blob service section of the storage account overview, select Containers
- Select the container to host your reports
- Click on Change access level button
- Choose Blob
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 install
in 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:
- Export a collection in JSON to save the collection file in your local disk.
- Generate a link to get a public accessible link for your collection.
- 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:
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:
You can access it through the link in the console log directly or download it from your Blob storage in the Azure Portal:
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.