Git Product home page Git Product logo

api's Introduction

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.

api's People

Contributors

abhijeetps avatar ankurgel avatar archish27 avatar bstack-security-github avatar crodjer avatar francisf avatar jatinbs avatar minoli-v avatar nakula avatar piyushranjan avatar prayagverma avatar pulkitsharma07 avatar rahulnwn avatar rchougule avatar ritesharora avatar scottgonzalez avatar tr4n2uil avatar utsavkesharwani avatar vikas17a avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api's Issues

Timeout = 0 - still supported?

(timeout=30)

A number in seconds before the worker is terminated. Set this to 0 to keep the worker alive 
indefinitely.

IMPORTANT! If you have set the timeout to 0. Make sure you remember to terminate 
the worker otherwise it will continue to use up your credits. Irrespective of timeout 
parameter, a browser worker is alive for a maximum time of 1,800 seconds.

Is a timeout of 0 still supported? Doesn't feel like 1800 seconds in my tests, maybe 5-10 mins max.

Terminal not alloted, yet

After creating a worker via POST /workers and then trying to create a screenshot I sometimes get

{"message":"Not Found","errors":[{"field":"id","code":"Terminal not alloted yet, cannot process screenshot at the moment"}]}

Didn't find anything about this error mentioned in the documentation.

Screenshots stored as JPEG but the url ends in .png

When I create screenshots using the /worker/:id/screenshot.json endpoint the API returns a url to a PNG image which in fact is a JPEG image. Is there a way to return a real PNG image? I was planning to use the screenshot for automatic frontend testing (using pixel matching) and would rather not have JPEG compression artefacts in the screenshots.

example response: https://s3.amazonaws.com/testautomation/54f41127df9733579bb00bf009cda30b3295cbfa/js-screenshot-1551970472.png

delete multiple builds not working

When I use the curl example from the docs it works without any problem

curl -u "xxxx:xxxx" -X DELETE "https://api.browserstack.com/automate/builds?buildId=xxxx"

but when I try to do the same with node I always get a 302 redirect error

const request = require('request')

request({
	url: 'https://api.browserstack.com/automate/builds?buildId=xxxx',
	method: 'DELETE',
	auth: {
		user: 'xxxx',
		pass: 'xxxx'
	}
}, (err, res, body) => {
	if (res.statusCode === 201) {
		console.log('success')
	} else {
		console.log('error: ' + res.statusCode)
		console.log(body)
	}
})

the code above logs

error: 302
<html><body>You are being <a href="https://api.browserstack.com/users/sign_in">redirected</a>.</body></html>

When I modify the code to e.g. change the status of a session it works.

request({
	url: `https://api.browserstack.com/automate/sessions/xxxx.json`,
	method: 'PUT',
	headers: {
		'Content-Type': 'application/json'
	},
	body: `{"status":"error"}`,
	auth: {
		user: 'xxxx',
		pass: 'xxxx'
	}
})

Is there any internal difference I need to consider when trying to modify multiple items?
I really have no idea what's wrong with the node code :/

Worker Ids are not being returned from the /workers call

There must have been a change made to the api recently, because the call to get all of the workers is no longer returning the worker id for each of the workers. Instead, I am just getting:

[{ browser: 'firefox',
version: '15.0',
os: 'win',
status: 'running' },
{ browser: 'firefox',
version: '15.0',
os: 'win',
status: 'queue' }]

What happened to the worker ids? They were in that array last week...

API for an SSO user

Is it possible to formulate a url that can be hit in the browser to take a user with browserstack SSO credentials to a specific url in a specific browser? The use case would be to have GitHub actions build specific links for testing for our dev team.

Missing documentation for error response from screenshot API

When requesting a screenshot with the JSON format, errors are reported differently than documented in the Error Handling section. There is no mention of how to handle errors in this case. From my experience, you just get back an object with an error property containing the error message.

What is the API rate limit?

I am getting this rate limit error (tests are using the latest karma-browserstack-launcher):

21 12 2018 17:32:40.723:INFO [launcher.browserstack]: Firefox (OS X Mojave) session at https://automate.browserstack.com/builds/1edbceee868d11599f454db274b4e1c7fa2908fe/sessions/d84ec96b49fc2f1ab33be6ff0e1f6df6caa8784b
Error: 403 Forbidden (Rate Limit Exceeded)

    at IncomingMessage.<anonymous> (/home/circleci/repo/node_modules/browserstack/lib/client.js:74:8)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
Step was canceled

Thank you!

Document latest/beta browser versions

It looks like I can use "latest" as the browser version. Is there a way I can get the beta version? "beta" does not work. Also would be useful to have this documented.

Any way to request tunnel status?

Wondering if it is possible to request information about established tunnels (with command-line tunnel)?

For example if we are launching the tunnel from command-line in automated environment, how do we detect the moment when tunnel is ready?

Btw, does BrowserStackTunnel.jar thingy has it's own issue tracker somewhere?

Manage Users

We are looking to automate removal of users during off-boarding. Is there not an API end-point to allow this yet? Thanks!

Return `browser_url` in the `/worker`

The response from client.createWorker (using Node.js's library; the POST /worker request) does not contain browser_url. I think BS knows the url even at that point, it would be helpful to provide it.

At this point, it's necessary to do another client.getWork(id) call to get it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.