Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
Load testing with Selenium Jest
Run a load test using Selenium with Jest scripts on BrowserStack Load Testing
Prerequisites
BrowserStack Username and Access key. You can find these under your account profile.
An existing automated test suite written in Selenium with Jest (Node.js 18 or later).
A package.json file at the root of your project that declares jest and a Selenium WebDriver package (for example, selenium-webdriver).
Before you zip and upload your project, replace any local WebDriver instances with a RemoteWebDriver call so the tests run against the BrowserStack hub. For example, change new Builder().forBrowser('chrome').build() to new Builder().usingServer('http://localhost:4444/wd/hub').forBrowser('chrome').build().
Supported versions
The following framework versions are recommended for Selenium Jest load tests:
Framework
Node version
Recommended version
Selenium Jest
Node.js 21
Selenium WebDriver 4.25.0 Jest 29.7.0
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.
Enter a Test Name for your load test, select Browser Only and click Upload scripts.
Upload scripts
In this step, upload your Selenium Jest automation project as a ZIP file. Select Selenium - Jest from the framework dropdown, then drag and drop your ZIP file (up to 250 MB) or click to select it.
After you upload your ZIP file, the dashboard automatically validates your project. If validation is successful, you see a confirmation message and a summary of the detected dependencies.
From the Select dependencies dropdown, select your package.json file to specify which dependencies to install for your tests.
Ensure that your package.json sits at the root level of your project and declares both jest and a Selenium WebDriver package (for example, selenium-webdriver).
Jest discovers tests by naming convention: files matching *.test.js, *.spec.js, or files inside a __tests__/ directory. You do not need to set a run target. To narrow the discovery set, use testMatch or testPathIgnorePatterns in your jest.config.js.
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. Use our Selenium Jest load testing sample project to quickly get started.
You can configure the following load parameters to customize your load test:
Save your BrowserStack credentials as environment variables. It simplifies running your Selenium Jest load test suite from your local or CI environment.
The Load Testing CLI is bundled with the BrowserStack Node.js SDK. If you have already installed the SDK, you can skip this step.
Initialize your project for load testing
Run the following command from the root directory of your Selenium Jest test project to generate the browserstack-load.yml file, which contains the configuration required to define and run your load test.
```bash
npx browserstack-cli load init --framework jest --language nodejs
```
Refer to the given table to use the framework and language combination argument:
Framework
Argument
Selenium - Jest
--framework jest --language nodejs
Configure your Load Test
Open the generated browserstack-load.yml file and update it with the relevant Selenium Jest 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 a Selenium test suite.
Specify the language
Set the language to nodejs.
Specify the test framework
Set the framework to jest.
Specify the path to your dependency file
The files block specifies the key files required to install dependencies and define which tests to execute.
Under dependencies, add the path to your package.json file. BrowserStack uses this file to run npm install before invoking Jest.
You do not need to specify a runTarget. Jest auto-discovers tests using its naming convention (*.test.js, *.spec.js, or files inside a __tests__/ directory). To narrow the test set, configure testMatch or testPathIgnorePatterns in your jest.config.js file.
Ensure all referenced files are relative to the project root.
Do not include the node_modules directory in your ZIP. BrowserStack runs npm install from your package.json before invoking npx jest, so any pre-bundled node_modules is redundant and counts against the 250 MB upload limit.
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.
You can configure the following load parameters to customize your load test:
```yml
# =============================
# Set Credentials and Identity
# =============================
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
projectName: Default Project # Tests under the same projectName will be grouped together.
testName: Default Test # Test runs with the same testName will be grouped together.
# =========================================
# Set Configuration for Browser Load Tests (Required)
# =========================================
testType: Selenium
language: nodejs # Programming language used in your project
framework: jest # Test framework
files:
dependencies:
- ./package.json
# ======================
# Set Load Configuration
# ======================
# Add Mandatory values for a test run (vus, duration, regions)
vus: 5 # Virtual user count
duration: 10m # Example: '2m', '3m40s'
regions:
# Percent should total 100 across all loadzones
- loadzone: us-east-1
percent: 50
- loadzone: us-west-1
percent: 50
# Refer to the Load Testing documentation to add advanced features to your test: https://www.browserstack.com/docs/load-testing
```
Before running a full-scale load test, do a sanity check with a small set of virtual users to validate your Selenium Jest configuration and test stability.