量角器angularJS全局变量

量角器angularJS全局变量

本文介绍了量角器angularJS全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用量角器与angularjs创建我的端到端测试。我有很多文件而我的规格阵列是相当大的,我想在所有文件中都有一个共同的功能。有没有一种方法来建立某种形式在那里我可以注入我的函数的全局beforeEach?
是否exports.config对象暴露的东西,这样我就可以有在所有文件中一个共同的变量?
我目前小猪釜底抽薪的浏览器变量但有可能是危险的。任何帮助深表AP preciated。谢谢

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

推荐答案

是的,你可以很容易地做到这一点使用上的prepare()钩量角器配置:

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全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 16:43