Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...