Skip to content

Commit

Permalink
test converted exemaple with Sauce Labs, extra logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bernii committed Jun 19, 2013
1 parent d2c9d2d commit 74c14dd
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 5 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
---
language: node_js
node_js:
- 0.8
- 0.8
script:
- "node tests/exporters.js"
- node tests/exporters.js
- node tests/saucelabs.js
env:
global:
- secure: |-
Ei1PS+CbFkUKa7aHaX54qt/P1Tsip71bu8hdWETHowYof+XELXIyJdg8LkpOsDu+Irpu6oBkrKSDrMks/V9/wJQ19YalKfVm9HYEfX9b81G7hugY3rycdSQCau5zfVkTja4XBpiypYJMl+k3078KZqllYYf3GLDDdWrmyHCm3MQ=
- secure: |-
u+4ktvf6GnCmhi50CF+UG4OZUbKytGnsnMfYDOStem6LDS6t3RUNza0Ns/LydRfOvHgFgw1vg6ZlvVdJLsNqvSFSl6KBwch1N0dBLGR0mOl/8wkhIUPJmuWsmdmS4iZ2pYIOXJrvId7xCS28z2K7luym8kRr/YaJX7yGc+AGOlY=
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "se-builder",
"description": "Foo for bar",
"version": "0.0.1",
"dependencies": {
"coloured-log": "",
"path": "",
"wd": "",
"underscore": "",
"uuid-js": "",
"q": "",
"request": ""
},
"private": true
}
7 changes: 6 additions & 1 deletion tests/exporters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// test exporters - run selenium tests using each one

var assert = require('assert')
, convert = require('../tools/convert');
, convert = require('../tools/convert')
, Log = require('coloured-log')
, log = new Log(Log.DEBUG);

// test exporters
var exporters = ["node-wd", "node-mocha", "java_new", "english"];
Expand All @@ -14,9 +16,12 @@ var testExporter = function(exporter, testFile) {
var testFile = "./tests/examples/full_example.json";

for (var i = exporters.length - 1; i >= 0; i--) {
log.debug("Testing exporter " + exporters[i]);
testExporter(exporters[i], testFile);
}

log.info("Tested " + exporters.length + " exporters succesfully");

// non-available exporter
assert.throws(function() {
convert.run(["non-available-exporter", testFile]);
Expand Down
108 changes: 108 additions & 0 deletions tests/saucelabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// test exporters with SuaceLabs

var assert = require('assert')
, convert = require('../tools/convert')
, Log = require('coloured-log')
, log = new Log(Log.DEBUG)
, vm = require("vm")
, fs = require('fs')
, wd = require('wd')
, _ = require('underscore')
, q = require('q')
, path = require('path')
, uuid = require('uuid-js')
, request = require('request')
, rqst = request.defaults({jar: false})
, platforms = [
{ browserName: "firefox", platform: "VISTA" },
{ browserName: "chrome", platform: "Linux" },
{ browserName: "iexplore", platform: "Windows 2008" }
]
, login = process.env.SAUCE_USERNAME
, accessKey = process.env.SAUCE_ACCESS_KEY
, buildId = process.env.TRAVIS_JOB_ID || Math.random().toString(36).slice(2);

log.info("Testing if exporterts really work with Selenium & Sauce Labs");

var SauceStatus = function(user, key) {
this.user = user;
this.key = key;
this.baseUrl = ["https://", this.user, ':', this.key, '@saucelabs.com', '/rest/v1/', this.user].join("");
};

SauceStatus.prototype.passed = function(jobid, status, callback) {
var _body = JSON.stringify({
"passed": status
}),
_url = this.baseUrl + "/jobs/" + jobid;
rqst({
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
method: "PUT",
url: _url,
body: _body,
json: true
}, function() {
callback();
});
};

// test node exporter
var exporters = ["node-wd"];

var sauceStatus = new SauceStatus(login, accessKey);
var testExporter = function(exporter, testFile) {
assert.doesNotThrow(function(){
_.each(platforms, function (caps) {
caps = _.clone(caps);

var isDone = function () {
log.info("Sauce job finished succesfully, job id:" + context.b.sessionID);
sauceStatus.passed(context.b.sessionID, true, function () {
});
},
isError = function (err) {
log.error("run failed - stacktrace below");
// mark job as failed
sauceStatus.passed(context.b.sessionID, false, function () {
throw new Error(err);
});
},
context = vm.createContext({
require: require,
fs: fs,
wd: wd,
_: _,
path: path,
uuid: uuid,
console: console,
Buffer: Buffer,
q: q,
__dirname: __dirname,
isDone: isDone, isError: isError
});

caps.name = exporter;
caps.build = buildId;

var conversionDone = function (output) {
selenium = output.replace('wd.promiseRemote()', 'wd.promiseRemote("ondemand.saucelabs.com", 80, "' + login + '", "' + accessKey + '")');
selenium = selenium.replace(/b\.init\({[\S\s]*?}\)/, 'b.init(' + JSON.stringify(caps) + ')');
selenium = selenium.replace('}).done();', '}).done(isDone, isError);');

log.debug("Running output of exporter " + exporter + " against Sauce");
vm.runInContext(selenium, context);
};

convert.run([exporter, testFile], null, conversionDone);
});
});
};

var testFile = "./tests/examples/full_example.json";

for (var i = exporters.length - 1; i >= 0; i--) {
log.debug("Testing exporter " + exporters[i]);
testExporter(exporters[i], testFile);
}
5 changes: 3 additions & 2 deletions tools/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var initContext = function(exporterName) {
selenium2: {io: { formats:[], lang_infos: []}}
}
});

for (var i = 0; i < files.length; i++) {
vm.runInContext(fs.readFileSync(path.resolve("./seleniumbuilder/chrome/content/html/js/", files[i])), context);
}
Expand All @@ -37,7 +37,8 @@ var main = function(args, readyCb, doneCb) {
// exporter is first in list
var format = context.builder.selenium2.io.formats[0];
var output = format.format(input, "whatever-name-man", format.get_params);
if (!outputPath) { return; }
if (doneCb) { doneCb(output); }
if (!outputPath) { return '';}
fs.writeFile(outputPath, output, function(err) {
if(err) {
console.log(err);
Expand Down

0 comments on commit 74c14dd

Please sign in to comment.