This sample shows how to run Jest + Playwright tests on BrowserStack using the BrowserStack Node SDK. The SDK reads browserstack.yml, fans your tests out across the platforms listed there, starts and stops BrowserStack Local automatically, and reports test status to the BrowserStack dashboard. Your test code stays plain @playwright/test + Jest -- no manual connect(), no capabilities in code.
- Node.js 18, 20, or 22 LTS, and npm (verified on Node 20)
- A BrowserStack account -- grab your Username and Access Key
-
Clone the repo
-
Install dependencies:
npm install
-
Add your credentials to
browserstack.yml(replaceYOUR_USERNAME/YOUR_ACCESS_KEY), or remove those two lines and export them as environment variables instead:export BROWSERSTACK_USERNAME=<browserstack-username> export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
Runs the public bstackdemo.com add-to-cart scenario across every platform in browserstack.yml:
npm run sample-testUse this when the site under test is on localhost, a staging host, or behind a firewall. BrowserStack Local opens a secure tunnel and resolves bs-local.com back to your machine, so the cloud browser can reach a page only you can serve.
The bundled local test navigates to http://bs-local.com:45454/ and asserts the page title contains BrowserStack Local — so you must have something serving that page on port 45454 first:
-
Serve a matching page locally (any page whose
<title>contains "BrowserStack Local" satisfies the test):mkdir -p bs-local-site && printf '<!doctype html><title>BrowserStack Local</title><body>OK</body>' > bs-local-site/index.html (cd bs-local-site && python3 -m http.server 45454) &
To test your own app instead, serve it on port
45454(or change the port and the title assertion intests/bstack_local_test.test.js). -
Set
browserstackLocal: trueinbrowserstack.yml. -
Run:
npm run sample-local-test
The SDK starts and stops the BrowserStack Local tunnel for you -- no manual binary download or lifecycle management. The tunnel routes bs-local.com:45454 to your machine's localhost:45454.
- One
browserstack.ymldeclares platforms, parallelism, the Local toggle, and reporting; the SDK picks them up automatically. - The SDK runs platforms in parallel for you -- one Jest run per
(platform x parallelsPerPlatform)cell, no per-platform branching needed. - The SDK rewrites Playwright launches -- your test calls
chromium.launch()and the SDK transparently redirects it to the per-platform browser configured in the yml (chrome/playwright-webkit/playwright-firefox). Nochromium.connect(wss_url)plumbing. - The SDK starts and stops BrowserStack Local when
browserstackLocal: true.
.
├── browserstack.yml # SDK config: credentials, platforms, Local toggle, reporting
├── package.json # SDK run scripts + deps
├── jest.config.js # sample test config (bstackdemo)
├── jest.local.config.js # local test config (bs-local)
└── tests/
├── bstack_sample.test.js # bstackdemo add-to-cart scenario
└── bstack_local_test.test.js # BrowserStack Local scenario
- View your test results on the BrowserStack Automate dashboard.
- To test on a different set of browsers, see our list of supported browsers and platforms.
- Understand how many parallel sessions you need with the Parallel Test Calculator.
Happy Testing!
