Permalink
Browse files

Now launching tests in parallel

Some refactor around test launchs
  • Loading branch information...
vvo committed Jan 23, 2013
1 parent 47cfb24 commit 7846773c2b42154bb669a33ebcb6abedd3ed9aa3
Showing with 100 additions and 32 deletions.
  1. +40 −0 tests/browse.js
  2. +11 −0 tests/browsers.local.json
  3. +11 −0 tests/browsers.saucelabs.json
  4. +38 −32 tests/functionnal.js
View
@@ -0,0 +1,40 @@
+var wd = require('wd');
+var async = require('async');
+
+module.exports = browse;
+function browse(url, desired, remoteCfg, cb) {
+ if (typeof remoteCfg === 'function') {
+ cb = remoteCfg;
+ remoteCfg = undefined;
+ }
+
+ var browser = wd.remote(remoteCfg);
+
+ // browser.on('status', logStatus);
+ // browser.on('command', logCommand);
+
+ async.series([
+ browser.init.bind(browser, desired),
+ wait4(100),
+ browser.get.bind(browser, url),
+ wait4(1000)
+ ], function(err) {
+ cb(err, browser);
+ });
+}
+
+function logStatus(info) {
+ console.log('\x1b[36m%s\x1b[0m', info);
+}
+
+function logCommand(meth, path) {
+ console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path);
+}
+
+function wait4(ms) {
+ return wait.bind(null, ms);
+}
+
+function wait(ms, cb) {
+ setTimeout(cb, ms);
+}
View
@@ -0,0 +1,11 @@
+[{
+ "browserName": "internet explorer",
+ "version": "9"
+}, {
+ "browserName": "internet explorer",
+ "version": "8"
+}, {
+ "browserName": "firefox"
+}, {
+ "browserName": "chrome"
+}]
@@ -0,0 +1,11 @@
+[{
+ "browserName": "internet explorer",
+ "version": "9"
+}, {
+ "browserName": "internet explorer",
+ "version": "8"
+}, {
+ "browserName": "internet explorer",
+ "version": "7",
+ "platform": "Windows 2003"
+}]
View
@@ -1,25 +1,37 @@
-var wd = require('wd');
var async = require('async');
var assert = require('assert');
+var baseurl = 'http://192.168.56.1:8080/tests/';
+var browse = require('./browse');
+var browsers = require('./browsers.local.json');
+var remoteCfg = {};
-var desired = {
- browserName: 'firefox'
-}
+browsers.forEach(launchTests);
-findTests(function(err, tests) {
- async.forEachSeries(tests, runTest, function(err) {
- if (err !== null) {
- assert.fail(err, null, err.message)
- }
- })
-});
+function launchTests(desired) {
+ var queue = async.queue(runTest, 2);
+
+ findTests(function(err, tests) {
+ tests.forEach(function(filename) {
+ queue.push({
+ url: baseurl + filename + '?' + Date.now(),
+ desired: desired
+ }, function(err) {
+ if (err !== null) {
+ console.error(err);
+ console.error(filename + ' was NOT OK on ' + desired.browserName + ' ' + (desired.version ? desired.version : ''));
+ } else {
+ console.log(filename + ' was OK on ' + desired.browserName + ' ' + (desired.version ? desired.version : ''));
+ }
+ });
+ });
+ });
+}
function findTests(cb) {
var fs = require('fs');
fs.readdir(__dirname, function(err, files) {
files = files.filter(isHtml);
files = files.sort();
- // files = [files[5]]
cb(null, files);
});
@@ -28,26 +40,20 @@ function findTests(cb) {
}
}
-function runTest(file, cb) {
- var browser = wd.remote();
+function runTest(opt, cb) {
+ var condition = "errorFlag === false && successFlag === true";
+ browse(opt.url, opt.desired, remoteCfg, function(err, browser) {
+ if (err !== null) {
+ console.error(arguments);
+ process.exit(1);
+ }
- async.series([
- browser.init.bind(browser, desired),
- browser.get.bind(browser, 'http://192.168.56.1:8080/tests/' + file),
- // wait for the test to execute before polling
- wait.bind(null, 1000),
- browser.waitForCondition.bind(browser, "errorFlag === false && successFlag === true", 1000, 100)
- ], function(err, results) {
- browser.quit();
- if(err !== null) {
- cb(new Error(file + ' has had an error: ' + err));
- } else {
- console.log(file + ' was OK');
- cb(null);
+ browser.waitForCondition(condition, 3000, 100, function(err, results) {
+ if (err !== null) {
+ console.error(arguments, opt.url, opt.desired);
+ process.exit(1)
}
- });
-}
-
-function wait(ms, cb) {
- setTimeout(cb, ms);
+ browser.quit(cb.bind(null, err));
+ });
+ })
}

0 comments on commit 7846773

Please sign in to comment.