This monorepo contains TypeScript clients for all REST APIs offered by BrowserStack.
Install the specific product client you need:
# Automate
$ npm i @dot-slash/browserstack-automate
# App Automate
$ npm i @dot-slash/browserstack-app-automate
# Accessibility
$ npm i @dot-slash/browserstack-accessibility
# Test Management
$ npm i @dot-slash/browserstack-test-management
# Local Testing (API & Binary)
$ npm i @dot-slash/browserstack-local-testing-api @dot-slash/browserstack-local-testing- Node.js: 20.0.0 or higher.
- BrowserStack Account: Please ensure that your BrowserStack account contains the required subscription(s) for using the APIs provided by these modules.
Add your BrowserStack username and API key to the following environment variables for your shell:
BROWSERSTACK_USERNAME=<your-username>
BROWSERSTACK_ACCESS_KEY=<your-access-key>You may also supply these credentials in code when creating an instance of an API client.
Each client is exported from its own package:
import { AutomateClient } from "@dot-slash/browserstack-automate";
import { AccessibilityClient } from "@dot-slash/browserstack-accessibility";
import { AppAutomateClient } from "@dot-slash/browserstack-app-automate";
import { TestManagementClient } from "@dot-slash/browserstack-test-management";
// BrowserStack Automate API
const automateClient = new AutomateClient();
const plan = await automateClient.getPlan();
console.log(plan);
// BrowserStack Accessibility API
const accessibilityClient = new AccessibilityClient();
const reports = await accessibilityClient.getWorkflowAnalyzerReports();
console.log(reports);
// BrowserStack Test Management API
const tmClient = new TestManagementClient();
const projects = await tmClient.getProjects();
console.log(projects);import { AppAutomateClient } from "@dot-slash/browserstack-app-automate";
const appAutomateClient = new AppAutomateClient();
const projects = await appAutomateClient.getProjects();
const builds = await appAutomateClient.getBuilds(projects[0].id);
console.log(builds);import { TestReportingClient } from "@dot-slash/browserstack-test-reporting";
const trClient = new TestReportingClient();
const build = await trClient.startBuild({
projectName: "my-project",
buildName: "my-build",
framework: "playwright",
});
// ... run tests, report results ...
await trClient.finishBuild(build.buildHashedId, { status: "passed" });import { ScreenshotsClient } from "@dot-slash/browserstack-screenshots";
const screenshotsClient = new ScreenshotsClient();
const screenshots = await screenshotsClient.launch(
{
url: "https://example.com",
browsers: [{ browser: "chrome", browser_version: "latest", os: "Windows", os_version: "11" }],
},
(screenshot) => console.log("captured:", screenshot.imageUrl)
);The monorepo also provides a unified CLI for interacting with various BrowserStack products and managing Local Testing:
# List projects in Automate
$ npx @dot-slash/browserstack-cli automate list-projects
# List Accessibility workflow analyzer reports
$ npx @dot-slash/browserstack-cli accessibility workflow-analyzer list
# Local Testing
$ npx @dot-slash/browserstack-cli local start
$ npx @dot-slash/browserstack-cli local stop
$ npx @dot-slash/browserstack-cli local list
# Run a command with Local Testing automatically managed
$ npx @dot-slash/browserstack-cli local run-with -- npm testRunning the BrowserStackLocal binary requires the @dot-slash/browserstack-local-testing package.
import { LocalTestingBinary } from "@dot-slash/browserstack-local-testing";
const localTestingBinary = new LocalTestingBinary({
accessKey: "<your-access-key>",
});
await localTestingBinary.start();
// ... run tests ...
await localTestingBinary.stop();Please refer to the documentation for methods available for each of these clients.
Sponsored access to BrowserStack, courtesy BrowserStack.