量角器 angularJS 全局变量 [英] protractor angularJS global variables
问题描述
我正在使用带有 angularjs 的量角器来创建我的 e2e 测试.我有很多文件,我的 specs 数组非常大,我想在所有文件中共享一个通用函数.有没有办法创建一个全局的 beforeEach 某种我可以注入我的函数的地方?export.config 对象是否公开了某些内容,以便我可以在所有文件中拥有一个公共变量?目前我正在支持浏览器"变量,但这可能是危险的.任何帮助深表感谢.谢谢
I'm using protractor with angularjs to create my e2e tests. I have many files for which my specs array is quite big and I want to share a common function across all files. Is there a way to create a global beforeEach of some sort where I can inject my function? Does the exports.config object expose something so that I can have a common variable across all files? Currently I'm piggy backing off the "browser" variable but that can potentially be dangerous. Any help is much appreciated. Thanks
推荐答案
是的,您可以使用量角器配置中的 onPrepare()hook 轻松做到这一点:
Yes, you can easily do that using the onPrepare()hook in the protractor configuration:
exports.config = {
// ...
// 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() {
// you can also add properties to globals here
}
};
这篇关于量角器 angularJS 全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!