Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shirish87/browserstack-client
node.js API client for BrowserStack APIs.
https://github.com/shirish87/browserstack-client
Last synced: about 2 months ago
JSON representation
node.js API client for BrowserStack APIs.
- Host: GitHub
- URL: https://github.com/shirish87/browserstack-client
- Owner: shirish87
- License: mit
- Created: 2015-07-19T07:52:57.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T11:53:17.000Z (7 months ago)
- Last Synced: 2024-11-14T02:17:16.487Z (2 months ago)
- Language: TypeScript
- Homepage: http://shirish87.github.io/browserstack-client/
- Size: 2.12 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BrowserStack Client
This module interfaces all REST APIs offered by [BrowserStack](https://www.browserstack.com).
![Build Status](https://github.com/shirish87/browserstack-client/actions/workflows/main.yml/badge.svg)
## Installation
```
$ npm i --save-dev browserstack-client
```## Requirements
Please ensure that your BrowserStack account contains the required subscription(s) for using the APIs provided by this module.
Add your BrowserStack username and API key to the following environment variables for your shell.
You may also supply these credentials in code when creating an instance of an API client. See `options.username` and `options.key`.
```
BROWSERSTACK_USERNAME=
BROWSERSTACK_KEY=
```Basic features require [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) support in your JavaScript runtime (`globalThis.fetch`).
Additional features (running [BrowserStackLocal](https://www.browserstack.com/docs/local-testing/releases-and-downloads) binary) require node.js runtime.
## Basic Usage
```ts
// index.mjs
import { BrowserStack } from "browserstack-client";// set environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_KEY
// BrowserStack JavaScript Testing API
const jsTestingClient = new BrowserStack.JSTestingClient();
/* ...or
const jsTestingClient = new BrowserStack.JSTestingClient({
username: "",
key: "",
});
*/console.log(await jsTestingClient.getAccountStatus());
// BrowserStack Automate API
const automateClient = new BrowserStack.AutomateClient();
console.log(await automateClient.getPlan());// BrowserStack App Automate API
const appAutomateClient = new BrowserStack.AppAutomateClient();
console.log(await appAutomateClient.getPlan());// BrowserStack Screenshots API
const screenshotsClient = new BrowserStack.ScreenshotsClient();
console.log(await screenshotsClient.getBrowsers());// BrowserStack Local Testing API
const localTestingClient = new BrowserStack.LocalTestingClient();
console.log(await localTestingClient.getBinaryInstances());
```## Additional Features
Some features leverage node.js built-in modules (`node:*`) that may not be available in other JavaScript runtimes (such as [Deno](https://deno.com)).
These are bundled separately along with all basic features from above.
```js
// index.mjs
import { BrowserStack } from "browserstack-client/node";const localTestingBinary = new BrowserStack.LocalTestingBinary({
key: "", // or set environment variable BROWSERSTACK_KEY
binHome: "", // or set environment variable BROWSERSTACK_LOCAL_BINARY_PATH
});console.log(await localTestingBinary.start());
console.log(await localTestingBinary.stop());
```## Deno Sample
```ts
/**
* @run --allow-read --allow-net --allow-env index.ts
*/import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
import { BrowserStack } from "https://esm.sh/browserstack-client@latest";const env = await load();
const options = {
username: env.BROWSERSTACK_USERNAME,
key: env.BROWSERSTACK_KEY,
};// BrowserStack JavaScript Testing API
const jsTestingClient = new BrowserStack.JSTestingClient(options);
console.log(await jsTestingClient.getAccountStatus());
```## Documentation
Please refer to the [documentation](https://shirish87.github.io/browserstack-client/api/globals.html) for methods available for each of these clients.
## Proxy Support
```
npm install node-fetch
npm install proxy-agent // or proxy specific https-proxy-agent (see docs)
```
* Docs for [node-fetch](https://www.npmjs.com/package/node-fetch#custom-agent)
* Docs for [proxy-agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent)```js
// index.mjs
import { JSTestingClient } from "browserstack-client";
import fetch from "node-fetch";
import { ProxyAgent } from "proxy-agent";// Docs:
// https://www.npmjs.com/package/node-fetch#custom-agent
// https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agentconst agent = new ProxyAgent();
// BrowserStack JavaScript Testing API
const jsTestingClient = new JSTestingClient({
username: "",
key: "",
// provide your own Fetch API implementation
fetch: (url, init) => fetch(url, { ...init, agent }),
});console.log(await jsTestingClient.getAccountStatus());
```
## Thanks
Sponsored access to [BrowserStack](https://www.browserstack.com/), courtesy BrowserStack.