Learn how to test localhost and staging websites
A guide to running your Playwright test on localhost and staging websites.
BrowserStack can integrate with test suites pointing to your localhost URL, staging environment, and even websites behind one or more proxies/firewalls. This is done using BrowserStack Local - a tunneling feature that establishes a secure connection between your machine and the BrowserStack Cloud.
Run your first local test
Run this sample test to check if BrowserStack Local is working as expected and can connect to BrowserStack servers.
Step 1: Clone sample git repository
Clone the node-js-playwright-browserstack sample repo on GitHub using the following command:
git clone https://github.com/browserstack/node-js-playwright-browserstack.git
cd node-js-playwright-browserstack
Step 2: Set BrowserStack credentials
Set environment variables for BrowserStack credentials as follows:
# Set these values in your ~/.zprofile (zsh) or ~/.profile (bash)
export BROWSERSTACK_USERNAME="YOUR_USERNAME"
export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"
# setx.exe does not set the environment variable in the current command prompt, but it will be available in subsequent command prompts
setx BROWSERSTACK_USERNAME "YOUR_USERNAME"
setx BROWSERSTACK_ACCESS_KEY "YOUR_ACCESS_KEY"
# Verify whether the variables have been set
echo BROWSERSTACK_USERNAME
echo BROWSERSTACK_ACCESS_KEY
Alternatively, you can also add your BrowserStack credentials in the test cases as shown in the following example:
const caps = {
'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
};
Step 3: Install the dependencies
Install dependencies using the following command:
npm install
Step 4: Set Local capability to true
Ensure the browserstackLocal
property is set to true in your browserstack.config.js
config file. You can now test your private websites on BrowserStack.
const caps = {
'browserstack.local': process.env.BROWSERSTACK_LOCAL || true,
};
Step 5: Execute build on BrowserStack
From the root directory of this project, run the following command:
npm run sample-local-test
Additional configuration
BrowserStack Local works out of the box in most cases, but depending on the URL being tested and your network setup, additional configuration may be needed. Here are the most frequently occurring scenarios:
The URL being tested is accessible from the internet but serves different content within your internal network.
This is common with staging environments set up as sub-domains and configured to work only in your private/VPN network. In this case, run the following command:
./BrowserStackLocal --key <your_access_key> --force-local
The given command will resolve all network traffic through the BrowserStack Local tunnel.
localhost
from a config file for example. In this case, we recommend honoring relative URLs in your web application as a best practice; or handling this case as you deem fit.
Bypass invalid certificate browser warnings
To avoid invalid certificate errors while testing on our remote browsers, set the acceptInsecureCerts
capability at the root level in your browserstack.config.js
file.
const caps = {
acceptInsecureCerts: true
};
Next Steps
- Migrate your existing test suites to run on BrowserStack
- Run your CodeceptJS Playwright tests on BrowserStack
- Run your Jest Playwright tests on BrowserStack
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!