← Load Test Directory

Advanced E-Commerce Test Example

Authentication, Adding to cart, browsing products and going to check out

You are now browsing the LoadForge locust test directory. You can use these tests as a starting point for your own tests, or use our AI wizard to generate one automatically.



This enhanced LoadForge locust script simulates a more comprehensive user journey on an e-commerce website. It includes advanced behaviors such as user authentication, browsing through a variety of products, adding items to the cart, viewing the cart, and proceeding to checkout. The script is designed to mimic realistic user actions and gather detailed performance metrics.


The below code can be run directly on LoadForge to test at scale.

from locust import HttpUser, task, between
import random

class EcommerceUser(HttpUser):
    wait_time = between(1, 5)
    product_ids = [101, 102, 103, 104, 105]  # Example product IDs
    cart_id = random.randint(1000, 9999)

    def on_start(self):

    def user_login(self):
        # Implement login logic here
        response = self.client.post("/login", {"username": "user", "password": "password"})
        if response.status_code != 200:
            print("Failed to log in")

    def view_products(self):

    def view_product_details(self):
        product_id = random.choice(self.product_ids)
        self.client.get(f"/products/{product_id}", name="/products/:id")

    def add_to_cart(self):
        product_id = random.choice(self.product_ids)
        self.client.post("/cart", {"product_id": product_id, "quantity": 1})

    def view_cart(self):

    def checkout(self):
        self.client.post("/checkout", {"cart_id": self.cart_id})

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!

Ready to run your test?
Start your first test within minutes.