module.exports = { groupGlobals : null, checkGroupGlobals : function(hookName) { if (hookName && this.groupGlobals) { return this.groupGlobals[hookName]; } if (this.test_settings.group_name) { try { this.groupGlobals = require('../globals/' + this.test_settings.group_name.toLowerCase() + '.js'); if (hookName) { return this.groupGlobals[hookName]; } } catch (err) { return false; } } return false; }, endSession : function(client, done) { if (client.sessionId) { client.end(function() { done(); }); } else { done(); } }, before: function (done) { var beforeGroup = this.checkGroupGlobals('before'); if (beforeGroup) { beforeGroup.call(this, done); } else { done(); } }, after: function (done) { var afterGroup = this.checkGroupGlobals('before'); if (afterGroup) { afterGroup.call(this, done); } else { done(); } }, beforeEach: function (client, done) { var beforeGroupEach = this.checkGroupGlobals('beforeEach'); if (beforeGroupEach) { beforeGroupEach.call(this, client, done); } else { done(); } }, afterEach : function (client, done) { var afterGroupEach = this.checkGroupGlobals('afterEach'); if (afterGroupEach) { afterGroupEach.call(this, client, function() { this.endSession(client, done); }.bind(this)); } else { this.endSession(client, done); } } };