Skip to content

Instantly share code, notes, and snippets.

@BrianFarnhill
Created April 8, 2020 22:32
Show Gist options
  • Save BrianFarnhill/7da26f62935b7b0f300ad4d54375227f to your computer and use it in GitHub Desktop.
Save BrianFarnhill/7da26f62935b7b0f300ad4d54375227f to your computer and use it in GitHub Desktop.
Generate Locust test from HAR file in PowerShell
$rawData = Get-Content -Raw -Path 'YourFileNameHere.har' | ConvertFrom-Json
$rootUrl = 'https://Your.Root.Domain/'
$output = @"
from locust import HttpLocust, TaskSet, task
class MyTaskSet(TaskSet):
"@
$callNumber = 0
$rawData.log.entries.request.url | Where-Object -FilterScript {
$_ -like "${rootUrl}*"
} | Select-Object -Unique | ForEach-Object -Process {
$pathUrl = $_.Replace($rootUrl, '')
$callNumber ++
$output += @"
@task(1000)
def path$callNumber(self):
self.client.get("$pathUrl")
"@
}
$output += @"
class MyLocust(HttpLocust):
host = "$rootUrl"
task_set = MyTaskSet
min_wait = 1
max_wait = 1
"@
$output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment