While possible to install globally, we recommend that you, if possible, add the converter to the
node_modules
of your test project using:
$ npm install --save har-to-k6
Note that this will require you to run the converter with npx har-to-k6 your-har-file
or,
if you are using an older version of npm, ``./node_modules/.bin/har-to-k6 your-har-file`.
$ npm install --global har-to-k6
$ docker pull grafana/har-to-k6:latest
$ npx har-to-k6 archive.har -o my-k6-script.js
$ ./node_modules/.bin/har-to-k6 archive.har -o my-k6-script.js
$ har-to-k6 archive.har -o my-k6-script.js
const fs = require("fs");
const { liHARToK6Script } = require("har-to-k6");
async function run () {
const archive = readArchive();
const { main } = await liHARToK6Script(archive);
fs.writeFileSync("./load-test.js", main);
}
Use validate()
to run validation alone. Returns without error for a valid
archive. Throws InvalidArchiveError
for validation failure.
const { InvalidArchiveError, validate } = require("har-to-k6");
const archive = readArchive();
try {
validate(archive);
} catch (error) {
if (error instanceof InvalidArchiveError) {
// Handle invalid archive
} else {
throw error;
}
}
har-to-k6
can be ran in the browser. This exposes the standard
API under harToK6
.
import { liHARToK6Script } from "har-to-k6";
const { liHARToK6Script } = require("har-to-k6");
Load standalone.js
into your HTML page:
<html>
<head>
<title>HAR Converter</title>
<script src="standalone.js"></script>
<script src="index.js"></script>
</head>
</html>
The API is available:
async function run () {
const archive = readArchive();
harToK6.validate(archive);
const { main } = await harToK6.liHARToK6Script(archive);
displayResult(main);
}
- LI-HAR - Static configuration format representing a K6 script
- LI-HAR to K6 converter - JavaScript package or function that converts a given LI-HAR to a K6 script
- LI-HAR to K6 CLI tool - a Node.js CLI tool exposing an interface for converting a given LI-HAR to a K6 script
Thanks to bookmoons for creating this tool 🎉