Node module for running tests using SauceLabs automated tests feature to run on several different browsers
npm install --save-dev sauce-test-runner
const saucelabs = require('gulp-saucelabs');
const connect = require('gulp-connect');
// Saucelabs
gulp.task('saucelabs', () => {
const config = {
urls: ['http://localhost:3000/tests/qunit/index.html'],
testname: 'My test',
framework: 'qunit',
browsers: [
{
browserName: "MicrosoftEdge",
platform: "Windows 10",
version: "latest"
}
],
onTestSuiteComplete: (status) => {
if (status) {
console.log('All tests passed!');
}
};
}
return saucelabs(config);
});
// Start local http server
gulp.task('connect', () => {
connect.server({ port: 3000, root: './' });
});
// Close down the http server
gulp.task('disconnect', () => {
connect.serverClose();
});
gulp.task('test-saucelabs', ['connect', 'saucelabs'], () => gulp.start('disconnect'));
Example:
const config = {
username: 'foo-bar',
key: 'xxxx-xxxx-xxxx-xxxx-xxxx',
urls: ['http://localhost:3000/tests/index.html'],
testname: 'My test',
framework: 'qunit',
logger: {
log: console.log,
debug: console.log,
},
debug: false,
browsers: [
{
browserName: "MicrosoftEdge",
platform: "Windows 10",
version: "latest"
},
{
browserName: "internet explorer",
version: "11",
platform: "Windows 8.1"
},
{
browserName: "internet explorer",
version: "10",
platform: "Windows 8"
}
],
onTestSuiteComplete: (status) => {
if (status) {
console.log('All tests passed!');
}
}
...
}
Username to SauceLabs. If not provided, uses the value of SAUCE_USERNAME environment variable. Optional
Accesskey for SauceLabs. If not provided, uses the value of SAUCE_ACCESS_KEY environment variable. Optional
The build number for this test. Optional
An array or URLs that will be loaded in the browsers, one after another. Required
Which framework to test. Options: qunit
, jasmine
, mocha
, custom
. Required
name of the test, displayed on the SauceLabs dashboard. Optional
An array of strings, to be added as tags to the test on Sauce Labs. Optional
Defaults to true; Won't launch a Sauce Connect tunnel if set to false. Optional
Array of optional arguments to be passed to the Sauce Connect tunnel. example: ['--debug', '--direct-domains', 'google.com']
. See here for further documentation.
Map of extra parameters to be passed to sauce labs. example: {'video-upload-on-pass': false, 'idle-timeout': 60}
. See here for further documentation.
Number of milliseconds between each retry to see if a test is completed or not (default: 2000). Optional
Number of times to attempt to see if a test is completed or not (default: 90). Effectively, your tests have statusCheckAttempts * pollInterval
seconds to complete (Thus, 180s by default). Set to -1
to try forever. Optional
Maximum number of unit test pages which will be sent to Sauce Labs concurrently. Exceeding your SauceLabs' allowed concurrency can lead to test failures if you have a lot of unit test pages. Optional
Maximum duration of a test, this is actually a Selenium Capability. SauceLabs defaults to 180 seconds for js unit tests. Optional
An array of objects representing the various browsers on which this test should run. Optional
A callback that is called every time a unit test for a page is complete. Runs per page, per browser configuration. Receives two arguments (result, callback)
. result
is the javascript object exposed to SauceLabs as the results of the test. callback
must be called, node-style (having arguments err
, result
where result is a true/false boolean which sets the test result reported to the command line). Optional
A callback that is called when the tunnel does not close properly and we had to cancel the promise waiting for the tunnel to close.
A callback that is called when all tests have run and the tunnel has been closed down. The callback receives one argument (boolean) which is true if all tests passed, otherwise false.
Logger functions, used to print the test output. The logger object needs to define two methods: log and debug which take a sequence of strings as arguments. Defaults to console.log.
Specifies if the module should invoke logger.debug to print saucelabs tunnel info messages.
Specifies how many times the timed out tests should be retried (default: 0). Optional
The job visibility level. Defaults to 'team'. Optional
Forked from https://github.com/axemclion/grunt-saucelabs
###0.1.4 Added callback and timeout for when the tunnel does not stop
###0.1.3 Removed YUI support