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!
The global object in JavaScript is an always defined object that provides variables and functions, and is available anywhere. In a web browser, the global object is the window object, while it is named global in Node. js. The global object can be accessed using the this operator in the global scope.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With