derby-webdriverio
Version:
Webdriver.io for Derby.js
122 lines (108 loc) • 4.72 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var Bluebird, addCustomCommands, chai, chaiAsPromised, exec, isNumber, natural, nounInflector, spawn, waitServer, webdriverio,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Bluebird = require('bluebird');
natural = require('natural');
nounInflector = new natural.NounInflector();
isNumber = require('lodash/isNumber');
chai = require('chai');
chaiAsPromised = require('chai-as-promised');
webdriverio = require('webdriverio');
addCustomCommands = require('./commands');
waitServer = require('./waitServer');
spawn = require('child_process').spawn;
exec = require('child_process').exec;
module.exports = function(webdriverConf, customBefore) {
return function() {
var groupName, ref, ref1, value;
ref = webdriverConf.browsers;
for (groupName in ref) {
value = ref[groupName];
if (value === 1 || value === true) {
global[groupName] = webdriverio.remote(webdriverConf);
} else if (isNumber(value) && value > 0) {
global[groupName] = webdriverio.multiremote((function() {
var i, j, ref1, res, singularName;
res = {};
singularName = nounInflector.singularize(groupName);
for (i = j = 0, ref1 = value; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
res[singularName + i] = webdriverConf;
}
return res;
})());
} else {
throw new Error("Wrong number of instances specified for '" + groupName + "' browser group. It must be a number (for multiremote testing) or 'true' (for a single browser)");
}
}
chai.Should();
chai.use(chaiAsPromised);
if (indexOf.call(Object.keys(webdriverConf.browsers), 'browser') < 0) {
global.browser = global[Object.keys(webdriverConf.browsers)[0]];
}
chaiAsPromised.transferPromiseness = global.browser.transferPromiseness;
ref1 = webdriverConf.browsers;
for (groupName in ref1) {
value = ref1[groupName];
addCustomCommands(global[groupName]);
}
return Bluebird.resolve().then(function() {
var dbName, ref2;
dbName = (ref2 = webdriverConf.server.env.MONGO_URL.match(/\/([^\/]*)$/)) != null ? ref2[1] : void 0;
return new Bluebird(function(resolve, reject) {
return exec("mongo " + dbName + " --eval \"db.dropDatabase();\"", function() {
return resolve();
});
});
}).then(function() {
return typeof customBefore === "function" ? customBefore() : void 0;
}).then(function() {
var envStr, key;
envStr = (function() {
var ref2, results;
ref2 = webdriverConf.server.env;
results = [];
for (key in ref2) {
value = ref2[key];
results.push(key + "=" + value);
}
return results;
})();
envStr = envStr.join(' ');
global.__runningServer = spawn('/bin/sh', ['-c', envStr + " " + webdriverConf.server.startCommand], {
detached: true
});
global.__runningServer.stdout.on('data', function(data) {
return console.log(data.toString('utf8'));
});
global.__runningServer.stderr.on('data', function(data) {
return console.log(data.toString('utf8'));
});
global.__runningServer.on('exit', function(code) {
console.log('Server exited with code ' + code);
return global.__runningServerExited = true;
});
return void 0;
}).then(function() {
return waitServer(webdriverConf.server.waitServer);
}).then(function() {
return Bluebird.mapSeries(Object.keys(webdriverConf.browsers), function(groupName) {
var amount, j, results, singularName;
amount = webdriverConf.browsers[groupName];
if (amount === 1 || amount === true) {
return global[groupName].init().timeoutsAsyncScript(webdriverConf.waitforTimeout);
} else {
singularName = nounInflector.singularize(groupName);
return Bluebird.mapSeries((function() {
results = [];
for (var j = 0; 0 <= amount ? j < amount : j > amount; 0 <= amount ? j++ : j--){ results.push(j); }
return results;
}).apply(this), function(i) {
return global[groupName].select(singularName + i).init().timeoutsAsyncScript(webdriverConf.waitforTimeout);
});
}
});
});
};
};
}).call(this);