Test Observability on Mocha JS
Quick start guide to integrate BrowserStack Test Observability with Mocha JS
Prerequisites
- You have an account with BrowserStack (even a free trial works) and can get the Username and Access Key from your account profile.
- You have a Mocha JS test suite (it is okay even if you do not run your tests on BrowserStack infrastructure).
Integrate with Test Observability
You can use BrowserStack Test Observability both when you’re using BrowserStack’s devices and browsers to run your tests and also if you’re running tests locally on your laptop/CI system or even when you’re using some other cloud provider.
Please select your setup below to get started with an awesome debugging experience with Test Observability:
Follow these steps to start using BrowserStack Test Observability with your existing setup of Mocha JS tests running on BrowserStack Automate or App Automate:
Install the latest version of the browserstack-node-sdk npm package
You’d need to install/update the browserstack-node-sdk
as shown below:
Please ensure that you have at least browserstack-node-sdk v1.32.2
before proceeding.
npm install browserstack-node-sdk@latest
npm list browserstack-node-sdk
Make changes to the SDK config file
If you’ve installed the browserstack-node-sdk
for the first time, you’d have to create the browserstack.yml
file shown below. Else, just verify that your config file has all the required key-value pairs.
Create a browserstack.yml
file in the root folder of your test suite if it doesn’t exist.
The projectName
and buildName
config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate as Test Observability will automatically identify different build runs.
Restrict the characters in your projectName
and buildName
to alphanumeric characters (A-Z, a-z, 0-9), underscores (_), colons (:), and hyphens (-). Any other character will be replaced with a space.
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
buildName: "Your static build/job name goes here"
projectName: "Your static project name goes here"
CUSTOM_TAG_1: "You can set a custom Build Tag here"
# Use CUSTOM_TAG_<N> and set more build tags as you need.
...
BrowserStack SDK is a very powerful tool that you can use to set the different browser/device combinations and parallelization. For more details, check out the Automate integration guide or the App Automate integration guide
Run your suite with BrowserStack Test Observability
Prepend browserstack-node-sdk
to the existing command that you use to trigger a run and data will automatically start getting sent to BrowserStack Test Observability.
npx browserstack-node-sdk "Your existing command for running test suite. E.g. <mocha mocha/specs/e2e/*/bdd/*.e2e.js --timeout=60000>"
Note: In case you’ve used double quotes in the command (" ")
after browserstack-node-sdk
, ensure you remove them. Otherwise, you might get the following error: Not a valid command. Check help and provide a valid command.
Post build run completion, you will see the build URL of Test Observability in your console. Alternatively, you can also navigate to your build run using Build Runs.
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!