Hybrid load testing with Playwright Python
Run a hybrid load test on BrowserStack Load Testing that generates browser load with pytest-playwright and protocol load with JMeter or k6.
BrowserStack installs the packages in your requirements.txt file, then runs your pytest suite for every browser virtual user in its own Chrome or Microsoft Edge browser.
Supported versions
BrowserStack supports the following framework and engine versions for hybrid load tests with Playwright Python:
| Framework | Python version | Preinstalled packages | Protocol engine |
|---|---|---|---|
| Playwright Python | Python 3.10 | pytest 9.2.0, pytest-playwright 0.10.0, Playwright 1.60 | JMeter 5.6.3, k6 2.0.0 |
BrowserStack installs the packages in your requirements.txt file on top of the preinstalled versions. A version that you pin in requirements.txt replaces the preinstalled version, so pinned versions must install on Python 3.10. Your tests run on the same browser regardless of which Playwright version you pin.
The load test settings select the browser. Chrome is the default. To run the browser part on Microsoft Edge, select Microsoft Edge under Select Browser on the Advanced Settings tab of the Load Configuration step.
The browser part of a hybrid test doesn’t support the following:
- Async tests: Projects that use
pytest-asyncioorpytest-playwright-asynciostop before the load starts. Use the synchronouspagefixture. - Firefox, WebKit, and
launch_persistent_context(): The browser part runs on Chrome or Microsoft Edge only. -
pytest-xdist: Each browser virtual user runs one pytest process. - Selenium: Selenium code in your project doesn’t drive the virtual user’s browser. For Selenium tests, see Hybrid load testing with Selenium Python.
Prerequisites
- BrowserStack username and access key. You can find these under your account profile.
- An existing JMeter script.
- A pytest project that uses
pytest-playwrightwith the synchronous API, through thepage,context, orbrowserfixtures. - A
requirements.txtfile at the root of the project that listspytest-playwright, or bothplaywrightandpytest. - Test files that pytest can discover. By default, pytest discovers files named
test_*.pyor*_test.py. - Access from the BrowserStack load generator IP addresses to your private package index, if the index is behind a firewall. For the list of IP addresses to allowlist, see Test private websites and APIs.
Tests that use the page fixture run without code changes.
Run a test
Perform the following steps to run a hybrid load test with JMeter and your Playwright test suite written in Python:
Create a load test
You can start a new test 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 Hybrid, and click Upload scripts.

Upload your scripts
A hybrid test combines a JMeter script with a Playwright Python project. JMeter generates API-level load, and Playwright drives browser-level load to simulate real user interactions.
Before you upload, zip the folder that contains your requirements.txt file. Leave out the __pycache__/, .pytest_cache/, .venv/, and venv/ folders.
The Load Sources step has two sections:
- API Load Source: Select Upload Script, select JMeter from the dropdown, and upload your JMeter script. Then, select your main script from the Select Main JMeter script dropdown.
-
Browser Load Source: Select Upload Automation Project, select Playwright - Pytest from the dropdown, and upload your ZIP file. The ZIP file size limit is 250 MB. Then, select your
requirements.txtfile from the Select dependencies dropdown.

Turning on Multiple Scenarios hides the Upload Script and Upload Automation Project cards, so each section shows only its dropdown. Adding test data files also hides the browser cards.
After you upload the files, BrowserStack validates them and lists any issues to fix. For a list of validation messages and fixes for your Python project, see Troubleshoot Python load tests.
To try hybrid load testing with Playwright Python before you upload your own files, click Use Sample Scripts on the Load Sources step to run a hybrid load test with the sample scripts.
You must complete both sections. After you upload both files, click Configure Load to move to the next step.
Configure load and run test
You can configure the following load parameters to customize your load test:
To run only some of your browser tests, turn on Multiple Scenarios in the Browser Load Config section. For each scenario, under Scenario Configuration, enter a Scenario name, select a selector from the Test Selector dropdown, and select or enter its value. To add more scenarios, click Add Another Scenario. You can use the following test selectors:
| UI builder selector | YAML type
|
Value | Example |
|---|---|---|---|
| Marker | tag |
One marker name, without @. Expressions such as smoke and not slow aren’t supported. |
smoke |
| Class (nodeid) | class |
path/to/test_file.py::TestClass. For a test function outside a class, use path/to/test_file.py::test_function. |
tests/test_checkout.py::TestCheckout |
| Method (nodeid) | method |
A method in a class, as path/to/test_file.py::TestClass::test_method. |
tests/test_checkout.py::TestCheckout::test_pay_by_card |
| Directory / file | package |
A folder or file in the project. The path can’t contain .. and can’t start with / or .. |
tests/test_search.py |
| pytest.ini / conftest.py | configFile |
A pytest configuration file in the project. The scenario uses this file instead of the root configuration. | pytest.ini |
You can add up to 10 scenarios. Scenario names are limited to 50 characters, and selector values can be up to 256 characters.

