量角器:如何扩展量角器库?
Protractor: How I can extend protractor library?
我想扩展标准量角器方法并创建我自己的库(或类似的东西),我可以在其中定义我自己的方法,然后在测试中使用它们。
例如:创建方法 by.MyAttribute('attributeName')
并将其用作全局方法。
也许有人知道我该怎么做?
要在 protractor
中全局使用某些内容,请在 onPrepare()
:
中使用 global
onPrepare: function () {
global.myvariable = "Hello, world!";
},
尽管如此,您还是应该明智地使用全局变量 - 它们会污染命名空间并使您的代码更难调试。或者,使用 require()
将您的库导入测试范围。
请注意,如果您正在编写自己的定位器,则应使用 by.addLocator()
,请参阅:
- How to globally add a custom locator to Protractor?
我想扩展标准量角器方法并创建我自己的库(或类似的东西),我可以在其中定义我自己的方法,然后在测试中使用它们。
例如:创建方法 by.MyAttribute('attributeName')
并将其用作全局方法。
也许有人知道我该怎么做?
要在 protractor
中全局使用某些内容,请在 onPrepare()
:
global
onPrepare: function () {
global.myvariable = "Hello, world!";
},
尽管如此,您还是应该明智地使用全局变量 - 它们会污染命名空间并使您的代码更难调试。或者,使用 require()
将您的库导入测试范围。
请注意,如果您正在编写自己的定位器,则应使用 by.addLocator()
,请参阅:
- How to globally add a custom locator to Protractor?