Example tests and snippets
Scraping Pages for Resources
LoadForge supports using the HttpUserWithResources plugin for Locust, allowing you to automatically fetch all relevant page resources.
We typically advise creating your test to manually include resources you wish to fetch, as this will not execute JS, so you may want to fetch AJAX resources. Or alternatively, you could upload a browser recording (.har) to achieve that same.
Tried the Wizard?
LoadForge has a full wizard available for test generation, and it can find all the static content on your domain and add it to your test file automatically for you!
Code
The below code requests the root of your website (/) and automatically also downloads anything matching this regular expression: .*[^(js|png|css|gif|woff)]$
In English, anything ending in .js, .png, .css, .gif, or .woff.
from locust_plugins.users import HttpUserWithResources
from locust import task
class TestUserWithResources(HttpUserWithResources):
# these default values can be overridden
# bundle_resource_stats=False
# default_resource_filter=".*[^(js)]$"
@task
def include_resources_default(self):
self.client.get("/cart")
@task
def include_resources_true(self):
self.client.get("/", resource_filter=".*[^(js|png|css|gif|woff)]$")
@task
def include_resources_false(self):
self.client.get("/dashboard", include_resources=False)
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!