Appearance
browserstack-client • Readme | API
browserstack-client / JSTestingClient
Class: JSTestingClient
Represents a client for interacting with the BrowserStack JavaScript Testing API.
Index
getAccountStatus — Retrieves the account status.
getBrowsers — Retrieves a list of browsers from the server.
createWorker — Creates a worker for JS testing.
getWorkers — Retrieves a list of workers.
getWorker — Retrieves a worker by its ID.
deleteWorker — Deletes a worker by worker ID.
updateWorkerURL — Updates the URL of a worker.
getWorkerScreenshot — Takes a screenshot of a worker.
ensureWorkerRunning — Awaits a worker with the specified workerId to attain "running" status.
launch — High-level abstraction for launching a worker-browser with the specified options.
See
https://www.browserstack.com/docs/automate/javascript-testing/api
Extends
APIClient
Constructors
new JSTestingClient(options)
new JSTestingClient(
options?):JSTestingClient
Constructs a new instance of the JSTestingClient class.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | BrowserStackOptions | Optional configuration options for the client. |
Returns
Overrides
APIClient.constructor
Source
Methods
getAccountStatus()
getAccountStatus():
Promise<Object>
Retrieves the account status.
Returns
Promise<Object>
A Promise that resolves to the account status.
Member Type Description used_timenumberExample 10running_sessionsnumberExample 0session_limitnumberExample 0total_available_timestringExample Unlimited Testing Time
Source
getBrowsers()
getBrowsers(query, options)
getBrowsers<
T>(query?,options?):Promise<Object&Object[]>
Retrieves a list of browsers from the server.
Type parameters
| Type parameter |
|---|
T extends true |
Parameters
| Parameter | Type | Description |
|---|---|---|
query? | Object & Object | - |
options? | APIFetchOptions<Object> | The fetch options for the request. |
Returns
Promise<Object & Object[]>
A promise that resolves to a fetch response containing the list of browsers.
Source
getBrowsers(query, options)
getBrowsers<
T>(query?,options?):Promise<Object>
Retrieves a list of browsers from the server.
Type parameters
| Type parameter |
|---|
T extends false |
Parameters
| Parameter | Type | Description |
|---|---|---|
query? | Object & Object | - |
options? | APIFetchOptions<Object> | The fetch options for the request. |
Returns
Promise<Object>
A promise that resolves to a fetch response containing the list of browsers.
Member Type WindowsObjectWindows.7Object&Object[]Windows.8Object&Object[]Windows.10Object&Object[]Windows.11Object&Object[]Windows.XPObject&Object[]Windows.8.1Object&Object[]OS XObjectOS X.Snow LeopardObject&Object[]OS X.LionObject&Object[]OS X.Mountain LionObject&Object[]OS X.MavericksObject&Object[]OS X.YosemiteObject&Object[]OS X.El CapitanObject&Object[]OS X.SierraObject&Object[]OS X.High SierraObject&Object[]OS X.MojaveObject&Object[]OS X.CatalinaObject&Object[]OS X.Big SurObject&Object[]OS X.MontereyObject&Object[]OS X.VenturaObject&Object[]OS X.SonomaObject&Object[]OS X.additionalPropertiesObject&Object[]winphoneObjectwinphone.8.1Object&Object[]androidObjectandroid.14.0Object&Object[]android.13.0Object&Object[]android.12.0Object&Object[]android.11.0Object&Object[]android.10.0Object&Object[]android.9.0Object&Object[]android.8.1Object&Object[]android.8.0Object&Object[]android.7.1Object&Object[]android.7.0Object&Object[]android.6.0Object&Object[]android.5.0Object&Object[]android.4.4Object&Object[]android.4.3Object&Object[]android.4.2Object&Object[]android.4.1Object&Object[]android.4.0Object&Object[]android.2.3Object&Object[]android.2.2Object&Object[]android.additionalProperties( Object&Object|Object&Object)[]
Source
createWorker()
createWorker(
body,options?):Promise<Object>
Creates a worker for JS testing.
Parameters
| Parameter | Type | Description |
|---|---|---|
body | Object & Object | Object | The request body. |
options? | APIFetchOptions<Object> | The API fetch options. |
Returns
Promise<Object>
A promise that resolves to the worker response.
Member Type Description idnumberDescription
ID of the worker
Example122326697urlstringDescription
URL of the worker
Examplehttps://www.google.com/ncr
Source
getWorkers()
getWorkers(
options?):Promise<Object&Object&Object[]>
Retrieves a list of workers.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | APIFetchOptions<Object> | Optional parameters for the API request. |
Returns
Promise<Object & Object & Object[]>
A promise that resolves to an array of Worker objects.
Source
getWorker()
getWorker(
workerId,options?):Promise<Object&Object&Object>
Retrieves a worker by its ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker. |
options? | APIFetchOptions<Object> | Additional options for the API request. |
Returns
Promise<Object & Object & Object>
A Promise that resolves to the retrieved worker.
Source
deleteWorker()
deleteWorker(
workerId,options?):Promise<Object>
Deletes a worker by worker ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker to delete. |
options? | APIFetchOptions<Object> | Optional API fetch options. |
Returns
Promise<Object>
A promise that resolves when the worker is deleted.
Member Type Description messagestringDescription
Status of the termination operation
Exampleworker is running for 19.405956957 secs, minimum life is 30 sectimenumberDescription
Duration of the worker
Example45.786373558
Source
updateWorkerURL()
updateWorkerURL(
workerId,body,options?):Promise<Object>
Updates the URL of a worker.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker. |
body | Object | The request body containing the updated URL. |
body.url | string | Description New URL for the worker Example https://www.google.com/ncr |
options? | APIFetchOptions<Object> | Optional API fetch options. |
Returns
Promise<Object>
A promise that resolves with the response from the server.
Member Type Description messagestringDescription
Status of the update URL operation
ExampleBrowser updated with new url
Source
getWorkerScreenshot()
getWorkerScreenshot(workerId, format, options)
getWorkerScreenshot(
workerId,format,options?):Promise<ArrayBuffer>
Takes a screenshot of a worker.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker. |
format | "png" | The format of the screenshot (e.g., "png", "json", "xml"). |
options? | APIFetchOptions<Object> | Additional options for the API request. |
Returns
Promise<ArrayBuffer>
A Promise that resolves to the screenshot data.
Source
getWorkerScreenshot(workerId, format, options)
getWorkerScreenshot(
workerId,format,options?):Promise<Object>
Takes a screenshot of a worker.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker. |
format | "json" | The format of the screenshot (e.g., "png", "json", "xml"). |
options? | APIFetchOptions<Object> | Additional options for the API request. |
Returns
Promise<Object>
A Promise that resolves to the screenshot data.
Member Type urlstring
Source
getWorkerScreenshot(workerId, format, options)
getWorkerScreenshot(
workerId,format,options?):Promise<string>
Takes a screenshot of a worker.
Parameters
| Parameter | Type | Description |
|---|---|---|
workerId | number | The ID of the worker. |
format | "xml" | The format of the screenshot (e.g., "png", "json", "xml"). |
options? | APIFetchOptions<Object> | Additional options for the API request. |
Returns
Promise<string>
A Promise that resolves to the screenshot data.
Source
ensureWorkerRunning()
ensureWorkerRunning(
workerId,options?,pollInterval?):Promise<Object&Object&Object>
Awaits a worker with the specified workerId to attain "running" status.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
workerId | number | undefined | The ID of the worker to retrieve. |
options? | APIFetchOptions<Object> | undefined | Optional API fetch options. |
pollInterval? | number | 10_000 | The interval (in milliseconds) at which to poll for the worker status. Default is 10000ms. |
Returns
Promise<Object & Object & Object>
A promise that resolves with the running worker.
Source
launch()
launch(
body,options?):Promise<Object>
High-level abstraction for launching a worker-browser with the specified options.
Parameters
| Parameter | Type | Description |
|---|---|---|
body | Object & Object | Object | The request body for creating the worker. |
options? | APIFetchOptions<Object> & Object | The options for creating the worker. |
Returns
Promise<Object>
A promise that resolves to the launched worker.
Member Type Value Description browserstring- Example Chromebrowser_versionstring- Example 80.0osstring- Example Windowsos_versionstring- Example 10devicestring- Example nullreal_mobileboolean- Example nullidnumber- Description
ID of the worker.
Example122326697sessionIdunknown- Description
ID of the session.
Example550709149fe79e949363b581e774d5ebffa1b8festatus"running"|"queue"- Description
Current status of the worker.
Examplerunning @enum {string}browser_urlstring- Description
Dashboard URL of the session
ExampleupdateURL( url) =>Promise<Object>- - getScreenshot() => Promise<ArrayBuffer>- - getScreenshotURL() => Promise<string>- - terminate() => Promise<Object>- -