Tuesday, March 19, 2019

Azure @ Enterprise - Downloading all the VSOnline / Azure DevOps load test .har files together

Background

After performing a load test via Azure Test Plans or Visual Studio Online, it produce the http archive  files with .har extension. Those .har files are available in the Azure DevOps portal as part of test results and we can download to analyze the nature of load test. But the problem is that we need to download files one by one. Its tedious to do via portal.

Solution

As everyone knows, the Azure is built around ReSTful Web APIs. The Portal UI itself is a wrapper around those APIs. Lets see how can we download those files easily using the same API layer.

Figuring out Url

Below Url gives the details of WebAPI which we can invoke to interact with the load tests.


In short, the url format is below
https://<organization name>.vsclt.visualstudio.com/_apis/clt/testRuns/<Run GUID>/results?api-version=5.0

The GUID of test run can be obtained from the portal URL, when we are in the individual test run page. If we try with the integer sequence number what we are seeing the test runs list, it will not work.

Security

The MSDN documentation says Personal Access Token and type Basic.  That means, when we put the PAT, we have to use base64 encoding. The best way to make sure its working, is via Postman. Below are the steps.
  • In Postman, make sure the http method is GET and enter the intended URL by replacing the organization name and Run GUID.
  • Go to Authorization tab and select TYPE as "Basic Auth".
  • Enter any user name or leave it empty and inside the password text box, put the Personal Access Token.
  • Press on 'Send' buttong to send the API request to Azure DevOps, and we should get data in JSON format.

What is the role of storage account and how to access files

The WebAPI call /testRuns/<GUID>/results gives a JSON as explained above not the .har files which we need. Instead of .har files or har data, it has a link to Azure Blob Storage. Notice that the link has some query string which have the SAS token details. 

Azure developers already knows how to download files from an Azure blob storage, if they get a URL with SAS token suffixed to it.

But for the benefit of testers and automation guys the below link has been given which explains, how to download files from Azure blob storage using a tool called Azure Storage Explorer. It is free as of now.


Once the connection is established in Azure Storage Explorer to storage account using the SAS token, we can navigate to the correct GUID folder of test run. Then to /TestResult/Diagnostics folder to download .har files.

Another way is to use another command line tool called AzCopy.exehttps://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy which download the files from Azure Storage Account in higher speeds. AzCopy.exe needs the SAS token to be passed into it via command line switches. Since that is not in the scope of this post, letting it to learners.

No comments: