Created
September 11, 2014 19:10
-
-
Save geekdave/f2f482d2f1ac8db0cb7b to your computer and use it in GitHub Desktop.
Nightwatch / SauceLabs Stats Updating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateStats: function (client, allPassed, callback) { | |
var data = JSON.stringify({ | |
"passed" : allPassed | |
}); | |
var requestPath = '/rest/v1/'+ client.options.username +'/jobs/' + client.sessionId; | |
try { | |
console.log('Updaing saucelabs', requestPath); | |
var req = https.request({ | |
hostname: 'saucelabs.com', | |
path: requestPath, | |
method: 'PUT', | |
auth : client.options.username + ':' + client.options.accessKey, | |
headers : { | |
'Content-Type': 'application/json', | |
'Content-Length' : data.length | |
} | |
}, function(res) { | |
res.setEncoding('utf8'); | |
console.log('Response: ', res.statusCode, JSON.stringify(res.headers)); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
res.on('end', function () { | |
callback(); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req.write(data); | |
req.end(); | |
} catch (err) { | |
console.log('Error', err); | |
callback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment