HomeWebDriverIO

WebDriverIO – Wait Commands

WebDriverIO – Wait Commands

<<Previous Post                          << Complete Tutorial>>                             Next Post>>

Wait Commands in WebDriverIO

Sometimes on testing a page we need to wait for something to happen on a page before we proceed. i.e., an element needs to appear or an element needs to go away before you do something.

WebdriverIO provides multiple commands to wait on elements to reach a certain state (e.g. displayed,enabled,existing). These commands take a selector argument and a timeout number which declares how long the instance should wait for that element to reach the state.

There are 4 types of wait commands in WebDriverIO which are as follows :-

  1. waitForDisplayed
  2. waitForEnabled
  3. waitForExist
  4. waitUntil

Let’s understand them one by one with example.

Pre-requisites:

Go through our previous articles on WebDriverIO if you are new to this Automation tool (Click here to view our complete tutorial)

waitForDisplayed

This command waits for an element for the provided amount of milliseconds to be displayed or not displayed.

Exercise:-

  1. Navigate to https://the-internet.herokuapp.com/dynamic_loading/1.
  2. Click on Start Button.
  3. Assert the ‘Hello World’ Text.

Syntax:

Sample Code for waitForDisplayed:

waitForEnabled

This command waits for an element (selected by css selector) for the provided amount of milliseconds to be (dis/en)abled.

Exercise:-

  1. Navigate to https://the-internet.herokuapp.com/dynamic_controls.

2. Click on Enable Button.

3. Wait for button to be enabled.

4. Add value test in enabled text box.

Syntax:

Sample Code for waitForEnabled:

waitForExist

This command waits for an element for the provided amount of milliseconds to be present within the DOM. Returns true if the selector matches at least one element that exists in the DOM, otherwise throws an error.

Exercise:-

  1. Navigate to https://the-internet.herokuapp.com/dynamic_loading/2.
  2. Click on Start Button.
  3. wait for element to be present in DOM.

 

Syntax:

Sample Code for waitForExist:

waitUntil

This wait command is your universal weapon if you want to wait on something. It expects a condition and waits until that condition is fulfilled with a truth value.

Exercise:-

  1. Navigate to https://the-internet.herokuapp.com/dynamic_controls.
  2. Click on Remove Button.
  3. Wait till checkbox gets removed from the page.

    Syntax:

     

    Sample Code for waitUntil

    Next Steps:

    > To learn more about WebDriverIO, continue to the next post (Click on Next Post link below)

    > Check complete WebDriverIO Tutorial Contents here (Click here)

    Please leave your questions/comments/feedback below.

    Happy Learning 🙂

    About Me > Ajay Lunia 

    Connect to me on Linked In (Click here)

    On a mission to contribute to the Software Testing Community in all possible ways.

    <<Previous Post                          << Complete Tutorial>>                             Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *