Skip to content

Instantly share code, notes, and snippets.

@mikberg mikberg/sauce.js
Created Jan 23, 2016

What would you like to do?
Report Nightwatch results to SauceLabs
/* eslint no-console:0 */
const https = require('https');
module.exports = function sauce(callback) {
const currentTest = this.client.currentTest;
const username = this.client.options.username;
const sessionId = this.client.capabilities['webdriver.remote.sessionid'];
const accessKey = this.client.options.accessKey;
if (!this.client.launch_url.match(/saucelabs/)) {
console.log('Not saucelabs ...');
return callback();
if (!username || !accessKey || !sessionId) {
console.log('No username, accessKey or sessionId');
return callback();
const passed = currentTest.results.passed === currentTest.results.tests;
const data = JSON.stringify({
const requestPath = `/rest/v1/${username}/jobs/${sessionId}`;
function responseCallback(res) {
console.log('Response: ', res.statusCode, JSON.stringify(res.headers));
res.on('data', function onData(chunk) {
console.log('BODY: ' + chunk);
res.on('end', function onEnd() {'Finished updating saucelabs');
try {
console.log('Updating saucelabs', requestPath);
const req = https.request({
hostname: '',
path: requestPath,
method: 'PUT',
auth: `${username}:${accessKey}`,
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
}, responseCallback);
req.on('error', function onError(e) {
console.log('problem with request: ' + e.message);
} catch (error) {
console.log('Error', error);

This comment has been minimized.


This comment has been minimized.

Copy link

shcallaway commented Sep 25, 2017

Thanks for this. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.