This repo contains samples for running Nightwatch tests on BrowserStack Load Testing using the BrowserStack CLI.
- Clone the repo
git clone https://github.com/browserstack/browserstack-nightwatch-load-testing-sample.git. - Set your credentials as environment variables, as described in Set your credentials.
- Use Node.js 20 or later. For the seven-day release-age policy in
.npmrc, also use npm 11.10 or later (npm install -g npm@11.10.0, which needs Node.js 20.17+ or 22.9+); older npm ignores that policy. - Run
npm ito install the dependencies. - Open the browserstack-load.yml file and update it with the relevant load test configurations.
The BrowserStack CLI reads your credentials from environment variables. Copy your username and access key from Account Settings and export them in the shell you run the test from:
On macOS or Linux (bash or zsh), run the lines below. The second one prompts for the key without echoing it, so the key stays out of your shell history:
export BROWSERSTACK_USERNAME="<your-username>"
printf 'BrowserStack access key: '; read -rs BROWSERSTACK_ACCESS_KEY; echo; export BROWSERSTACK_ACCESS_KEYOn Windows, run these in PowerShell. The second line prompts for the key in the same way:
$env:BROWSERSTACK_USERNAME = "<your-username>"
$env:BROWSERSTACK_ACCESS_KEY = [System.Net.NetworkCredential]::new('', (Read-Host -AsSecureString 'BrowserStack access key')).PasswordThese variables last only for the current terminal session. If the CLI reports an authentication error, check that both are set in the terminal you run it from.
Never commit your credentials. Keep your access key out of browserstack-load.yml and every other file you push. If a key is ever exposed, regenerate it from Account Settings.
- Download the BrowserStack CLI for your operating system. The download is a zip: extract it and place the
browserstack-clibinary (browserstack-cli.exeon Windows) in the root of this project. On macOS or Linux, also runchmod +x browserstack-cli, since some unzip tools drop the executable bit. - Start your test:
- macOS / Linux:
./browserstack-cli load run - Windows (PowerShell):
.\browserstack-cli.exe load run
- macOS / Linux:
- You can view your test results on the BrowserStack Load Testing dashboard
