量角器中的`browser.call()`是什么? [英] What is `browser.call()` for in Protractor?

查看:109
本文介绍了量角器中的`browser.call()`是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近正在查看量角器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.

如果您希望某个函数在网络驱动程序事件后专门运行(意味着您要将其添加到队列中),则可以像这样在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).

如文档中所述.

这篇关于量角器中的`browser.call()`是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