Example tests and snippets

Custom HTTP Headers

You can easily set any headers you need by tweaking your get() or post() calls to include a header set. This is commonly used for authentication on an API (see api examples)

We have two example of setting headers below, but you can set any key value headers you need with LoadForge.

Code

Below we set our POST requests Content-Type to application/vnd.api+json and the GET request to application/json within the same test.

self.client.post(
    "/login",
    data=json.dumps(payload),
    headers={"Content-Type": "application/vnd.api+json"}
)


self.client.get("/api/test", headers={"Content-Type": "application/json"}

Global Headers

You can also set headers globally by defining the on_start() section as shown below. This will ensure ALL requests have the custom header added.

def on_start(self):
    self.client.headers.update({'Authorization': 'Bearer xxx'})
def on_start(self):
    self.client.headers.update({'Content-Type': 'application/json'})

These are snippets!

These are just partial examples from a test. You may use the wizard or another example template and copy paste these into your test.


Locust Test Example

LoadForge is powered by locust, meaning open source locust users can copy this script as well. If you are a locust user, consider importing your script to LoadForge to supercharge your testing!

Previous
Crawling a website