Cypress request wait by default?

白昼怎懂夜的黑 提交于 2019-12-10 20:55:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!