Generating locust load tests from HAR files using PowerShell

Apr 9, 2020

One of the tasks I’ve been helping a number of customers with recently is load testing of websites - making sure that apps can stand up to large amounts of traffic has always been critical, and verifying that before the real traffic comes is just as important. My go-to load tester is Locust, it’s open-source and easy to use, you simply write a python script for your test and you’re off and running.

To shortcut things for myself a little this week, I wrote a quick PowerShell script that I wanted to share with you that generated a basic locust test file from a HAR file. If you’re not familiar with a HAR file, it stands for “HTTP Archive”, and is basically a collection of data about HTTP requests and responses. The easiest way to generate one is to open your web browsers developer tools, go to the Network tab, refresh the page then choose “save HAR file”. It’s essentially just JSON, so parsing it is easy. This let me to writing a quick PowerShell script that generated the locust test from any page that I opened. I could also tell the browser to preserve the history between page loads and collect a list of multiple pages worth of data before saving the HAR file, which was good for simulating multi-page behaviour as well.

Here’s a gist with the script that parses it.

It’s very straight forward, just point it at your HAR file and set the top-level domain (I use this to filter our requests to external sites, like trackers etc.) then run it. The locust config is basic (you’ll want to tweak the wait times to suit, and potentially the task weights) but this will get you started pretty easily. I hope this helps you get more load testing done - happy testing!



You're signed in as | Sign out

Submitting comment...

There are no comments on this post yet. Be the first to leave one!