1

My Cypress test cases are working fine when I run from my system pointing to QA. But the scheduled builds from CI are failing randomly because sometimes the page is taking more time to load.

I've tried cy.wait(1500) -> It works sometimes and fails sometimes. So, I was wondering is there a command in Cypress that waits till all components in the page are loaded? Instead of I try different values inside cy.wait() which in turn fails someday?

1

There's no such concept of waiting or even writing your own waits (like with Selenium) in Cypress. Cypress has this built in.

I recommend reading their docs, it's one of the core concepts mentioned here https://docs.cypress.io/guides/core-concepts/retry-ability.html#Commands-vs-assertions

The point here is, you write something like:

cy.get('.my_element')
  .should('have.length', 2)

and Cypress queries the DOM and tries to find .my_element, if it succeeds, it goes on to the assertion, if it fails, though, it queries the DOM again, and again, and again until it times out (timeouts could be configured, read about it here: https://docs.cypress.io/guides/core-concepts/retry-ability.html#Timeouts and here: https://docs.cypress.io/guides/references/configuration.html#Timeouts)

You should be aware of the fact that not every command in Cypress is retried, for example cy.click() is not retried, cos you obviously want to click only once. On the other hand, even cy.click() has its own timeout, it waits until an element becomes actionable. The point is, you have to do nothing (again unlike in Selenium) to make sure the element is actionable.

| improve this answer | |
  • Thank you @pavelsaman. Is there a way Cypress.config('pageLoadTimeout', 100000) can be put globally rather than in each spec file – A J May 11 at 23:17
  • 1
    Yes, there is. The last link in my post tells you the details. You can set pageLoadConfig in you cypress.json config file. You can have more config files and choose one with --config-file option. – pavelsaman May 12 at 6:46
  • 1
    @pavelsaman No big deal, but what is pageLoadConfig? You meant pageLoadTimeout, true? – Jeff Tanner Aug 30 at 15:04
  • 1
    @JeffTanner: correct, that's what I meant. Thank you for the correction. – pavelsaman Aug 30 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.