Home

Awesome

sauce-test

The easy way to run unit tests on sauce-labs and in chromedriver

Build Status Dependency Status NPM version

Installation

npm install sauce-test

Usage

For basic usage, see test.js in this repo. For more advanced usage, see test/browser.js in https://github.com/then/then-jsonp

var runTests = require('sauce-test');

runTests(entries, remote, options).done(function (results) {
  console.dir(results);
});

If you want to write your own custom webdriver tests:

var runTestsAtLocation = require('sauce-test').runTestsAtLocation;

runTestsAtLocation({url: 'http://example.com'}, remote, {
  testComplete: () => Promise.resolve(true),
  testPassed: (cabbie) => {
    return cabbie.getSyncDriver().then(driver => {
      const window = driver.browser().activeWindow();
      const title = window.getElement('h1');
      assert(title.isDisplayed() === true);
      assert(title.getText().trim() === 'Example Domain');
      return true;
    }).catch(ex => {
      console.error(ex.stack);
      return false;
    });
  }
}).done(function (results) {
  console.dir(results);
});

entries

Entries should be an array of file names or JavaScript code. e.g.

runTests(__dirname + '/test.js', remote, options).done(function (results) {
  console.dir(results);
});
runTests('TESTS_PASSED = 40 + 2 === 42;TESTS_COMPLETE = true;', remote, options).done(function (results) {
  console.dir(results);
});
runTests([__dirname + '/assert.js', 'assert(40 + 2 === 42);TESTS_PASSED = true;TESTS_COMPLETE = true;'], remote, options).done(function (results) {
  console.dir(results);
});

See also the browserify option.

remote

Remote is the url of the selenium web driver server you want to run your tests on. You can also enter 'chromedriver' to automatically start up chromedriver and run your tests in google chrome or 'saucelabs' (along with the username and accessKey options) to run your tests on saucelabs.

options

Publishing code

sauce-test publishes your code to https://tempjs.org automatically for you. You can control how the code is served using these options.

You can also manually just publish code (without running any tests) via:

var test = require('sauce-test');
test.publishCode(__dirname + '/test.js', options).done(function (res) {
  console.log('To view tests in a browser, navigate to: ' + res.url);
});

Sauce Labs options

The following options are specific to saucelabs and are ignored by other remotes:

filterPlatforms: (platform, defaultFilter) => platform.browserName === 'chrome' && defaultFilter(platform)

The default is to omit development and beta browsers, and only test every 5th version of chrome and firefox below 35 and 30 respectively.

choosePlatforms: (platforms) => [platforms[Math.floor(Math.random() * platforms.length)]]
{
  name: path.basename(process.cwd()),
  build: process.env.TRAVIS_JOB_ID
}

Other options

throttle: require('throat')(3)
capabilities: {
  'record-video': false,
  'record-screenshots': true,
  'capture-html': false
}

License

MIT