Question

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!

Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top