Pages

Waits in protractor ?

Implicit and explicit wait in protractor ?

Implicit wait :
  • It will effects all elements available in website and once we set implicit wait ,it will set for the life of session.
  • WebDriver polls the DOM for a certain duration when trying to find any element. This can be useful when certain elements on the webpage are not available immediately and need some time to load.
  • The default setting is 0, meaning disabled
  • If element found within the given implicit wait time, selenium moves to next commands in program without waiting to complete the total implicitly wait time. It is also called as dynamic wait.
  • Most of the time we will use implicit wait in conf.js file(s).
browser.manage().timeouts().implicitlyWait(30000);
Explicit wait :
  • The name itself saying, explicitly we are setting certain amount of time for an particular web element.
  • Explicit wait will pass the condition to halt the program execution for certain amount of time.This means that for as long as the condition returns a falsy value, it will keep trying and waiting.
  • Since explicit waits allow you to wait for a condition to occur, they make a good fit for synchronising the state between the browser and its DOM, and your WebDriver script.
  • ExplicitWait does not have any effect on element and element.all. ExplicitWat also called WebdriverWait.
  • ExplicitWait, by default, calls the ExpectedCondition every 500 milliseconds until it returns successfully.
browser.wait(conditions)
  • Protractor provides ExpectedConditions class which will provide wait conditions.
  • We have to use those wait conditions from ExpectedConditions class.
  • It is a library of canned expected conditions that are useful for protractor, especially when dealing with non-angular apps.
  • Each wait condition returns a function that evaluate to a promise.
Below are wait conditions present in ExpectedConditions class provided in protractor:
  • alertIsPresent
  • elementToBeClickable
  • textToBePresentInElement
  • textToBePresentInElementValue
  • titleContains
  • titleIs
  • urlContains
  • urlIs
  • presenceOf
  • stalenessOf
  • visibilityOf
  • invisibilityOf
  • elementToBeSelected
  • not
  • and
  • or
We will learn each wait condition in next posts 😄

Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.