Where to put implicitlyWait in Protractor?

荒凉一梦 提交于 2019-12-23 10:15:43

问题


If I want to use implicitlyWait, where I should put browser.manage().timeouts().implicitlyWait(5000); in the test?


回答1:


Add it in the onPrepare() function of your protractor's conf.js file. The reason to add implicitlyWait() there is because implicit wait is the default time that protractor waits before passing or throwing an error for an action. Letting protractor know what the implicit wait time is, even before the tests start is the best way to make use of it and onPrepare() function runs before all test suites and only once.

Example scenario:

Suppose you have the below line of code -

element(LOCATOR).getText();

in your test spec and protractor executes it after initiating the automation on page. Now, if the element with the locator specified is not found on the page, then protractor doesn't throw an error immediately, but it waits for the implicit wait time to complete. Meanwhile until implicit timeouts, it checks if the element can be located on the DOM. At the end of the implicit wait time if the element is not found, then the protractor throws the respective error. So for all the operations that you perform it is necessary to let protractor know the implicit wait time well before hand.

Usage:

onPrepare: function(){
    browser.manage().timeouts().implicitlyWait(5000);
},


来源:https://stackoverflow.com/questions/33299567/where-to-put-implicitlywait-in-protractor

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