問題描述
我最近正在瀏覽 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()` 是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!