Locust Directory

Login and get profile

Test that logs in and then requests a profile page.

Overview

A test which posts to a login page when it starts, then requests /profile and some static content normally.
This is a great example for logging into a site and then requesting content after login.

Code

import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    def on_start(self):        
        self.client.post("/login", {'email': 'user@domain.com', 'password': 'passw0rd'})
    
    @task(2)
    def profiles(self):
        self.client.get("/profile")     
        
    @task(1)
    def statics(self):
        self.client.get("/img/logo.png")
        self.client.get("/css/styles.css")
        self.client.get("/js/scripts.js")
This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

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