Protocol load testing using Locust
Run a protocol load test on BrowserStack Load Testing
Prerequisites
- BrowserStack Username and Access key. You can find these under your account profile.
- An existing Locust script written in Python (for example, a
locustfile.py).
Run a test
Based on your preferred method of performing load tests, use one of the following methods:
Create a new test
You can start a new test either from the Quick Start page or the Load Tests page on the Load testing dashboard.
On the dashboard, click Create Load Test.

Enter a Test Name for your load test, select API Only, and click Upload scripts

Upload scripts
Upload your Locust scripts.

BrowserStack Load Testing supports two upload modes for Locust tests:
Single file
Upload a single Python file (for example, locustfile.py) that contains your Locust test. This option works well when your script has no external dependencies beyond the Locust library and uses only the Python standard library.
The script must:
- Import from Locust (for example,
from locust import HttpUser, task, between). - Define at least one user class that subclasses
HttpUser,FastHttpUser,User, orGrpcUser.
Sample locustfile.py
Multi-file project
Upload a .zip archive that contains your main Locust script and any additional supporting files. Use this option when your test imports helper modules, reads from data files, or depends on third-party Python packages.
Project structure example
Upload behavior
- BrowserStack preserves the folder hierarchy inside the ZIP, so relative imports such as
from utils.helpers import logincontinue to work at runtime. - The maximum supported ZIP size is 100 MB. If the archive exceeds this limit, the upload is rejected with a clear error message.
When you upload a .zip file, specify the main script path in the Main script field, relative to the root of the ZIP (for example, tests/locustfile.py). The platform uses this as the Locust entry point. If you leave this field empty or the file is not found, the test configuration shows an error and the run cannot start.
If your test uses third-party Python packages, include a requirements.txt file at the root of your ZIP. BrowserStack installs the listed packages before the run starts. Keep the install lightweight, since the install step has a 120-second timeout.
Once you have verified the configuration, click Configure Load to move to the next step.
You can also run load tests using the sample scripts if you want to try out the feature before uploading your own files.
You can configure the following load parameters to customize your load test:
Run the test
After configuring your load parameters, click Run Test to start your load test.
For more information on analyzing your test results, refer to View protocol test results.
Download the BrowserStack Load Testing CLI
Download the CLI based on your operating system:
Generate the YAML file
Run the given command to generate the browserstack-load.yml file which contains the configuration required to define and run your load test:
Configure your Load Test
Open the generated browserstack-load.yml file and update it with the relevant test details. Here’s a sample configuration:
Specify number of virtual users
Set vus to the maximum number of virtual users to simulate during the test.
The maximum limit for this config is currently 1000. Contact us if you want to increase this limit.
Specify the test scripts
The files block defines the key files needed to identify which tests to execute.
Single Locust file
For a test that lives in a single Python file, set testScripts to the absolute path of that file:
files:
testScripts:
- /Users/abc/Desktop/testing-locust/locustfile.py
Multi-file Locust project
If your test depends on helper modules, data files, or third-party Python packages, configure testDir along with testScripts:
-
testDir: Absolute path to the directory that contains your Locust scripts, helper modules, data files, andrequirements.txt. The CLI zips this directory as is and uploads it, so your folder structure is preserved. -
testScripts: Absolute path to the main Locust entry script. The path must point to a file insidetestDir.
files:
testDir: /Users/abc/Desktop/testing-locust
testScripts:
- /Users/abc/Desktop/testing-locust/locustfile.py
Behavior and constraints
- The CLI validates that the entry script defined in
testScriptsexists insidetestDir. If it is missing, the run fails fast with an error. - BrowserStack includes every file and folder under
testDirin the upload, so relative imports such asfrom utils.helpers import logincontinue to work at runtime. - To add third-party Python packages, place a
requirements.txtfile at the root oftestDir. BrowserStack installs the listed packages before the run starts. Keep the install lightweight, since the install step has a 120-second timeout. - The maximum upload size is 100 MB.
- If your test imports a file that is not present under
testDir, the test run fails when Locust executes those imports.
Set reporting structure
- Use
projectNameto group related tests under the same project on the dashboard. UsetestNameto group multiple runs of the same test. - Both
projectNameandtestNamemust remain consistent across different runs of the same test. - You can use the following characters in
projectNameandtestName:- Letters (A to Z, a to z)
- Digits (0 to 9)
- Periods (.), colons (:), hyphens (-), square brackets ([]), forward slashes (/), at signs (@), ampersands (&), single quotes (‘), and underscores (_)
- All other characters are ignored.
Example with load profile stages
Instead of using flat vus and duration, you can define a loadProfile with multiple stages:
You can configure the following load parameters to customize your load test:
Run the Load Test
Run the given command to start your test:
Check out the FAQs section to get answers to commonly asked questions.
View your test results
After running your load test, you can view detailed results on the Load Testing dashboard.
For more information on analyzing your test results, refer to View protocol test results.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!