Overview
In this guide, we’ll walk through creating a load test for a Next.js website using Locust, and running it with LoadForge. This specific test is able to used with any Javascript based site (next, nuxt, react, etc) as it automatically crawls URLs on the site and uses those in the load test.You can authenticate, maintain sessions, and much more with LoadForge. Browse the docs for examples on what you need, or use your LoadForge account’s
wizard or AI test generator to make the test for you.
Prerequisites
Ensure you have:- Very basic understanding of Python.
- Have set up a LoadForge account.
- Have added and verified your Host for testing
Using BS4
LoadForge instances come pre-provisioned with many helpful tools, including beautifulsoup4, which we use for parsing html content in this test. You can install it yourself locally if you can busy developing your test still with the following command:Creating Your Test File
The example below demonstrates a user that crawls a webpage, discovering and loading linked pages and static content (like images, CSS, JS files). You can paste this locustfile directly into LoadForge to test your site.Notes on the script
on_start
: Initiates crawling the homepage once per simulated user.crawl
: A recursive method making GET requests to paths, discovering and loading other linked resources.@task(1)
: Simulates users continually loading the homepage.
Conclusion
This guide provided a basic setup for load testing a Next.js website, crawling, and discovering links/resources. Ensure to optimize and adjust your locustfile based on real-world user interactions, website structure, and testing objectives.LoadForge operates on the robust foundation of Locust. This compatibility ensures that users of open-source Locust can effortlessly adopt this script into their setups. If you’re already leveraging Locust, think about integrating your script with LoadForge to elevate your testing experience!