Example tests and snippets

Including Static Content

It's quite common with LoadForge tests to ignore static content (images, stylesheets, javascript, etc) as the main source of load will be your dynamic pages. However, it can be good to test the capacity of your webserver as well.

Tried the Wizard?

You can use the Wizard with static content enabled and it will automatically generate a test for you with your images, stylesheets and javascript files included. You can also scrape the page.

The below example requests an index page, and then a CSS, JS, and image file as well. You'll see the image request has a custom weight @task(4) to make it request 4x more images than the other task.

Code

from locust import HttpUser, task, between


class QuickstartUser(HttpUser):
    wait_time = between(5, 9)


    # this will run once per wait_time
    @task(1)
    def index_page(self):
        self.client.get("/")
        self.client.get("/app.js")
        self.client.get("/app.css")


    # this will run 4x as much as the above
    # it helps us fake 4x as many images on a page as content
    @task(4)
    def image_selection(self):
        self.client.get("/images/logo.jpg")

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
Scraping pages