Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

container:
# A Docker image with Semgrep installed. Do not change this.
image: returntocorp/semgrep:1.166.0
image: returntocorp/semgrep:1.166.0@sha256:c180f0c93a17b420c0af5006214a29d3c747c5459c732b740191adf657dd0068
# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
log
.DS_Store
20 changes: 20 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Supply-chain hardening directives (SC-12282), same set as the Playwright and
# WebdriverIO load-testing samples (LTS-3294 / LTS-3295).
# See: https://browserstack.atlassian.net/wiki/spaces/ENG/pages/6091571922/Supply+Chain+Security+Enhancements+Tech+Spec
#
# access=restricted is intentionally OMITTED — this is a public, customer-facing
# sample repository, not a published private package.
#
# ignore-scripts=true is safe: this sample has no install scripts of its own, and the
# tests run remotely on BrowserStack, so no local browser-driver postinstall is needed.
#
# engine-strict=true enforces the `engines.node` floors of this package (>=20) and of
# its dependencies (serialize-javascript needs >=20), so an older Node fails at install.

strict-ssl=true
save-exact=true
audit-level=high
legacy-peer-deps=false
ignore-scripts=true
engine-strict=true
min-release-age=7
Comment thread
MihirR-BS marked this conversation as resolved.
Resolved
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# browserstack-nightwatch-load-testing-sample
A sample repository demonstrating load testing with the Nightwatch framework
This repo contains samples for running [Nightwatch](https://nightwatchjs.org/) tests on BrowserStack Load Testing using the BrowserStack CLI.

![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)

## Setup

* 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](#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 i` to install the dependencies.
* Open the browserstack-load.yml file and update it with the relevant load test configurations.

## Set your credentials

The BrowserStack CLI reads your credentials from environment variables. Copy your username and access key from [Account Settings](https://www.browserstack.com/accounts/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:

```sh
export BROWSERSTACK_USERNAME="<your-username>"
printf 'BrowserStack access key: '; read -rs BROWSERSTACK_ACCESS_KEY; echo; export BROWSERSTACK_ACCESS_KEY
```

On Windows, run these in PowerShell. The second line prompts for the key in the same way:

```powershell
$env:BROWSERSTACK_USERNAME = "<your-username>"
$env:BROWSERSTACK_ACCESS_KEY = [System.Net.NetworkCredential]::new('', (Read-Host -AsSecureString 'BrowserStack access key')).Password
```

These 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.

## Running your tests

- Download the BrowserStack CLI for your operating system. The download is a zip: extract it and place the `browserstack-cli` binary (`browserstack-cli.exe` on Windows) in the root of this project. On macOS or Linux, also run `chmod +x browserstack-cli`, since some unzip tools drop the executable bit.
- [macOS x86](https://load-api.browserstack.com/api/v1/binary?os=macos&arch=x64)
- [macOS ARM](https://load-api.browserstack.com/api/v1/binary?os=macos&arch=arm64)
- [Windows x86](https://load-api.browserstack.com/api/v1/binary?os=win&arch=x64)
- [Linux x86](https://load-api.browserstack.com/api/v1/binary?os=linux&arch=x64)
- [Linux ARM](https://load-api.browserstack.com/api/v1/binary?os=linux&arch=arm64)
- Start your test:
- macOS / Linux: `./browserstack-cli load run`
- Windows (PowerShell): `.\browserstack-cli.exe load run`

## Notes
* You can view your test results on the [BrowserStack Load Testing dashboard](https://load.browserstack.com)
15 changes: 15 additions & 0 deletions browserstack-load.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
projectName: Default Project Name
testName: nightwatch_test
testType: Nightwatch
vus: 1
duration: 5m
regions:
- loadzone: us-east-1
percent: 100
files:
dependencies:
- package.json
testConfigs:
- nightwatch.conf.js
captureErrorResponses: false
headless: true
87 changes: 87 additions & 0 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Refer to the online docs for more details:
// https://nightwatchjs.org/gettingstarted/configuration/
//

// _ _ _ _ _ _ _
// | \ | |(_) | | | | | | | |
// | \| | _ __ _ | |__ | |_ __ __ __ _ | |_ ___ | |__
// | . ` || | / _` || '_ \ | __|\ \ /\ / / / _` || __| / __|| '_ \
// | |\ || || (_| || | | || |_ \ V V / | (_| || |_ | (__ | | | |
// \_| \_/|_| \__, ||_| |_| \__| \_/\_/ \__,_| \__| \___||_| |_|
// __/ |
// |___/

module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ['tests'],

// See https://nightwatchjs.org/guide/concepts/page-object-model.html
// page_objects_path: ['nightwatch/page-objects'],

// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
// custom_commands_path: ['nightwatch/custom-commands'],

// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
// custom_assertions_path: ['nightwatch/custom-assertions'],

// See https://nightwatchjs.org/guide/extending-nightwatch/adding-plugins.html
plugins: [],

// See https://nightwatchjs.org/guide/concepts/test-globals.html
globals_path: '',

webdriver: {},

test_workers: {
enabled: true
},

test_settings: {
default: {
disable_error_log: false,
launch_url: 'http://localhost',

screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},

desiredCapabilities: {
browserName: 'chrome'
},

webdriver: {
start_process: true,
server_path: ''
},

},

chrome: {
desiredCapabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
args: [
//'--no-sandbox',
//'--ignore-certificate-errors',
//'--allow-insecure-localhost',
//'--headless=new'
]
}
},

webdriver: {
start_process: true,
server_path: '',
cli_args: [
// --verbose
]
}
},

},

};
Loading
Loading