Converting HAR Files to Test Scripts
Tutorial and explanation on how to utilize the built k6’s built in HAR file coverter and associated options. The built-in HAR converter that will read HAR files and convert them to k6 scripts that can then be executed.
Using the converter
To use the converter use the following command:
k6 convert myfile.har
-O option to save to a file, or just redirect the output on stdout to a file).
k6 converter options
The converter offers various options to aid in producing a script, without extra noise. You can view all options with
k6 help convert
This allows you to specify the name of the output file. The default is “har-script.js”
This option allows you to supply a comma-separated list of domains which are the only ones you want to fetch things from in your k6 test. This means that k6 will filter out any requests that go to domains other than these.
The inverse of
--only. This option allows you to specify some domains that you want to exclude from the k6 test, meaning that the generated k6 script will not contain any requests for this domain.
When executing tests of websites or web apps, you want Virtual Users to make requests like a browser would. Browsers open connections in parallel and load those resources in parallel. By default, the converter looks for requests made within 500 ms of one another and includes them in the same batch request in your script.
This flag allows you to specify the maximum duration between requests. e.g.
--batch-threshold 1000 would change the setting to all requests made within 1 second of each other, are put in the same batch request in the outputted script. If there is a delay of longer than 1 second, a new batch request is created in the script.
Tools that can output HAR files
The built-in HAR converter is very useful because HAR is a format supported by many other tools, whose output can now be used by k6 to control VU behavior. Here is a list of some useful tools that are able to output HAR files:
- Chrome (browser)
- Firefox (browser)
- Microsoft Edge (browser)
- Charles recording proxy (HTTP proxy/recorder)
- Dynatrace (APM tool)
- Fiddler (HTTP proxy/recorder)
- Webpagetest (Online web page tester)
- Crossbrowsertesting (Online testing service)
- pcap2har (Converts sniffer - e.g. Wireshark - pcap files to HAR)