我最近正在浏览 Protractor API并注意到 browser.call()
method :
Schedules a command to execute a custom function within the context of webdriver's control flow.
我想将此功能添加到我的工具包中,但我不确定我是否完全理解它何时可以在实践中使用以及它涵盖哪些用例?
最佳答案
Protractor 的工作方式是它有一个内部队列,用于设置函数的顺序。因此,如果您要在测试中的某个位置调用函数而不告诉 Protractor ,则该函数将位于队列之外,并且该函数的实际执行可能随时发生。
您可以在测试中使用 console.log("something")
进行检查,并查看它们是否按照应用程序编写的顺序执行。
如果您希望某个函数在 Webdriver 事件之后专门运行(意味着您希望将其添加到队列中),您可以在 browser.call()
中调用它,如下所示
browser.previousStep();
browser.call(functionX, this, parameters...)
browser.nextStep()
this
参数代表:
The object in whose scope to execute the function (i.e. the
this
object for the function).
如文档中所述。
关于javascript - Protractor 中的 `browser.call()` 代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40955929/