Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put implicitlyWait in Protractor?

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

like image 585
winlinuz Avatar asked Oct 23 '15 09:10

winlinuz


People also ask

How do you wait for an element to be visible in a Protractor?

wait(function () { return elem. isDisplayed(); });

What is browser wait?

browser. wait() on the other hand works differently. You provide an Expected Condition function for Protractor/WebDriverJS to execute and wait for the result of the function to evaluate to true.


1 Answers

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);
},
like image 180
giri-sh Avatar answered Sep 21 '22 02:09

giri-sh