Generating scripts from HAR files

Micro Focus Expert
Micro Focus Expert
3 1 373

Generating scripts from HAR files - Blog graphic 3.pngWhen it comes to HAR files, usually the following two questions arise: (1) What is a HAR file? And (2) how can HAR files be useful, especially in regards to load testing? In this blog post, we will introduce you to HAR files and we will step through a sample workflow, which illustrates how HAR files can be leveraged in a real-world scenario.

What is a HAR file?

But first, let’s gather a few basic facts around HAR files: HAR is short for HTTP archive. HAR files are based on a standard that is being developed by the W3C. The purpose of a HAR file is to store performance data about web pages, and since this storing process is basically a traffic capturing process (similar to the work the Silk Performer Recorder does), HAR files can also be used in the context of load testing. Also, HAR files are supported by a variety of tools, particularly by some widely-used web browsers, like Firefox, Chrome, and Internet Explorer. So, these are the key points about HAR files:

  • HAR stands for HTTP archive.
  • HAR files are based on an evolving W3C standard.
  • HAR files store performance data about web pages.
  • HAR files are supported by a variety of tools.

How can HAR files be useful?

There are circumstances where HAR files can be very useful. Take a look at the following scenario that we have made up (also outlined in the diagram below): The lead character in our short story is John. John is a salesman in a big insurance company. For his every day work, he uses a web-based CRM tool, which is built and maintained by the in-house software development department. John usually uses Firefox, his favorite web browser, to access the CRM tool. Occasionally, when a lot of salesmen access the tool simultaneously, the performance of the CRM tool drops noticeably.

In such a case, John wishes to notify the performance engineering team about the unresponsive tool. By using HAR files, John can now do so. And the great benefit is that he does not need any specific tool or expert knowledge. All he needs is the tool that he’s using regularly anyway: his web browser.

So, John uses Firefox to record a workflow within the CRM tool and the recorded traffic is saved in a HAR file. John now hands over the HAR file to Robert, one of the performance engineers in the company. Robert imports the HAR file into Silk Performer and uses his expert knowledge to create a full-fledged load test out of it. The CRM tool can now be load tested, monitored, and perpetually optimized.

Generating scripts from HAR files - Blog graphic 1.png

The benefits of using HAR files

To summarize:

  • John does not require any special tool or expert knowledge to contribute to the company’s load testing efforts.
  • Virtually anybody can now record a workflow, be it developers, managers, business analysts, or salesmen.
  • To do so, all you need is a tool that supports HAR files, like a modern web browser.

Remember though: Whenever you have access to the Silk Performer Recorder and the knowledge to make use of it, it’s the preferred option. Because the Silk Performer Recorder is still the most advanced and robust tool for recording load test scripts.

Creating a HAR file in Chrome

We will now explore how to actually create a HAR file within a browser, for this example we’ll be using Chrome. So we start Chrome, open the Developer Tools and click the Network tab. This tab reveals the network traffic between browser and server.

When you navigate through any website, you will probably notice that the table on the Network tab only shows the traffic (the resources) of the last visited site. We, however, want to record a sequence of clicks, a workflow. To prevent Chrome from constantly overwriting the already captured traffic, we have to enable the option Preserve log (1). Now we can record a sequence of clicks. When we’re done, we right-click somewhere in the table and click Save as HAR with content (2) in the context-menu. We give the file a name and save it.

Note that the controls and check boxes are named differently in the various browsers. But they basically all do the same.

01.png

Importing the HAR file in Silk Performer

We now start Silk Performer. Before we import the file, note that the HAR file is converted into a capture file during import, which again will be used to generate a script file.

Generating scripts from HAR files - Blog graphic 2.png

In the menu, we click Project > Add Capture File > Import and Convert .har File (1). Alternatively you can right-click the Capture Files node in the tree and click Import and Convert .har File (2).

02.png

When we open the file, the Capture File page displays and a .spcap file is added to the Capture Files node in the tree. You can use the filters on the Capture File page or adjust other script generation settings, just as you are used to. When you’re done, click Generate script. The editor displays, showing the load test script and a .bdf file is added to the Scripts node in the tree.

Conclusion

Generating Silk Performer scripts from HAR files is a valuable option to have for cases when the Silk Performer Recorder is not available or does not work as expected (due to group policy restrictions for example). It must be noted though that the HAR format is rather vaguely defined, which might be the reason why different browsers generate quite different HAR files for the same pages. Nevertheless, Silk Performer does a good job in compensating for these shortcomings and generates useful capture files.

Watch the video

In the following video you can watch how we performed the above described steps:

More information

To learn more about all new features and enhancements Silk Performer 19.5 provides, take a look at the following blog post:

The Silk Performer Help is another comprehensive source of information.

If this article was useful for you, leave us a comment or like it. We appreciate your feedback.

1 Comment
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Great feature, thanks!

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.