Skip to main content
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

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.

Screenshot of load testing dashboard showing the run a new test button highlighted

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

Dashboard showing test name field and type of load test to run

Upload scripts

Upload your Locust scripts.

Screenshot of load testing dashboard asking to add scripts for load testing

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, or GrpcUser.
Sample locustfile.py
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
Copy icon Copy
Upload behavior
  • BrowserStack preserves the folder hierarchy inside the ZIP, so relative imports such as from utils.helpers import login continue 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:

Copy icon Copy

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, and requirements.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 inside testDir.
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 testScripts exists inside testDir. If it is missing, the run fails fast with an error.
  • BrowserStack includes every file and folder under testDir in the upload, so relative imports such as from utils.helpers import login continue to work at runtime.
  • To add third-party Python packages, place a requirements.txt file at the root of testDir. 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 projectName to group related tests under the same project on the dashboard. Use testName to group multiple runs of the same test.
  • Both projectName and testName must remain consistent across different runs of the same test.
  • You can use the following characters in projectName and testName:
    • 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.
browserstack-load.yml
Example with load profile stages

Instead of using flat vus and duration, you can define a loadProfile with multiple stages:

browserstack-load.yml with loadProfile

You can configure the following load parameters to customize your load test:

Run the Load Test

Run the given command to start your test:

Copy icon Copy

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





Thank you for your valuable feedback

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy Check Circle