Skip to main content
No Result Found
Connect & Get help from 6000+ developers on our Discord community. Ask the CommunityAsk the Community

Load testing with Selenium Python

Run a load test using Selenium Python scripts on BrowserStack Load Testing

Prerequisites

  • BrowserStack Username and Access key. You can find this under your account profile.
  • An existing automated test suite written in Selenium with Python and pytest.

Use our Selenium Python load testing sample project to quickly get started.

Run a test

Based on your preferred method of performing load tests, use one of the following methods:

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 Browser Only and click Upload scripts.

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

Upload scripts

In this step, upload your Selenium Python automation project as a ZIP file. Select your framework (for example, Selenium - Python) from the dropdown, then drag and drop your ZIP file (up to 250MB) or click to select it.

Before you zip and upload your Selenium Python automation project, replace local WebDriver instances (such as webdriver.Chrome()) with RemoteWebDriver or a remote WebDriver factory to run tests on the remote setup. Set the remote URL to http://localhost:4444/wd/hub. Example RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps);'

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

After you upload your ZIP file, the dashboard automatically validates your project. If validation is successful, you will see a confirmation message and a summary of the detected configuration and dependencies.

In the Specify run target field, enter the path to your Python file or module (for example, test_login.py). Then, select your requirements.txt file from the Select dependencies dropdown to specify which dependencies to install for your tests.

Dashboard showing successful validation of a Selenium project ZIP with config and dependencies

Ensure that your requirements.txt and any test runner configuration files are placed at the root level of your project.

Once you have verified the configuration, click Configure Load to move to the next step.

You can also run load tests using the Selenium Python 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 test

After you finish configuring load parameters, click RUN TEST.

Placeholder for Selenium Python run test screen on load testing dashboard

Set BrowserStack credentials

Save your BrowserStack credentials as environment variables. It simplifies running your Selenium Python load test suite from your local or CI environment.

Copy icon Copy
Copy icon Copy
Copy icon Copy

Install BrowserStack Python SDK

Execute the following commands to install BrowserStack Python SDK for plug-and-play integration of your test suite with BrowserStack.

python3 -m pip install browserstack-sdk
browserstack-sdk setup --username "YOUR_USERNAME" --key "YOUR_ACCESS_KEY"
python3 -m pip install browserstack-sdk
browserstack-sdk setup --username "YOUR_USERNAME" --key "YOUR_ACCESS_KEY"

Initialize your project for load testing

Run the following command from the root directory of your Selenium Python test project to generate the browserstack-load.yml file, which contains the configuration required to define and run your load test.

Copy icon Copy

Refer to the given table to use the framework - language combination argument depending on your preference:

Framework Argument
Selenium - Python --framework selenium --language python
Selenium - Pytest --framework pytest --language python

Configure your Load Test

Open the generated browserstack-load.yml file and update it with the relevant Selenium Python test details. Use it to define your virtual users, duration, load profile, and regions.

Specify the test type

testType defines the type of load test that you want to execute. Currently, Playwright, Selenium, WebdriverIO and Nightwatch are supported. Set this to Selenium for a load test using Selenium test suite.

Specify the language

Set the language to python.

Currently, only Selenium with Python, and Pytest is supported.

For a Python (vanilla) project, you need to specify only the language parameter.

For a Pytest project, you must also specify the framework parameter with value pytest.

If you omit the framework parameter, the platform treats the project as a Python (vanilla) project.

Specify the test framework

Set the framework to pytest, if that is your preferred framework.

Specify the paths to your Python configuration file

The files block specifies the key files required to install dependencies and define which tests should be executed.

  • Under dependencies, ist the paths to required files for installing dependencies. For Python projects, include the path to your requirements.txt file.
  • Against runTarget, specify the path to python files (.py) or module (directory) that you want to run. Note: This attribute is only relevant for Python (vanilla) projects. This doesn’t work for Pytest projects.

Ensure all referenced files are relative to the project root.

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–Z, a–z)
  • Digits (0–9)
  • Periods (.), colons (:), hyphens (-), square brackets ([]), forward slashes (/), at signs (@), ampersands (&), single quotes ('), and underscores (_)
    All other characters are ignored.

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

browserstack-load.yml

Run the Load Test

Run the load test from the root of your Selenium Python project using the Load Testing CLI.

Copy icon Copy

Before running a full-scale load test, do a sanity check with a small set of virtual users to validate your Selenium Python configuration and test stability.

View test results

When the test runs, you get a link to the result dashboard, where you can analyze key metrics such as:

  • Response time
  • Request throughput
  • Web vitals (LCP, CLS, INP, and others)
  • Errors and bottlenecks

If you run into issues, try the troubleshooting steps or contact us for help.

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