The browser part runs on Chrome by default. To run it on Microsoft Edge, open the Advanced Settings tab and select Microsoft Edge under Select Browser.
After you finish configuring load parameters, click Save & Run Test. To save the test without running it, click Save Only.
Pass pytest flags to your test run
The UI Builder doesn’t show Run Command for hybrid tests. To add pytest flags, use the CLI and set runCommand inside the Playwright entry under tests.
Don’t set runCommand at the top level of browserstack-load.yml. The CLI applies a top-level runCommand to the API test too, and BrowserStack rejects the run.
The following configuration runs only the browser tests with the smoke marker:
For the flags that you can use, see Pass pytest flags to your test run in the browser load testing guide.
Prepare your project
Keep the requirements.txt file at the root of your project. The folder that contains requirements.txt is the folder that you zip and upload. The following example shows the structure of a project:
Before you zip your project, make the following changes:
- Open pages with the
page,context, orbrowserfixture. The load test settings select the browser, not your code. Achromium.launch()call connects to the virtual user’s browser, and BrowserStack ignores its launch options exceptslow_mo. Afirefox,webkit, orlaunch_persistent_context()call fails the iteration that runs it, and the load test keeps running. - Remove
-n,--numprocesses, and--distfromaddoptsin your pytest configuration. Each browser virtual user runs one pytest process. - Use paths relative to the project root. Your tests run from the project root, so absolute paths from your machine don’t exist during the load test.
- Leave out the
__pycache__/,.pytest_cache/,.venv/, andvenv/folders. The CLI excludes these folders automatically. The ZIP file size limit is 250 MB.
BrowserStack installs only the requirements.txt file at the project root. If you split your requirements into several files, reference the other files from the root file with -r, such as -r requirements-test.txt.
For a sample test, the minimum requirements.txt file, and custom test file names, see Prepare your project in the browser load testing guide.
Install packages from a private package index
BrowserStack sets the environment variables of your test before it installs your packages. To install packages from a private package index, follow these steps:
- Add the
PIP_INDEX_URLenvironment variable and set it to the URL of your index. To keep the public index as well, usePIP_EXTRA_INDEX_URLinstead. - If the URL contains a token, mask the variable. In the UI Builder, add the variable on the Env Variables tab and click the closed-eye icon next to it. In
browserstack-load.yml, setisMasked: truefor the variable. - Make sure that the index is reachable from the internet. If the index is behind a firewall, allowlist the BrowserStack load generator IP addresses. For the list of IP addresses, see Test private websites and APIs.
The following configuration installs packages from a private index and masks the token in its URL:
BrowserStack masks credentials and tokens in the pip output in the logs. For more information about masked variables, see Environment variables.
How BrowserStack runs your Python tests
Review the following behaviors before you analyze your test results:
- Setup: Before the load starts, each browser virtual user installs the packages in
requirements.txtand checks that pytest can collect your tests. Package installation must finish within 10 minutes, and test collection within 2 minutes. - Iterations: Each browser virtual user runs pytest once per iteration. A failed test fails only that iteration, and the virtual user starts the next iteration.
- Test timeout: Each test has a 90-second limit by default. To change the limit, add
pytest-timeouttorequirements.txtand settimeoutinpytest.ini. - Browser settings: Custom headers and the screen resolution of the load test apply to the
pageandcontextfixtures and to the contexts that your tests create, unless a test sets its own value. - Test data: To read a test data file, open it by its path in your project, such as
data/users.csv. Each virtual user reads its own slice of the file at that path. - Test results: The Tests tab isn’t available for Playwright Python tests yet.
Troubleshoot Python load tests
BrowserStack validates your project when you upload it and when the test starts. If a problem stops your project from running, BrowserStack blocks the upload. The following table lists the messages you might see:
| Message | How to fix |
|---|---|
| We couldn’t find a requirements.txt in your zip. | Add a requirements.txt file at the root of the folder that you zip, and upload the project again. |
| Your requirements.txt doesn’t list pytest-playwright. | Add pytest-playwright, or both playwright and pytest, to requirements.txt and upload the project again. |
| We couldn’t find any pytest test files in your zip. | Name your test files test_*.py or *_test.py, or set python_files in your pytest configuration. Then, upload the project again. |
The following table lists the warnings you might see when you upload your project:
| Warning | What to do |
|---|---|
| Your requirements.txt includes Selenium. Playwright - Pytest runs your Playwright tests only; Selenium code in this project won’t drive the load-test Chrome. To load test Selenium code, create a Selenium load test. | Remove the Selenium code from this project, or create a Selenium load test for it. |
Your requirements.txt includes <package>. Playwright - Pytest load tests support only the synchronous pytest-playwright fixtures, so async tests aren’t supported. Write your tests with the sync page fixture. |
Rewrite async tests with the synchronous page fixture, and remove pytest-asyncio or pytest-playwright-asyncio. |
| Your pytest config runs tests in parallel (-n). Each virtual user runs one pytest process, and the virtual-user count sets concurrency. Remove -n from addopts, or the test will fail when it starts. | Remove -n from addopts in your pytest configuration and upload the project again. |
<file> launches its own browser (<API>). Load tests redirect a Chromium launch to the load-test Chrome and ignore its launch options. Use the page fixture instead. |
Use the page fixture. The test still runs, but BrowserStack ignores the launch options. |
<file> launches its own browser (<API>). Load tests run every test in the load-test Chrome, so this call will fail. Use the page fixture instead. |
Replace the Firefox, WebKit, or launch_persistent_context() call with the page fixture. Otherwise, every iteration that runs this call fails. |
The following table lists the messages you might see when you run the test from the CLI:
| Message | How to fix |
|---|---|
| Playwright - Pytest tests require language set to python. | Set language to python, or remove the language key. |
Playwright - Pytest load tests install your project from requirements.txt. The first dependency file must be requirements.txt at the root of your project, but got <file>. Add ./requirements.txt as the first entry under files.dependencies and run again. |
Set ./requirements.txt as the first entry under files.dependencies. |
If setup fails, the run shows the Error status, and the Summary tab shows an Initialization error banner. AI Insights below the banner explains the cause and suggests a fix. The logs of the run contain the full pip or pytest output. The following table lists common problems, the messages in the logs, and how to fix them:
| Problem | Message in the logs | How to fix |
|---|---|---|
| Packages failed to install | [ERROR] [LTS-PYTEST] Dependency install failed: pip install -r requirements.txt (exit 1) |
Check the package names and versions in requirements.txt. Run pip install -r requirements.txt in a clean Python 3.10 environment and fix any errors. For a private index, check PIP_INDEX_URL and the network access to the package index. |
| Package installation timed out | [ERROR] [LTS-PYTEST] setup timeout after 600s (pip install) |
Remove unused packages from requirements.txt and pin their versions. Package installation must finish within 10 minutes. |
| Test collection timed out |
[ERROR] [LTS-PYTEST] setup timeout after 120s (test collection), with the message “Collecting your tests took longer than 2 minutes. Check for slow imports or network calls at import time, then run again.” |
Move network calls and slow setup out of import time, such as into fixtures. |
| No tests found |
[ERROR] [LTS-PYTEST] No tests collected, with the message “No tests were collected. Check the selector, the test paths and the pytest configuration, then run again.” |
Check the value of the scenario test selector, testpaths and python_files in your pytest configuration, and your marker names. |
| Tests failed to import |
[ERROR] [LTS-PYTEST] Test collection failed, with the message “pytest could not import or collect your tests. Fix the errors shown below, then run again.” The pytest output follows. |
Read the pytest output below the message. The cause is usually a syntax error, a package missing from requirements.txt, or a failed import in conftest.py. |
| Unsupported option |
[ERROR] [LTS-PYTEST] Unsupported option: <option>, such as parallel workers (pytest-xdist) or --browser firefox. Or Unsupported option or invalid pytest arguments. A line that says what to remove follows. |
Remove the option that the log names from addopts or runCommand. If the log says the pytest arguments are invalid, check runCommand and your pytest configuration for a typo or a nonexistent path. |
| Tests failed |
[LTS-PYTEST] Tests failed: 2 failed. The counts vary, such as 1 failed, 2 errors. |
Read the failed assertion in the pytest output. Under load, failures often come from timeouts, so increase your test timeout or your application’s capacity. If the output says Unsupported browser API, your test calls firefox, webkit, or launch_persistent_context(). Use the page, context, or browser fixture instead. Only that iteration fails. |
| Unexpected error | The test environment could not be prepared. This is a problem on our side; please contact support with the test ID. | Contact support with the test ID. If you pinned old versions of pytest, pytest-playwright, or Playwright, remove the pins and run the test again. |
If you run into issues, try the troubleshooting steps or contact us for help.
What’s next
- View hybrid test results: Review API and browser metrics from your test run in one place.
- Configure load parameters: Set load profiles, load zones, thresholds, and other run settings.
- Fail a load test on threshold breach: Stop a run and mark it as failed when a metric crosses its threshold.
- CI/CD integration: Run load tests automatically from your CI/CD pipeline.
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!

