forked from admc/se-builder
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test converted exemaple with Sauce Labs, extra logging
- Loading branch information
Showing
5 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
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
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= |
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
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 | ||
} |
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
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
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); | ||
} |
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