问题描述
我最近正在浏览 Protractor API 并注意到 browser.call()
方法:
I've recently being going through the Protractor API and noticed the browser.call()
method:
安排一个命令在 webdriver 的控制流上下文中执行自定义函数.
Schedules a command to execute a custom function within the context of webdriver's control flow.
我想将此功能添加到我的工具包中,但我不确定我是否完全了解何时可以在实践中使用它以及它涵盖哪些用例?
I would like to add this function to my toolkit, but I am not sure I completely understand when might it be used in practice and what use cases does it cover?
推荐答案
量角器的工作方式是它有一个内部队列,用于设置函数的顺序.因此,如果您要在测试中的某个地方调用一个函数而不告诉量角器,那么该函数将在队列之外,并且该函数的实际执行可能随时发生.您可以在测试中使用 console.log("something")
进行检查,并查看它们没有按照应用程序的编写顺序执行.
the way protractor works is it has an internal queue where it sets the order of your functions. So if you were to call a function somewhere in your test without telling protractor, that function would be outside the queue and the actual execution of the function could happen anytime.
You can check that using console.log("something")
inside your tests and see that they don't execute in the order the application is written.
如果您希望某个函数在 webdriver 事件之后专门运行(意味着您要将其添加到队列中),您可以像这样在 browser.call()
中调用它
If you want a function to run specifically after a webdriver event (meaning you want to add it to the queue) you can call it inside the browser.call()
like this
browser.previousStep();
browser.call(functionX, this, parameters...)
browser.nextStep()
this
参数表示:
在其范围内执行函数的对象(即 this
函数的对象).
The object in whose scope to execute the function (i.e. the
this
object for the function).
如文档中所述.
这篇关于Protractor 中的 `browser.call()` 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!