Automate HAR file downloading

As some of you know Perfecto provides the functionality that enables you to Generate and Analyze HAR files. If you want to automate the process of the HAR files downloading this article is for you.

Step-by-step instructions

Let’s start with the prerequisites:

  1. You need to add these lines to your code obtain the executionID, which will later be used as anchor for finding the test ID:

    Copy
    Capabilities caps = driver.getCapabilities();
    String externalID = (String) caps.getCapability("executionId");

     

         For your convenience of testing you can print it like this:

    Copy
    System.out.println("externalID: " + externalID);
  2. You need to have a security Token, providing you with the ability to authenticate to your cloud.
  3. Follow this article on how to generate the HAR file. Stop upon reaching the “Retrieving the HAR file” part as the mentioned download method is manual.
  4. For my testing purposes I have installed Postman.

Having the prerequisites all set, you can now continue.

To download the file in an automated manner (Let’s see how I have done with the help of Postman):

  1. Go for an HTTP GET with the following data:

    • URL: https://<your-cloud>.reporting.perfectomobile.com/export/api/v1/test-executions
    • Header:
  2. Click on “New”:

  3. Select “Request”:

  4. Fill up the Name and select a Collection:

  5. Click “Save to <your Collection>”:

  6. Enter the URL https://<your-cloud>.reporting.perfectomobile.com/export/api/v1/test-executions (change <your-cloud> with the name of your cloud)

  7. Click on “Header” and type the Key and the Value accordingly:

  8. Click “Send”:

  9. The result should look like this:

  10. Here you have an “externalID”, like the one you have in the Prerequisites (you may need to search for it using the CTRL+F function):

  11. Determining the same “externalID” as the one in the code is essential for the determining the right test you are going to download the HAR file for.

    Few lines below our “externalID” you will find “path” like this one (under “artifacts”):

    This is the path you need!

  12. When you follow it, you will be taken to a ZIP file that you can download and extract. The HAR file is two levels below: