• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
  • Created about 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Spec of latest BrowserStack JavaScript testing api

API Overview

The following denotes the HTTPS-based API for BrowserStack. It provides browser-as-a-service for automated cross-browser testing. The goal is to provide a simple service which can easily be used by any browser testing framework.

Authentication

All methods need to authenticate who you are, before spawning browser workers and deleting a worker for example. Authentication is done using your username and the BrowserStack access key within the HTTP request.

For example:

curl -u "username:access_key" https://api.browserstack.com/5

Note: A 401 Unauthorized response is received if an unauthorized request is made.

Schema

All requests are made to https://api.browserstack.com/VERSION/ and all returned data is done so in JSON-format. This documentation outlines version 5.

curl -i -u "username:access_key" https://api.browserstack.com/5

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf8
Status: 200 OK
X-API-Version: 5

{}

All date formats are given in ISO-8601 which can be processed natively with Date.parse in compatible JavaScript environments.

Error Handling

All requests are pre-processed and validated. This section outlines how we handle errors within the API and respond to them.

All API requests are validated. The following is an example output for a required parameter that wasn't given.

HTTP/1.1 422 Unprocessable Entity
Content-Length: 136

{
  "message": "Validation Failed",
  "errors": [
    {
      "field": "type",
      "code": "required"
    }
  ]
}

Possible error codes are required and invalid.

HTTP Verbs

The API is kept concise and simple by making use of relevant HTTP verbs on each request. The specifications for these are vague and their use within this API is specific but in general, we follow the following rules:

  • HEAD - Performs the request to assess the status of a resource and expects no content response.
  • GET - Used to retrieve resources.
  • POST - Used to create new resources.
  • PUT - Used to update resources.
  • DELETE - Used to delete resources.

API v5 Documentation

Getting Available Browsers

Fetches all available browsers.

GET /browsers

For example:

curl -u "username:access_key" https://api.browserstack.com/5/browsers

Output:

{
  'Windows':
    {
      '10':
        [
          {
            "browser": "chrome",
            "browser_version": "83.0"
          },
          {
            "browser": "chrome",
            "browser_version": "84.0"
          },
          {
            "browser": "chrome",
            "browser_version": "85.0 beta"
          },
          {
            "browser": "ie",
            "browser_version": "11.0"
          },
          {
            "browser": "edge",
            "browser_version": "insider preview"
          }...
        ],
    },
  'OS X':
    {
      'Catalina':
        [
          {
            "browser": "chrome",
            "browser_version": "85.0 beta"
          },
          {
            "browser": "edge",
            "browser_version": "85.0 beta"
          },
          {
            "browser": "safari",
            "browser_version": "13.1"
          },
          {
            "browser": "firefox",
            "browser_version": "79.0"
          },
          {
            "browser": "firefox",
            "browser_version": "80.0 beta"
          }...
        ],
      }...
    },
}

A flat parameter can also be passed to get browsers in a flat structure

GET /browsers?flat=true

For example:

curl -u "username:access_key" https://api.browserstack.com/5/browsers?flat=true

Output:

[  
  {
    "os": "Windows",
    "os_version": "10",
    "browser": "chrome",
    "device": null,
    "browser_version": "84.0",
    "real_mobile": null
  },
  {
    "os": "Windows",
    "os_version": "10",
    "browser": "edge",
    "device": null,
    "browser_version": "85.0 beta",
    "real_mobile": null
  },
  {
    "os": "OS X",
    "os_version": "Catalina",
    "browser": "firefox",
    "device": null,
    "browser_version": "79.0",
    "real_mobile": null
  },
  {
    "os": "OS X",
    "os_version": "Catalina",
    "browser": "firefox",
    "device": null,
    "browser_version": "80.0 beta",
    "real_mobile": null
  }....
]

Create a New Browser Worker

A browser worker is simply a new browser instance. A user can start multiple browser worker at a time. All browser workers when created are pushed in a queue and they run when their turn comes. We make sure that your browser worker starts running as soon as possible. Your testing time is calculated from the time when browser worker starts running.

POST /worker

Note: This call requires authentication. A 401 Unauthorized response is given if an unauthorized request is made.

For example:

curl -u "username:access_key" -X POST -d '{"os":"OS X","os_version":"Mojave","url":"https://browserstack.com","browser":"chrome","browser_version":"75.0"}' https://api.browserstack.com/5/worker -H 'content-type: application/json'

Response:

{"id":123456789,"url":"https://browserstack.com"}

Once a worker has been spawned you can then control this browser instance remotely. You can also look at the testing session status at the Automate Dashboard. This will provide you with the general details about the session and a live preview of the remote machine.

Parameters

A valid request for Desktop OS must contain os, os_version, url, browser and browser_version.

For Mobile OS, browser and browser_version are optional.

timeout is optional but defaults to 300 seconds.

os

A valid OS. A list of supported OSs is given using the GET /browsers. See the Getting Available Browsers above for details.

os_version

A valid OS Version. A list of supported OS Versions is given using the GET /browsers. See the Getting Available Browsers above for details.

browser

A valid browser. A list of supported browsers is given using the GET /browsers. See the Getting Available Browsers above for details.

device

A valid device. A list of supported devices is given using the GET /browsers. If a device is not provided it defaults to the first device available for that os version. See the Getting Available Browsers above for details.

browser_version

A valid browser version. A list of supported browser versions is given using the GET /browsers. See the Getting Available Browsers above for details.

(timeout=300)

Time in seconds before the worker is terminated. The default value is 300 seconds and the minimum value is 60 seconds.

IMPORTANT! Irrespective of the timeout parameter, a browser worker is alive for a maximum time of 1800 seconds.

(url)

A valid url to navigate the browser to.

Make sure the url is encoded. JavaScript: encodeURI(url), PHP: urlencode($url),

(name)

Provide a name to the session/worker.

(build)

Optional name of the build the session is running under.

(project)

Optional name of the project the build is under.

(browserstack.video)

Optional flag to enable video recording in your test.

(resolution)

Set the resolution of VM before the beginning of your test. Available for Desktop only. Default is 1024x768.

OS Supported Resolutions
Windows (XP,7) 800x600, 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080, 2048x1536
Windows (8,8.1,10) 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080, 2048x1536
OS X 1024x768, 1280x960, 1280x1024, 1600x1200, 1920x1080

Response

The response will be returned when the worker has been set up and initialized. This involves loading the HTML data or navigating to the url given depending on the setup parameters. Use the id returned to perform any further communications etc.

HTTP/1.1 200 Success
Content-Type: application/json
X-API-Version: 5

{
  "id": "123456789"
}

Screenshots

Use this method to take a screenshot at the current state of the worker.

GET /worker/<id>/screenshot(.format)

Acceptable formats are json, xml and png. This information can also be provided via the HTTP Accept headers: text/json, text/xml, image/png respectively.

For example:

curl -u "username:access_key" https://api.browserstack.com/5/worker/123456789/screenshot.json

Get Details of all Browser Workers

Returns comprehensive information, such as, worker ID, browser URL, session ID, etc., for all the browser workers you've created. It also returns the current status of the workers, which can be either queue or running.

GET /workers

Example request:

curl -u "username:access_key" -X GET https://api.browserstack.com/5/workers 

Example response:

[
  {
   "id": "<workerId>",
   "status": "running",
   "os": "OS X",
   "os_version": "Mojave",
   "browser": "chrome",
   "browser_version": "75.0",
   "real_mobile": null,
   "device": null,
   "browser_url": "<dashboard_url_of_the_session>",
   "sessionId": "<sessionId>"
  },
 {
    "id": "<workerId>",
    "status": "queue",
    "os": "android",
    "os_version": "2.2",
    "device": "Samsung Galaxy S",
    "browser": "Android Browser",
    "browser_version": null,
    "real_mobile": false,
    "browser_url": "<dashboard_url_of_the_session>",
    "sessionId": "<sessionId>"
  } ...]

Terminating a Browser Worker

Use this method to terminate a worker. Useful if you set the worker up to run indefinitely or if you've received all the information needed and you want to save on credit time.

DELETE  /worker/<id>

The id is the id returned when you first created the worker. Once called the browser instance will be immediately terminated and will no longer be accessible.

Note: This call requires authentication. If the request was made unauthorized a 401 Unauthorized response is given. Alternatively, if the authorized user is not the owner of the worker or id does not exist a 403 Forbidden response is given. Also, if this request is sent within 60 seconds of starting the worker, the response will be 422 Unprocessable Entity and the worker will be terminated after 60 seconds of its running time.

For example:

curl -u "username:access_key" -X DELETE https://api.browserstack.com/5/worker/123456789

Getting Worker Status

Sometimes you will need to check on the status of a worker. Not to be confused with the state of the javascript environment within the worker, this method simply determines whether the worker is in the queue, running or terminated.

GET /worker/<id>

This call requires authentication. If the request was made unauthorized a 401 Unauthorized response is given. Alternatively, if the authorized user is not the owner of the worker a 403 Forbidden response is given.

For example:

curl -u "username:access_key" https://api.browserstack.com/5/worker/123456789

If the worker has been terminated an empty response is given. Otherwise, you get a response with status and browser details.

{
  status: 'running',
  browser: 'ie',
  browser_version: '6.0',
  os: 'Windows',
  os_version: 'XP',
  sessionId: "<sessionId>",
  browser_url: "<dashboard url for the session>"
}

If you want to know the list of your current workers with their status, use the following method.

GET /workers

This method will return the list of workers whose status is either queue or running.

For example:

curl -u "username:access_key" https://api.browserstack.com/5/workers

Response:

[
  {
    status: 'running',
    browser: 'ie',
    version: '6.0',
    os: 'Windows',
    os_version: 'XP',
    sessionId: "<sessionId>",
    browser_url: "<dashboard url for the session>"
  },
  {
    status: 'queue',
    device: 'Samsung Galaxy Tab 8.9',
    os: 'android',
    os_version: '2.2',
    sessionId: "<sessionId>",
    browser_url: "<dashboard url for the session>"
  } ...
]

Getting API Status

If you want to know the status of your API, use the following method

GET /status

This will return the current status of API, like how much API time has been used and how many workers are running parallelly. All the paid plans have no time limits, only limit on parallel workers you can create.

For example:

curl -u "username:access_key" https://api.browserstack.com/5/status
  {
    used_time: 4235.4,
    total_available_time: 6000,
    running_sessions: 1,
    sessions_limit: 1
  }

The time returned is in seconds.

If a user runs out of API time, all requests will return the following response

{
  message: "You have run out of API time"
}

Note: You can make up to 1600 API requests every 5 minutes.

More Repositories

1

browserstack-runner

JavaScript
130
star
2

nightwatch-browserstack

Selenium examples for Nightwatch and BrowserStack Automate
JavaScript
77
star
3

testng-browserstack

Selenium examples for TestNG and BrowserStack Automate
Java
75
star
4

browserstack-local-nodejs

NodeJS bindings for BrowserStack Local
JavaScript
71
star
5

webdriverio-browserstack

Selenium examples for WebDriverIO and BrowserStack Automate
JavaScript
68
star
6

enigma

Access management tool
Python
54
star
7

github-actions

A collection of GitHub Actions for BrowserStack. For internal reference: https://browserstack.atlassian.net/wiki/spaces/ENG/pages/1750928573/GitHub+Integration+via+GitHub+Actions
JavaScript
54
star
8

playwright-browserstack

Sample repo for Playwright samples with BrowserStack.
JavaScript
51
star
9

browserstack-cypress-cli

NPM package for the customers to run Cypress on Browserstack Infra
JavaScript
51
star
10

automate-node-samples

Sample mocha, protractor, nightwatchjs, wd parallel testing code for running selenium with BrowserStack Automate
JavaScript
45
star
11

webdriverio-appium-app-browserstack

JavaScript
42
star
12

protractor-browserstack

Selenium examples for Protractor and BrowserStack Automate
JavaScript
42
star
13

