Skip to content

Commit

Permalink
Merge pull request #14 from paypal/develop
Browse files Browse the repository at this point in the history
Remove thrown errors in favor of debug/error logging
  • Loading branch information
nikulkarni committed Nov 27, 2014
2 parents 2d9e403 + 609027d commit 9b28e80
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 278 deletions.
252 changes: 130 additions & 122 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
/*───────────────────────────────────────────────────────────────────────────*\
│ Copyright (C) 2014 eBay Software Foundation │
│ │
│ │
│ Licensed under the Apache License, Version 2.0 (the "License"); you may │
│ not use this file except in compliance with the License. You may obtain │
│ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 │
│ │
│ Unless required by applicable law or agreed to in writing, software │
│ distributed under the License is distributed on an "AS IS" BASIS, │
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
\*───────────────────────────────────────────────────────────────────────────*/
│ Copyright (C) 2014 eBay Software Foundation │
│ │
│ │
│ Licensed under the Apache License, Version 2.0 (the "License"); you may │
│ not use this file except in compliance with the License. You may obtain │
│ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 │
│ │
│ Unless required by applicable law or agreed to in writing, software │
│ distributed under the License is distributed on an "AS IS" BASIS, │
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
\*───────────────────────────────────────────────────────────────────────────*/
'use strict';

var async = require('async'),
Setup = require('./setup'),

debug = require('debug'),
log = debug('nemo:log'),
error = debug('nemo:error'),
_ = require('lodash'),
webdriver = require('selenium-webdriver');

error.log = console.error.bind(console);

/**
* Represents a Nemo instance
* @constructor
Expand All @@ -28,132 +32,136 @@ var async = require('async'),
*/

function Nemo(config) {
this.nemoData = (config && config.nemoData) ? config.nemoData : undefined,
this.waterFallArray = [],
this.preDriverArray = [],
this.postDriverArray = [],
this.plugins = {};
log('new Nemo instance created', JSON.stringify(config));
var nemoData = (config && config.nemoData) ? config.nemoData : undefined,
waterFallArray = [],
preDriverArray = [],
postDriverArray = [],
plugins = {};
//config is for registering plugins
if (config && config.plugins) {
this.plugins = config.plugins;
plugins = config.plugins;
}
}

