Reputation: 1471
I have about 20 spec files and most of them use the same functions repeated in each one. Can I put global functions in the conf.js file that each spec file can use? I read this page http://stackoverflow.com/questions/21320400/protractor-angularjs-global-variables
, but it wasn't very helpful and I can't get it working. I tried putting a function in onPrepare
, but the spec files can't find it. I also tried doing global.viewByAds = function () {...};
If anyone can help me I'd really appreciate it!
Upvotes: 11
Views: 5667
Reputation: 4351
you could simply add a js file and use require
helper.js:
module.exports = {
foo: 'bar',
doSomething: function () {
return 1+1;
}
};
in your specs:
//require helper.js at specs
var helper = require('./helper.js');
helper.doSomething()
Upvotes: 9