automate-python-samples

Sample behave, lettuce, nose, unit, py.test code for running selenium with BrowserStack Automate
Python
37
star
14

ruby-screenshots

Ruby Wrapper for BrowserStack Screenshots API
Ruby
34
star
15

testng-appium-app-browserstack

Java
30
star
16

cucumber-js-browserstack

Selenium examples for Cucumber-JS and BrowserStack Automate
JavaScript
28
star
17

automate-ruby-samples

Sample cucumber, capybara, unit, minitest code for running selenium with BrowserStack Automate
Ruby
22
star
18

selenium-webdriver-nodejs

Selenium Webdriver Nodejs
JavaScript
20
star
19

browserstack-fastlane-plugin

Ruby
20
star
20

browserstack-local-java

Java bindings for BrowserStack Local
Java
18
star
21

java-appium-app-browserstack

Java
17
star
22

enigma-access-modules

Plug-able access modules for enigma
Python
17
star
23

flashblock-detector

Flash blocking plugin detector
JavaScript
17
star
24

python-appium-app-browserstack

Python
16
star
25

browserstack-gradle-plugin

Gradle plugin for uploading app and running tests on BrowserStack
Java
16
star
26

capybara-browserstack

Selenium examples for Capybara and BrowserStack Automate
Ruby
14
star
27

specflow-browserstack

Selenium examples for SpecFlow and BrowserStack Automate
C#
14
star
28

behave-browserstack

Selenium examples for Behave and BrowserStack Automate
Python
14
star
29

browserstack-local-php

PHP bindings for BrowserStack Local
PHP
13
star
30

behat-browserstack

Selenium examples for Behat and BrowserStack Automate
PHP
13
star
31

docker-browserstack-local

Docker official Image packaging for Browserstack Local Binary
Dockerfile
12
star
32

serenity-browserstack

Selenium examples for Serenity and BrowserStack Automate
Java
12
star
33

browserstack-local-ruby

Ruby bindings for BrowserStack Local
Ruby
11
star
34

rspec-browserstack

Selenium examples for RSpec and BrowserStack Automate
Ruby
10
star
35

node-js-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
JavaScript
10
star
36

automate-csharp-samples

Sample nunit, Galio code for running selenium with BrowserStack Automate
C#
9
star
37

lettuce-browserstack

Selenium examples for Lettuce and BrowserStack Automate
Python
8
star
38

python-selenium-browserstack

Python
8
star
39

junit-browserstack

Selenium examples for JUnit and BrowserStack Automate
Java
8
star
40

cucumber-java-browserstack

Java
8
star
41

browserstack-local-python

Python bindings for BrowserStack Local
Python
7
star
42

cucumber-ruby-appium-app-browserstack

Ruby
7
star
43

mocha-browserstack

Selenium examples for Mocha and BrowserStack Automate
JavaScript
7
star
44

browserstack-runner-sample

Code example to show how to run QUnit javascript tests with browserstack-runner
HTML
7
star
45

node-appium-app-browserstack

JavaScript
7
star
46

automate-php-samples

Sample behat, phpunit code for running selenium with BrowserStack Automate
PHP
7
star
47

android-native-app-certificate-pinning

Demo Android App for self-signed SSL certificate validation using Certificate Bundling and pinning process (Use case 1: App data sync with HTTPs servers, Use case 2: App using UIWidgets like WebView)
Java
7
star
48

automate-selenium-ide-samples

Run Selenium IDE scripts (json format) on BrowserStack Automate
JavaScript
6
star
49

xcuitest-sample-browserstack

Swift
6
star
50

junit-appium-app-browserstack

Java
6
star
51

phpunit-browserstack

Selenium examples for PHPUnit and BrowserStack Automate
PHP
6
star
52

browserstack-docker-example

This repo hosts the docker file running a basic selenium test on BrowserStack
JavaScript
5
star
53

selenium-webdriver-ruby

Faster Webdriver for Ruby
Ruby
5
star
54

automate-java-samples

