Reputation: 767
I am trying to call a custom function in the onPrepare method in my local protractor config which extends a global protrator config but am not able to get it to work. Inorder to make it a bit more simpler I wrote it like this inside my protractor.config
module.exports = {
foo: function() {
console.log('testing');
},
// A callback function called once protractor is ready and available, and
// before the specs are executed
// You can specify a file containing code to run by setting onPrepare to
// the filename string.
onPrepare: function() {
// At this point, global 'protractor' object will be set up, and jasmine
// will be available. For example, you can add a Jasmine reporter with:
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
// 'outputdir/', true, true));
console.log(foo);
},
};
My local.protractor.config is
var globalConf = require('./protractor.conf.js');
exports.config = globalConf;
But I get the error as foo being undefined.
[launcher] Error: ReferenceError: foo is not defined
Is there a way to add a custom method that onprepare can call which I can call from in my local.protractor.config
Upvotes: 0
Views: 6184
Reputation: 3091
Try this (move your function away from exporting object):
var foo = function () {
console.log('BAR')
}
exports.config = {
//other params here
onPrepare: function() {
foo()
},
//other params here
};
Upvotes: 1