Nemo.prototype = {
/**
*
* Nemo.setup
*@param {Object} config -
* {
* 'view': ['example-login', 'serviceError'] //optional
* ,'locator': ['wallet'] //optional
* ,<plugin config namespace>: <plugin config> //optional, depends on plugin setup
* }
*@returns webdriver.promise - successful fulfillment will return an {Object} as below:
* {
* 'view': {} //view instances if specified in config
* ,'locator': {} //locator instances if specified in config
* ,'driver': {} //driver instance. ALWAYS
* ,'wd': {} //static reference to selenium-webdriver. ALWAYS
* ,<plugin namespace>: <plugin object> //if plugin registers
* }
*/
setup: function(config) {
this.nemoData = (this.nemoData) ? this.nemoData : JSON.parse(process.env.nemoData);
config = config || {};
var me = this,
nemo = {
'props': this.nemoData,
'view': {},
'locator': {},
'driver': {},
'wd': webdriver
};
var d = webdriver.promise.defer();
me.preDriverArray = [datasetup];

Object.keys(me.plugins).forEach(function(key) {
var modulePath,
pluginConfig,
pluginModule;
return {
/**
*
* setup
* @param {Object} config -
* {
* 'view': ['example-login', 'serviceError'] //optional
* ,'locator': ['wallet'] //optional
* ,<plugin config namespace>: <plugin config> //optional, depends on plugin setup
* }
*@returns webdriver.promise - successful fulfillment will return an {Object} as below:
* {
* 'view': {} //view instances if specified in config
* ,'locator': {} //locator instances if specified in config
* ,'driver': {} //driver instance. ALWAYS
* ,'wd': {} //static reference to selenium-webdriver. ALWAYS
* ,<plugin namespace>: <plugin object> //if plugin registers
* }
*/
setup: function setup(config) {
nemoData = (nemoData) ? nemoData : JSON.parse(process.env.nemoData);
config = config || {};
var me = this,
nemo = {
'props': nemoData,
'view': {},
'locator': {},
'driver': {},
'wd': webdriver
};
var d = webdriver.promise.defer();
preDriverArray = [datasetup];

if ((me.plugins[key].register || config[key]) || key === 'view') {
//register this plugin
pluginConfig = me.plugins[key];
modulePath = pluginConfig.module;
pluginModule = require(modulePath);
if (me.plugins[key].priority && me.plugins[key].priority < 100) {
me.preDriverArray.push(pluginModule.setup);
} else {
me.postDriverArray.push(pluginModule.setup);
Object.keys(plugins).forEach(function pluginsKeys(key) {
var modulePath,
pluginConfig,
pluginModule;

if ((plugins[key].register || config[key]) || key === 'view') {
log('register plugin %s', key);
//register this plugin
pluginConfig = plugins[key];
modulePath = pluginConfig.module;
pluginModule = require(modulePath);
if (plugins[key].priority && plugins[key].priority < 100) {
preDriverArray.push(pluginModule.setup);
} else {
postDriverArray.push(pluginModule.setup);
}
}
});
waterFallArray = preDriverArray.concat([driversetup], postDriverArray);
if (config.view || (plugins && plugins.view)) {
waterFallArray.push(viewsetup);
}
});
me.waterFallArray = me.preDriverArray.concat([driversetup], me.postDriverArray);
if (config.view || (me.plugins && me.plugins.view)) {
me.waterFallArray.push(viewsetup);
}
if (config.locator) {
me.waterFallArray.push(locatorsetup);
}
async.waterfall(me.waterFallArray, function(err, result) {
if (err) {
d.reject(err);
} else {
d.fulfill(nemo);
if (config.locator) {
waterFallArray.push(locatorsetup);
}
});
return d;

//waterfall functions
function datasetup(callback) {
callback(null, config, nemo);
}
function driversetup(config, _nemo, callback) {
//do driver/view/locator/vars setup
(new Setup()).doSetup(webdriver, _nemo.props, function(err, _nemo) {
async.waterfall(waterFallArray, function waterfall(err, result) {
if (err) {
callback(err);
d.reject(err);
} else {
//set driver
nemo.driver = _nemo.driver;
callback(null, config, nemo);
d.fulfill(nemo);
}
});
}
return d;

function locatorsetup(config, _nemo, callback) {
//setup locators
config.locator.forEach(function(key) {
nemo.locator[key] = require(nemo.props.autoBaseDir + '/locator/' + key);
});
callback(null, config, nemo);
}

function viewsetup(config, _nemo, callback) {
var viewModule = _nemo.view;
if (!config.view) {
config.view = [];
//waterfall functions
function datasetup(callback) {
callback(null, config, nemo);
}
//setup views
config.view.forEach(function(key) {
if (me.plugins.view) {
//process with the view interface
viewModule.addView(key);
} else {
//old views
//dedupe step
if (nemo.view[key]) {
return;

function driversetup(config, _nemo, callback) {
//do driver/view/locator/vars setup
(Setup()).doSetup(webdriver, _nemo.props, function setupCallback(err, _nemo) {
if (err) {
callback(err);
} else {
//set driver
nemo.driver = _nemo.driver;
callback(null, config, nemo);
}
var viewMod = require(nemo.props.autoBaseDir + '/view/' + key);
nemo.view[key] = new viewMod(_nemo);
});
}

function locatorsetup(config, _nemo, callback) {
//setup locators
config.locator.forEach(function (key) {
nemo.locator[key] = require(nemo.props.autoBaseDir + '/locator/' + key);
});
callback(null, config, nemo);
}

function viewsetup(config, _nemo, callback) {
var viewModule = _nemo.view;
if (!config.view) {
config.view = [];
}
//setup views
config.view.forEach(function viewKeys(key) {
if (plugins.view) {
//process with the view interface
viewModule.addView(key);
} else {
//old views
//dedupe step
if (nemo.view[key]) {
return;
}
var viewMod = require(nemo.props.autoBaseDir + '/view/' + key);
nemo.view[key] = new viewMod(_nemo);
}

});
callback(null, config, nemo);
});
callback(null, config, nemo);
}
}
}
};
};
}

module.exports = Nemo;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"main": "index.js",
"devDependencies": {
"async": "~0.2.8",
"mocha": "~1.10.0",
"chai": "~1.6.0",
"debug": "^2.1.0",
"grunt": "~0.4.1",
"grunt-simple-mocha": "~0.4.0",
"grunt-loop-mocha": "^0.3.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-loop-mocha": "^0.3.0",
"grunt-simple-mocha": "~0.4.0",
"mocha": "~1.10.0",
"nemo-drivex": "^0.1.0",
"nemo-view": "^0.2.0",
"nemo-locatex": "^0.1.0"
"nemo-locatex": "^0.1.0",
"nemo-view": "^0.2.0"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 9b28e80

Please sign in to comment.