File Structure
01.spec.js - - - I call helpers from the protractor specs which is fine
describe('should click on element', function () {
var helper1 = require('../../modules/helpers/helper1.js');
it('should click and assert...', function() {
helper1.clickOnCircle('Accounts');
});
});
...But to use any helper functions from another helper file...
helpers1.js - - - I have to require the helper in every function
module.exports = {
clickOnCircle: clickOnCircle,
clickOnBox : clickOnBox
};
var helper2 = require('./helper2.js'); //node require doesn't hit something like this
function clickOnCircle(circleText) {
var helper2 = require('./helper2.js'); //needed in every function
helper2.doSomething(circleText);
}
function clickOnBox(boxText) {
var helper2 = require('./helper2.js'); //needed in every function
helper2.doSomething(boxText);
}
It's almost like I want the helper files to be available globally. I've messed around using configuration parameters but I still end up having to require the helper from each function.
here is a brief example of how we use our helpers and page objects. We have a file called helper.js and all of our page objects are in the pages folder. We are using the require-all node module to help us include all our page objects.
then this is a template of how we would have one of those pages
You can load other modules just once at the beginning of your module and then reference them anywhere from within that module.
This should work just fine:
What about using inheritance,
for example:
This also makes a class for you to use in the module. This places the
exports
at the bottom of the page allowing thehelper
variable to stay scoped as global instead of scoped outside yourmodule.exports