Skip to end of metadata
Go to start of metadata

If you already have JavaScript unit tests, running them on Sauce using the REST API is simple. Check out JavaScript Unit Testing for more information. 

Standard URL: https://saucelabs.com/rest/v1/

Finding Your Username and Access Key

You can find your Sauce Labs username and access key in the User Profile > User Settings section of your Sauce Labs dashboard. You should also check out our topic on setting your username and access key as environment variables.

MethodDescriptionURLMethod TypeRequest FieldsExample Request

Start JS Unit Tests

Start your JavaScript unit tests on as many browsers as you like with a single request:username/js-testsPOST
  • platforms (required): an array of desktop platforms
  • url(required): should point to the page that hosts your tests.
  • framework (required): can be "qunit""jasmine""YUI Test""mocha", or "custom".

The custom framework checks window.global_test_results on the test page and uses whatever object supplied there to get test results. Read about it here.

Supported Jasmine Version

Only the Jasmine 2 framework is supported.  

 

 OS X/Linux Example

curl https://saucelabs.com/rest/v1/YOUR_USERNAME/js-tests \ -X POST \ -u YOUR_USERNAME:YOUR_ACCESS_KEY \ -H 'Content-Type: application/json' \ --data '{  "platforms": [["Windows 7", "firefox", "27"],  ["Linux", "googlechrome", ""]],  "url": "https://saucelabs.com/test_helpers/front_tests/index.html",  "framework": "jasmine"}'

 

 Windows Example

curl https://saucelabs.com/rest/v1/YOUR_USERNAME/js-tests -X POST -u YOUR_USERNAME:YOUR_ACCESS_KEY -H 'Content-Type: application/json' -d platforms="[[\"Windows 8\", \"internet explorer\", \"10\"][\"OS X 10.8\", \"safari\", \"6\"]]" -d url="https://saucelabs.com/test_helpers/front_tests/index.html" -d framework=jasmine -d name=sauce-sample-test

Using Sauce Connect

Hosting your tests on your LAN or your laptop? You'll need to run Sauce Connect to bridge Sauce Labs to your local network. Optional parameters related to Sauce Connect include:

  • tunnelIdentifier: specifies the ID of a specific tunnel when using multiple Sauce Connect tunnels.
  • parentTunnel: specifies the username of a parent account whose shared Sauce Connect tunnel your tests should use.

Any other parameters get passed on as Optional Desired Capabilities for the Selenium server. This means you can set things like: maxDuration

The default maxDuration for all JS unit tests is 180 seconds.

Get JS Unit Test Status

Get the status of your JS unit tests:username/js-tests/statusPOST
    • js tests (required): an array of job ids which you would like the status of

curl https://saucelabs.com/rest/v1/YOUR_USERNAME/js-tests/status \ -X POST \ -u YOUR_USERNAME:YOUR_ACCESS_KEY \ -H 'Content-Type: application/json' \ -d '{"js tests": ["JOB_ID_1","JOB_ID_2"]}'

Make the request multiple times as the tests run until the response contains completed: true to the get the final results.

1 Comment

  1. Anonymous

    This mentions a framework=mocha parameter in the REST API and mentions a
    window.global_test_results variable for the "custom" framework but
    mentions no such thing for Mocha, implying that Sauce Labs "just
    works" with Mocha. This page should link to (and better organize) these: Getting Started with JavaScript Unit Testing Example