Overview
LoadForge allows you to login to any website, and then browse the site as a logged in user (or set of users).
We recommend learning about regular user logins before this guide.
Sessions are automatic
LoadForge will automatically keep sessions, meaning you can login and then browse the site like a browser would.
This guide will give you an example of how to login as different users throughout the test, simulating multiple user logins and site usage. Note that this typically isn't needed, as 1000 of a single login is generally the same load as 1000 separate users.
Generated users code example
from locust import HttpUser, TaskSet, task, between
import time
class AwesomeUser(HttpUser):
wait_time = between(10, 20)
# On start populate our user list
def on_start(self):
self.createUsernames()
# Create an array of user1 -> user1000
def createUsernames(self):
self.users = []
for i in range(1000):
self.users.append("user"+str(i+1))
# Fetch the next user in our list
def getUsername(self):
return self.users.pop()
# Login to the site
def login(self):
username = self.getUsername()
loginInformation = {
"username": username,
"password":"passw0rd"
}
self.client.post("/login", loginInformation)
# Logout from the site
def logout(self):
self.client.get('/logout', name="logout")
# Define our tasks here
@task(1)
def load_page(self):
# Login first
self.login()
# Put your logged in tasks here
self.client.get('/profile/info')
# Logout now
self.logout()
The above code creates 1000 users named "user1" through "user1000" and logs in with each of those. It's designed for a 1000 user test of course. You can easily modify this. You can also pick usernames at random like so:
def getUsername(self):
return "user"+str(randomint(1,1000))
You can modify this test to suit whatever pre-populated user system you have. You could also consider registering users with the test and clearing your database afterwards.
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!