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_time
number
Example 10
running_sessions
number
Example 0
session_limit
number
Example 0
total_available_time
string
Example 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 Windows
Object
Windows.7
Object
&Object
[]Windows.8
Object
&Object
[]Windows.10
Object
&Object
[]Windows.11
Object
&Object
[]Windows.XP
Object
&Object
[]Windows.8.1
Object
&Object
[]OS X
Object
OS X.Snow Leopard
Object
&Object
[]OS X.Lion
Object
&Object
[]OS X.Mountain Lion
Object
&Object
[]OS X.Mavericks
Object
&Object
[]OS X.Yosemite
Object
&Object
[]OS X.El Capitan
Object
&Object
[]OS X.Sierra
Object
&Object
[]OS X.High Sierra
Object
&Object
[]OS X.Mojave
Object
&Object
[]OS X.Catalina
Object
&Object
[]OS X.Big Sur
Object
&Object
[]OS X.Monterey
Object
&Object
[]OS X.Ventura
Object
&Object
[]OS X.Sonoma
Object
&Object
[]OS X.additionalProperties
Object
&Object
[]winphone
Object
winphone.8.1
Object
&Object
[]android
Object
android.14.0
Object
&Object
[]android.13.0
Object
&Object
[]android.12.0
Object
&Object
[]android.11.0
Object
&Object
[]android.10.0
Object
&Object
[]android.9.0
Object
&Object
[]android.8.1
Object
&Object
[]android.8.0
Object
&Object
[]android.7.1
Object
&Object
[]android.7.0
Object
&Object
[]android.6.0
Object
&Object
[]android.5.0
Object
&Object
[]android.4.4
Object
&Object
[]android.4.3
Object
&Object
[]android.4.2
Object
&Object
[]android.4.1
Object
&Object
[]android.4.0
Object
&Object
[]android.2.3
Object
&Object
[]android.2.2
Object
&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 id
number
Description
ID of the worker
Example122326697
url
string
Description
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 message
string
Description
Status of the termination operation
Exampleworker is running for 19.405956957 secs, minimum life is 30 sec
time
number
Description
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 message
string
Description
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 url
string
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 browser
string
- Example Chrome
browser_version
string
- Example 80.0
os
string
- Example Windows
os_version
string
- Example 10
device
string
- Example null
real_mobile
boolean
- Example null
id
number
- Description
ID of the worker.
Example122326697
sessionId
unknown
- Description
ID of the session.
Example550709149fe79e949363b581e774d5ebffa1b8fe
status
"running"
|"queue"
- Description
Current status of the worker.
Examplerunning @enum {string}
browser_url
string
- Description
Dashboard URL of the session
ExampleupdateURL
( url
) =>Promise
<Object
>- - getScreenshot
() => Promise
<ArrayBuffer
>- - getScreenshotURL
() => Promise
<string
>- - terminate
() => Promise
<Object
>- -