Skip to end of metadata
Go to start of metadata

This Node.js example script executes a simple test to open a browser, navigate to the Sauce Labs demo web app, and then close the browser. It also incorporate a number of best practices, such as using environment variables for authentication credentials, and is set up to report Pass/Fail results to your Sauce Labs dashboard. You can clone this script directly from the saucelabs-training GitHub repo and modify it as you want to test your authentication credentials, set desired capabilities, and run tests against your own web app. You can also clone this script directly from our GitHub repo.

 Click here to view the example script

var webdriver = require('selenium-webdriver'),
    assert = require('assert'),
    username = process.env.SAUCE_USERNAME,
    accessKey = process.env.SAUCE_ACCESS_KEY,
    /* Change the baseURL to your application URL */
    baseUrl = "",
    tags = ["sauceDemo", "demoTest", "module4", "nodeTest"],

describe('Instant Sauce Test Module 4', function() {

    beforeEach(function (done) {
        var testName = this.currentTest.title;
        driver = new webdriver.Builder().withCapabilities({
            'browserName': 'chrome',
            'platform': 'Windows 10',
            'version': '59.0',
            'username': username,
            'accessKey': accessKey,
            'build': 'Onboarding Sample App - NodeJS',
            'name': '4-best-practices',
            /* As a best practice, set important test metadata and execution options
            such as build info, tags for reporting, and timeout durations.
            'maxDuration': 3600,
            'idleTimeout': 1000,
            'tags': tags,
        }).usingServer("http://" + username + ":" + accessKey +

        driver.getSession().then(function (sessionid) {
            driver.sessionID = sessionid.id_;

    afterEach(function (done) {
        driver.executeScript("sauce:job-result=" + (true ? "passed" : "failed"));

    it('should-open-chrome', function (done) {
        driver.getTitle().then(function (title) {
            console.log("title is: " + title);

  • No labels