Timed out retrying after 4000ms: Expected to find element

This issue has been tracked since 2021-11-13.


I am trying to use this, as such (magento 2 site)

cy.waitUntil(() => cy.get('.loader > img').length == 0, {
            interval: 100 // performs the check every 500 ms, default to 200

which is to detect if a loader is busy in checkout process, however, once that loader is removed in DOM, I get

Timed out retrying after 4000ms: Expected to find element: .loader > img, but never found it.

Because this error occurred during a before each hook we are skipping the remaining tests in the current suite: Checkout Payment Methods
  56 |         cy.get('#top-cart-btn-checkout').should('be.visible')
  57 |         cy.get('#top-cart-btn-checkout').click()
> 58 |         cy.waitUntil(() => cy.get('.loader > img').length == 0, {
     |                               ^
  59 |             interval: 100 
  60 |         });
  61 | 

Image for visual


Likely just a syntax/usage issue, but can't figure it out.
Appreciate your effort.

NoriSte wrote this answer on 2021-11-13

Hi @ProxiBlue
You can't put assertions inside the checkFunction passed to cy.waitUntil. In this case, you didn't insert any assertion directly, but cy.get contains assertions itself, take a look at its docs. You should replace it as follows

-cy.get('.loader > img').length == 0
+Cypress.$('.loader > img').length == 0

let me know if it works.

ProxiBlue wrote this answer on 2021-11-14

It works, thanks a million.

More Details About Repo
Owner Name NoriSte
Repo Name cypress-wait-until
Full Name NoriSte/cypress-wait-until
Language JavaScript
Created Date 2019-04-27
Updated Date 2023-03-19
Star Count 635
Watcher Count 8
Fork Count 24
Issue Count 3


Issue Title Created Date Updated Date