我有大约20个spec文件,其中大多数使用相同的函数重复。我可以将全局函数放在每个spec文件可以使用的conf.js文件中吗?我读了这页http://stackoverflow.com/questions/21320400/protractor-angularjs-global-variables
,但它不是很有帮助,我无法让它发挥作用。我尝试在onPrepare
中放置一个函数,但是spec文件找不到它。我也试过global.viewByAds = function () {...};
如果有人能帮助我,我真的很感激!
答案 0 :(得分:10)
你可以简单地添加一个js文件并使用require
helper.js:
module.exports = {
foo: 'bar',
doSomething: function () {
return 1+1;
}
};
在你的规格中:
//require helper.js at specs
var helper = require('./helper.js');
helper.doSomething()