Integrate Your Test Suite with BrowserStack
This section will help you migrate your existing test suite to run on BrowserStack Automate. It also covers key features and best practice recommendations for smooth integration.
Step 1: 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',
};
For a production-grade integration we recommend you store your credentials as environment variables and use those environment variables in your test script.
Step 2: Connect CDP endpoint
Connect to the CDP endpoint at BrowserStack as shown:
Import the required method
const { getCdpEndpoint } = require('./browserstack.config.js')
The CDP Endpoint calls the getCdpEndpoint
method defined in the browserstack.config.js
which further calls the BrowserStack CDP.
Step 3: Set platforms to test on
Set the browsers/devices you want to test in the playwright.config.js
file.
projects: [
{
name: 'chrome@latest:Windows 11',
use: {
connectOptions: { wsEndpoint: getCdpEndpoint('chrome@latest:Windows 11','test1') },
},
}
,
{
name: 'playwright-webkit@latest:OSX Ventura',
use: {
connectOptions: { wsEndpoint: getCdpEndpoint('playwright-webkit@latest:OSX Ventura', 'test2') }
},
},
{
name: 'playwright-firefox:Windows 11',
use: {
connectOptions: { wsEndpoint: getCdpEndpoint('playwright-firefox:Windows 11', 'test3') }
},
}
],
Step 4: Set capabilities
Naming your tests and builds properly is crucial for effective debugging, test reporting, and analyzing your build execution time. Here are the capabilities you can use.
Capability | Description |
---|---|
name |
Name for your test case. Example, Homepage - Get started |
build |
CI/CD job or build name. Example, Website build #23, staging_1.3.27 |
project |
Name of your project. Example, Marketing Website |
const caps = {
browser: 'chrome',
os: 'osx',
os_version: 'catalina',
name: 'My first playwright test',
build: 'playwright-build',
'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
'client.playwrightVersion': clientPlaywrightVersion,
};
Step 5: Enable BrowserStack Local
Test localhost / internal servers in your network
const caps = {
'browserstack.local': process.env.BROWSERSTACK_LOCAL || true,
};
Step 6: Set up debugging capabilities
BrowserStack provides the following debugging capabilities for your tests:
- Use visual logs capability to capture screenshots at every Playwright command automatically. You can enable visual logs by using the
browserstack.debug
capability. - Network Logs capture the browser’s performance data such as network traffic, latency, HTTP requests, and responses in a HAR format. You can enable network logs using the
browserstack.networkLogs
capability.
Enable these debugging capabilities as shown in the following code example:
const caps = {
"browserstack.debug" : "true",
"browserstack.networkLogs" : "true",
}
Step 7: Run your test suite
Run the test command from the project’s root directory to execute your test suite with BrowserStack.
Step 8: View your test result
View your tests on the BrowserStack Automate dashboard. To learn more about the dashboard, check the view test results document.
Next Steps
Once you have successfully integrated your test suite with BrowserStack, you might want to check the following:
- Learn how to test localhost and staging websites
- Set browser options
- Select Playwright version
- Run test from behind a proxy
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!