Sample junit, testng code for running selenium with BrowserStack Automate
Java
5
star
55

test-university

This repository is a reference guide for all Test University resources and codes samples.
5
star
56

OSXVNC

abcd
C
4
star
57

ruby-appium-app-browserstack

Ruby
4
star
58

jest-js-browserstack

JavaScript
4
star
59

karma-browserstack-example

JavaScript
4
star
60

nunit-browserstack

Selenium examples for NUnit and BrowserStack Automate
C#
4
star
61

puppeteer-browserstack

Sample repo for Puppeteer samples with BrowserStack.
JavaScript
4
star
62

geb-browserstack

Selenium examples for Geb and BrowserStack Automate
Groovy
4
star
63

nunit-appium-app-browserstack

C#
4
star
64

browserstack-demo-app

A shopping application to demonstrate real-world usage of BrowserStack testing methods, patterns, and workflows.
JavaScript
4
star
65

espresso-browserstack

Java
4
star
66

cucumber-watir-browserstack

Selenium examples for Cucumber-Watir and BrowserStack Automate
Ruby
4
star
67

selenide-browserstack

Selenium examples for TestNG and BrowserStack Automate
Java
3
star
68

ws-reconnect-proxy

Proxy Server that is between a ws server and a ws client. In case of either server / client disconnects graceful or otherwise - initiates/ supports reconnection .
JavaScript
3
star
69

fast-selenium-scripts

Python
3
star
70

browserstack-local-csharp

CSharp bindings for BrowserStack Local
C#
3
star
71

cucumber-ruby-browserstack

Selenium examples for Cucumber-Ruby and BrowserStack Automate
Ruby
3
star
72

browserstack-integration-nodejs

Integration to run your tests on BrowserStack
JavaScript
3
star
73

behave-appium-app-browserstack

Python
3
star
74

teamcity-plugin

Java
3
star
75

browserstack-integration-ruby

Integration to run your tests on BrowserStack
Ruby
3
star
76

pytest-browserstack

Python
3
star
77

speedlab-code-samples

Demonstrates the workflow of SpeedLab APIs
JavaScript
3
star
78

selenium-parallel-webinar-demo

Demo of the tests used by David Burns during his Webinar on 22 April 2020
Python
2
star
79

csharp-appium-app-browserstack

C#
2
star
80

wd-browserstack

Selenium examples for WD and BrowserStack Automate
JavaScript
2
star
81

pytest-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
Python
2
star
82

automate-client-java

Java
2
star
83

unittest-browserstack

Selenium examples for Unit Test and BrowserStack Automate
Python
2
star
84

chitragupta-node

Node SDK for structured JSON logging
JavaScript
2
star
85

automate-groovy-samples

how to run selenium scripts on BrowserStack Automate in groovy
Groovy
2
star
86

cucumber-js-cypress-browserstack

Creating a sample repo for Cypress - Cucumber
JavaScript
2
star
87

webdriver-framework

Repository that contains the logic for creating the WebDriver instances based on a configuration file. These WebDriver instances can be either be used for controlling cloud browsers or in-house browsers. This library will also be responsible for managing the BrowserStackLocal tunnel.
Java
2
star
88

typescript-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
TypeScript
2
star
89

codecept-js-browserstack

JavaScript
1
star
90

jbehave-browserstack

Selenium examples for JBehave and BrowserStack Automate
Java
1
star
91

chitragupta-rails

Rails SDK for structured JSON logging
Ruby
1
star
92

node-js-selenium-browserstack

JavaScript
1
star
93

ruby-selenium-browserstack

Ruby
1
star
94

gauge-java-browserstack

Selenium Java examples for Gauge and BrowserStack Automate
Java
1
star
95

phpunit-appium-app-browserstack

PHP
1
star
96

protractor-browserstack-reporter

JavaScript
1
star
97

browserstack-android-sample-app

Java
1
star
98

emberjs-qunit-browserstack

JavaScript
1
star
99

pytest-appium-app-browserstack

Pytest integration with BrowserStack
Python
1
star
100

java-selenium-browserstack

Java
1
star