Skip to content

Instantly share code, notes, and snippets.

@ryankirkman
Forked from bernii/sauce-qunit-example.js
Last active December 13, 2015 22:29
Show Gist options
  • Save ryankirkman/4985246 to your computer and use it in GitHub Desktop.
Save ryankirkman/4985246 to your computer and use it in GitHub Desktop.
// You need to have the following installed:
// https://github.com/admc/wd
// https://github.com/kriskowal/q
// https://github.com/holidayextras/node-saucelabs
var wd = require('wd')
, Q = require('q')
, assert = require('assert')
, sauce = require('saucelabs')
, host = "ondemand.saucelabs.com"
, port = 80
, username = YOUR_USERNAME_GOES_HERE
, accessKey = YOUR_ACCESS_KEY_GOES_HERE
// using promisified version of webdriver
, browser = wd.promiseRemote(host, port, username, accessKey);
browser.on('status', function(info){
console.log('\x1b[36m%s\x1b[0m', info);
});
browser.on('command', function(meth, path, data){
console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path, data || '');
});
// general rest call helper function using promises
var updateJob = function (sessionID, data) {
var deferred = Q.defer();
var myAccount = new sauce({username: username, password: accessKey});
myAccount.updateJob(sessionID, data, function(err, res) {
deferred.resolve(res);
});
return deferred.promise;
};
// test case
browser.init({
browserName: 'chrome',
tags: ["examples"],
name: "Sample QUnit test",
// provide build name if you want to see frontend tests
// summary on your jobs page
build: "frontend-tests-example"
}).then(function () {
return browser.get("http://saucelabs.com/test_helpers/front_tests/qunit.html")
.delay(3000); // wait for tests to finish
}).then(function () {
return browser.title();
}).then(function (title) {
// are we on the right page?
assert.ok(~title.indexOf("Refactored date examples"), 'Wrong title!');
}).then(function () {
// get jasmine output as JSON
return browser.eval("window.global_test_results");
}).then(function (jsreport) {
// make an API call to Sauce - set custom-data with 'jasmine' data
var data = {
'custom-data': {qunit: jsreport}
};
return updateJob(browser.sessionID, data);
}).then(function (body) {
console.log("CONGRATS - WE'RE DONE", body);
}).fin(function () {
browser.quit();
}).done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment