Fileonii
Fileonii

Reputation: 11

Could cypress wait for some element appears?

I want made cypress to wait until full of my web app will be open. Some elements load independently of each other, and I have to wait for full screen to be loaded, because after this I want to take snapshot with percy. How can I handle with it? Is it possible to make it dependent on some e.g html classes?

Upvotes: 1

Views: 2158

Answers (1)

Abhinav Nigam
Abhinav Nigam

Reputation: 591

The cypress hack for this problem would be cy.get('button', {timeout: 2000})

However, I would suggest using a library like cypress-wait-until. This would provide you with a syntax like

  cy.waitUntil(() =>
    cy.get("input[type=hidden]#recaptchatoken")
      .then($el => $el.val()))
      // ... then, check that it's valid string asserting about it
      .then(token => expect(token).to.be.a("string").to.have.length.within(1,1000));

Upvotes: 1

Related Questions