Explorer reports addition
We have added a new Explorer feature to reports, with a timeline scrubber and easy anomaly detection.
Guide on handling CSRF tokens, sessions, and protected pages with LoadForge using Locust.
LoadForge can record your browser, graphically build tests, scan your site with a wizard and more. Sign up now to run your first test.
Testing authenticated flows requires obtaining CSRF tokens, logging in with credentials, maintaining session cookies, and accessing protected endpoints. Locust’s HttpUser manages cookies automatically, enabling realistic user simulations.
# locust.py
from bs4 import BeautifulSoup
from locust import HttpUser, between, task
class AuthFlowUser(HttpUser):
wait_time = between(1, 3)
host = "https://example.com"
def on_start(self):
# Load login page to fetch CSRF token
response = self.client.get("/login", name="Get Login Page")
soup = BeautifulSoup(response.text, "html.parser")
token = soup.find("input", {"name": "csrf_token"})["value"]
# Perform login with CSRF and credentials
self.client.post(
"/login",
name="Perform Login",
data={"username": "user", "password": "pass", "csrf_token": token}
)
@task(3)
def load_dashboard(self):
self.client.get("/dashboard", name="Dashboard")
@task(1)
def load_profile(self):
self.client.get("/profile", name="Profile")
Notes:
pip install locust beautifulsoup4.csrf_token, username, password) match your application.