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:
- Select an enrolled billing account
- Navigate to the billing statements portal
- Fetching the list of bills
- 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:
- Fetching the list of accounts associated with the user
- Select the account by making a GET call
- We then populate the list of documents
- We randomly select a document ID from the list that was loaded and send a download request
- 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.