Skip to end of metadata
Go to start of metadata

Sauce Labs is a cloud platform for executing automated and manual mobile and web tests. Sauce Labs supports running automated tests with Selenium WebDriver (for web applications) and Appium (for native and mobile web applications). This topic will provide you with an example of how to get your Node.js tests set up and running on Sauce.

Example Only

The code in this topic is presented as an example only, since your tests and testing environments may require specialized scripting. This information should be taken only as an illustration of how you could set up your tests with Sauce Labs, and is not directly supported by Sauce.


Code Example

Save this code to a file named something like sauce_node_code_example.js to see an example of how you would run your node.js test on Sauce.

You can also clone this script directly from our GitHub repo.

var webdriver = require('selenium-webdriver'),
    username = "YOUR_SAUCE_USERNAME",
    accessKey = "YOUR_SAUCE_ACCESS_KEY",

driver = new webdriver.Builder().
    'browserName': 'chrome',
    'platform': 'Windows XP',
    'version': '43.0',
    'username': username,
    'accessKey': accessKey
  usingServer("http://" + username + ":" + accessKey +


driver.getTitle().then(function (title) {
    console.log("title is: " + title);


Running the Test

Once you have everything set up, you can run the example test simply by running the example file. 

$ node sauce_node_example_test.js

Running Local Tests

Developing websites/apps within your local network is secure and efficient. The drawback to this method is that local assets are not publicly-accessible on the Internet, so the browsers/devices in the Sauce Labs cloud can't load and test your app. The solution is to use Sauce ConnectSauce Connect is a proxy server that creates a secure tunnel connection between the Sauce Labs virtual machine that runs your test and your local  network. You can also use Sauce Connect to test applications and websites that are located within your corporate firewall. Sauce Connect is not required to run tests on Sauce Labs, only in situations where the application or website you want to test is not publicly accessible. 

If you want to use Sauce Connect, you need to set host to localhost and the port to 4445, as shown in this example script.
Sauce Connect and Node.js Example
var client = require('webdriverio').remote({
    user: process.env.SAUCE_USERNAME,
    key: process.env.SAUCE_ACCESS_KEY,
    host: 'localhost',
    port: 4445,
    desiredCapabilities: {
        browserName: 'chrome'


Running Tests in Parallel

Now that you’re running tests on Sauce, you may wonder how you can run your tests faster. One way to increase speed is by running tests in parallel across multiple virtual machines.

You can run your tests in parallel at two levels, and you can run your tests in parallel across multiple browsers. For example, if you have 10 tests and want to run on five browsers, this would be parallelism of five. You can also run tests across browsers and each test in parallel. Using our previous example this would be more like 50 parallel tests. Doing this requires that your tests are written in a way that they do not collide with one another, as described in our Best Practice topics avoiding external test dependencies and avoiding dependencies between tests.

Match Thread Count to Concurrency Limit

You should match your thread count to your concurrency limit, which is shown in the My Account section of your user profile information on the Sauce Labs dashboard.  

For more information, check out the example scripts in our GitHub repo

Reporting on Test Results

"Wait," you might be asking, "My test says 'Complete' but what happens if it fails?"

Unfortunately, Sauce has no way to determine whether your test passed or failed automatically, since it is determined entirely by your business logic. You can, however, tell Sauce about the results of your tests as shown by this code snippet from the example file for running node.js files in parallel.

saucelabs.updateJob(driver.sessionID, {
      name: title,
      passed: passed
    }, done);