简体   繁体   中英

Where to put implicitlyWait in Protractor?

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

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);
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM