问题
I need Cypress to wait for any xhr requests to complete by default before performing any operations. Is there any way to make this as a default or any other alternatives because the application I am testing is slow and makes a lot of api calls?
Edit: By writing a single statement for every api request is getting messy and unnecessary work. Need a way to make this easier.
回答1:
Found something that works for me here https://github.com/PinkyJie/cypress-auto-stub-example
Look for cy.waitUntilAllAPIFinished
回答2:
If what you want is to wait for a specific xhr you can do it making use of cy.route()
. I use this in some scenarios and it is really useful. The general steps to use it are:
cy.server()
cy.route('GET','**/api/my-call/**').as('myXHR');
- Do things in the UI such as clicking on a button that will trigger such api calls
cy.wait(@myXHR)
This way if such call isn't triggered your test will fail. You can find extensive documentation about this here
来源:https://stackoverflow.com/questions/54766816/cypress-request-wait-by-default