The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Analytics

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

If you already have existing JavaScript unit tests as part of your build cycle, you can run them on Sauce using the REST API.

What You'll Need

Use Sauce Connect Proxy for your Local JavaScript Unit Tests

Are you hosting your tests on your local area network (LAN) or your laptop? You'll need to run Sauce Connect Proxy to bridge the Sauce Labs platform to your local network. The optional parameters related to Sauce Connect Proxy 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 optional Test Configuration Options get passed on to the local Selenium server.

REST API Methods

Base API REST URL: https://saucelabs.com/rest/v1/, for more information about the API endpoints, refer to The Sauce Labs REST API.

MethodDescriptionURLMethod TypeRequest FieldsExample Request

Start JS Unit Tests

Starts your JavaScript unit tests on one, or multiple browsers.: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/$SAUCE_USERNAME/js-tests \ -X POST \ -u SAUCE_USERNAME:SAUCE_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/%SAUCE_USERNAME%/js-tests -X POST -u SAUCE_USERNAME:SAUCE_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

Get JS Unit Test Status

Gets 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/$SAUCE_USERNAME/js-tests/status \ -X POST \ -u $SAUCE_USERNAME:$SAUCE_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