在量角器中从 onPrepare() 传递全局变量 [英] Passing global variable from onPrepare() in protractor
本文介绍了在量角器中从 onPrepare() 传递全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 onPrepare() 内部从 conf 传递全局变量.以便它可以用于不同的规格.
How to pass global variable from conf inside onPrepare(). So that it can be use in different specs.
在 onPrepare() 内部,因为我正在从我在 onPrepare() 中调用的函数中获取价值.所以想让这个价值成为全球性的.以便它可以在所有规范中使用.
Inside onPrepare() because i am getting value from function which i am calling in onPrepare(). so want to make that value as global. so that it can be use in all spec.
推荐答案
这里是我如何做全局变量 - 我在测试中使用多个浏览器,所以我需要一些快捷方式来轻松访问两个浏览器:
Here is how i did globals - i am using multiple browsers in tests, so i need some shortcuts to access both browsers easy:
onPrepare: function() {
// Making manager and user globals - they will be accessible in all tests.
global.manager = browser;
global.user = browser.forkNewDriverInstance();
...
//Making Expected Conditions global since it used widely.
global.EC = protractor.ExpectedConditions;
然后只要调用它就可以在任何地方访问
Then it will be accessible everywhere just by calling
manager.$('blabla').click();
user.$('blabla').click();
user.wait(EC.visiblityOf($('foo')), 5000, 'foo should be visible');
希望这会有所帮助!
这篇关于在量角器中从 onPrepare() 传递全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文