Where to put implicitlyWait in Protractor?

Problem

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

Problem courtesy of: winlinuz

Solution

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);
},
Solution courtesy of: Girish Sortur

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.