What is `browser.call()` for in Protractor?

只愿长相守 提交于 2019-12-18 09:37:49

问题


I've recently being going through the Protractor API and noticed the browser.call() method:

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?


回答1:


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.

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()

The this parameter represents:

The object in whose scope to execute the function (i.e. the this object for the function).

as stated in the documentation.



来源:https://stackoverflow.com/questions/40955929/what-is-browser-call-for-in-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!