Automation testing

4. How to use waitUntil?

How can I use wait until?

Let's start with: How does it work?

  • waitUntil is constantly checking if the returning condition is true.
  • After curly brace you see 10000, it is timeout in milliseconds.
  • Then you see a string which is just an error message to show if 10 seconds have gone but true was not returned. Example conclusion: Wait 10 seconds for a fake link to be displayed. If it will not be displayed, a show the following error "Fake Link did not show up after 10 seconds".

// It waits for true to be returned
browser.waitUntil(() => {
           return yourPageObject.fakeLnk.isDisplayed();
       }, { timeout: 10000, timeoutMsg:'Fake Link did not show up after 10 seconds'});
WaitUntil 10 elements are visible

browser.waitUntil(() => {
           return $$('.tenElementsClass').map((elem) => elem.isDisplayed()).length > 9;
           // Same code below but element is in page object
           // return pageObj.yourElements.map((elem) => elem.isDisplayed()).length > 9;
       }, { timeout: 10000, timeoutMsg:'Ten elements were not visible'});
WaitUntil text equals to expected

browser.waitUntil(() => {
           return yourPageObject.fakeTextLbl.getText() === 'I love rock & roll!'
       }, { timeout: 10000, timeoutMsg:'"I love rock & roll "'});
WaitUntil text is not there

browser.waitUntil(() => {
           return yourPageObject.fakeTextLbl.getText() != 'I love rock & roll!'
       }, {timeout: 10000, timeoutMsg:'"I love rock & roll "'});
WaitUntil url contains word friends

browser.waitUntil(() => {
   return browser.getUrl().includes('/friends');
       }, {timeout: 10000, timeoutMsg:'"I love rock & roll "'});
Previous Article
3. What is wdio.conf.js?
Automation testing
Next Article
5. How to use MAP?
Automation testing
We help ambitious people to get into Tech with no prior experience.