Using Locust for Load Testing – Use Case

Mostafa Rashed
Full Stack Developer

Locust Logo

Earlier this week we discussed Load Testing Alternatives to JMeter. After trying out load testing alternatives like Selenium and Gatling; we realized our favourite tool was Locust. Today we discuss why Locust was the best option for us, and how we customized it to suit our needs.

Our Use Case

On a recent Indellient project we prioritized load testing after major infrastructure and refactoring work for our client. The client provides a billing service that allows thousands of users to connect to different institutions to view and manage their billing accounts. 

After our search for the perfect Load Testing tool we ended up choosing Locust. Learn more about the different tools we tried here:

For our use case, the application being tested allows clients to log in to their account and manage all their billing in one place.  In this example, we’ll look at the flow of a user logging into their account and downloading a bill (PDF). This tests multiple API calls, loading dynamic details onto the page, and fetching a document stored on the client’s servers.  

The general steps can be broken down into: 

  1. Authenticate
  2. Select an enrolled billing account 
  3. Navigate to the billing statements portal 
  4. Fetching the list of bills 
  5. Downloading the bill 

Authentication for a normal user works by entering a username and password combination like any site. However, in the background API call we use a uniquely generated security token that’s embedded into the HTML page as an extra security measure. This is usually done by the script that’s served alongside the webpage. Since we’re not using a headless browser, we needed to simulate the same API call after loading the page in order to authenticate properly.  

Using BeautifulSoup with Locust

This is where BeautifulSoup comes in. With BeautifulSoup we are able to easily parse the HTML to find the token we need and include it as the body of the POST call along with the credentials using Python’s HTTP client. This way we successfully simulate a real user logging in.  

We then once again mimic the page script by: 

  1. Fetching the list of accounts associated with the user 
  2. Select the account by making a GET call 
  3. We then populate the list of documents 
  4. We randomly select a document ID from the list that was loaded and send a download request 
  5. End the test 

As you can see, having Python was very convenient and simplified the test creation. I was then able to launch a test via the CLI in distributed mode and I was able to have hundreds of users being simulated within seconds. 


Custom Cloud Applications

Indellient takes a customer-first approach to help you build a modern cloud strategy on Amazon Web Services, Windows Azure and Google Cloud Platform. Our team can help you build, replatform, migrate and integrate applications, so you can benefit from the scalability, agility, and performance available through cloud technologies.

Indellient is an IT Professional Services Company that specializes in Data AnalyticsCloud Development ApplicationDevOps Services, and Business Process Management.

Learn More

About The Author

Mostafa Rashed

Hey! I'm Mostafa Rashed, a Full-Stack Developer at Indellient. I'm currently working on a team that develops and supports web applications, custom solutions and cloud infrastructure. I've graduated from the University of Guelph with a Bachelors in Computer Science as well as a minor in Mathematics. Naturally, I'm into technology, but I'm also a big time gear heads with a love for cars!