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

后端 未结 1 773
失恋的感觉
失恋的感觉 2020-12-21 19:39

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

Schedules a command to execute a custom function within t

相关标签:
1条回答
  • 2020-12-21 20:28

    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.

    0 讨论(0)
提交回复
热议问题