Created
April 8, 2020 22:32
-
-
Save BrianFarnhill/7da26f62935b7b0f300ad4d54375227f to your computer and use it in GitHub Desktop.
Generate Locust test from HAR file in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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