What is the point with the browserstack.com API? What is the point with the browserstack.com API? selenium selenium

What is the point with the browserstack.com API?


Current API opens your provided url in all platform/browser combinations.

So, if you open an HTML page with lot of JS tests, you need to be using tool like yeti/testswarm/js-test-driver which automatically fetch results from browser.

Another example of using BrowserStack API is http://ryanseddon.github.com/bunyip/

Sample integration with Jenkins: http://github.com/jquery/testswarm/wiki/Automated-Distributed-Continuous-Integration-for-JavaScript

For local JS testing, you will need to use tools like localtunnel to get a public url for your local servers.


One of the most useful capabilities of the current BrowserStack API is to allow you to mark a session as a failed test.

Like any Selenium hub/node system, BrowserStack doesn't know why you're sending commands to the browser. It just runs the commands you request. Consequently, it has no way to know when a test fails.

But you can use the API to tell it that a test failed, so that the session gets marked as failed in the BrowserStack UI. Then you can filter on just the failed sessions to investigate them.

This is in Java, not Python, but here's some sample code that shows how to update sessions to reflect that they represent failed tests. You just pass in the Selenium session IDs (which you need to save as you run the test in question) and the exception you got when the test failed.

import com.mashape.unirest.http.Unirest;import com.mashape.unirest.http.exceptions.UnirestException;import com.unblu.automation.support.settings.Prop;import com.unblu.automation.support.settings.Settings;import org.openqa.selenium.remote.SessionId;public class BrowserStackUpdater {    private void markSessionAsFailed(SessionId sessionId, Throwable e) {        var url = "https://api.browserstack.com/automate/sessions/" + sessionId + ".json";        try {            var userName = "BROWSERSTACKUSERNAMEHERE";            var key = "BROWSERSTACKKEYHERE";            var result = Unirest.put(url)                .basicAuth(userName, key)                .field("status", "failed")                .field("reason", e.toString())                .asString();            System.out.println("Marking test failed; reply from BrowserStack: " +              result.getStatus() + " : " + result.getBody());        }        catch (UnirestException ue) { ue.printStackTrace(); }    }    public void markTestFailedInBrowserStack(Iterable<SessionId> sessionIds, Throwable e) {        var env = Settings.getString(Prop.runEnvironment);        if (env.equals("BrowserStack")) {            for (var sid : sessionIds) {                markSessionAsFailed(sid, e);            }        }    }}