1

I am trying to automate a website where the testing environment is reduced and the page loads nearly two minutes(120000). I don't want to use cy.wait(120000) or cy.pause() command. Could anyone help by giving more suggestions to solve the issue even the testing environment gets slower than this. I have tried should,intercept,etc..,Other than the normal ones can someone suggest me some ideas.It wil be more helpful if you post your answers with commands.

Advance Thanks for making a try to solve this.

adiga
  • 34,372
  • 9
  • 61
  • 83
razeem
  • 43
  • 6

1 Answers1

3

cy.wait is not a good practice in most situations because it just hangs your program to wait till the end of the timeout.

I think you're looking for a solution to wait for an element appears in HTML, so I'd suggest you to check this part of the document

In your case, it should be like below

cy.get('.selector', { timeout: 120000 }).should('be.visible')

Even though the timeout is longer but whenever your .selector appears on the HTML, it will pass.

Note that, the default timeout is only 4 seconds, so if you want to have more timeout, you can modify it to longer (like 2 mins for your case).

Why do we need to have timeout? Well, basically, we don't want the program hangs forever, so that's why we need to have timeout.

Nick Vu
  • 14,512
  • 4
  • 21
  • 31
  • Thank you for your response.I got the output.But is there anyother way to get the element's response without using timeout also.@https://stackoverflow.com/users/9201587/nick-vu – razeem Mar 18 '22 at 07:00
  • 2
    I also mentioned this part `Why do we need to have timeout? Well, basically, we don't want the program hangs forever, so that's why we need to have timeout.` Cypress requires us to have a certain timeout to make the program avoid hanging forever (even though you don't pass the timeout, it will be set 4 seconds as default). With my above example, you can set the timeout like 1 day or 1 week, and as soon as you get the expected element, `cy.get` will pass and continue other next steps that is different from `cy.wait` @razeem – Nick Vu Mar 18 '22 at 07:11