cypress-io / cypress-documentation

Cypress Documentation including Guides, API, Plugins, Examples, & FAQ.

Home Page:https://docs.cypress.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cy.intercept() 顺序问题

javanf opened this issue · comments

Description

当cy.intercept().as('xxx')在点击事件之前,cy.wait('@xxx')能捕获响应,但是经常捕获的响应是前一次的响应。如果放在点击事件之后, Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: ticketTypeAnalysis. No request ever occurred.

URL of Issue(s)

https://docs.cypress.io/api/commands/intercept#Intercepted-responses

Steps to replicate

1、正常逻辑点击后,捕获点击的请求响应

cy.get('.el-button').click()
cy.intercept('POST', '**/xxx').as('name')
cy.wait('@name')

但是这种写法,直接报错,声明下不是接口响应太慢
Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: ticketTypeAnalysis. No request ever occurred

2、cypress推荐逻辑,先监听,后点击,捕获:https://docs.cypress.io/api/commands/intercept#Intercepted-responses,文档都是这种写法。

cy.intercept('POST', '**/xxx').as('name')
cy.get('.el-button').click()
cy.wait('@name')
`

但是这种写法,经常捕获到的是错误的响应,都是前一个请求的响应数据。

### Browser

_No response_

### Device

- [X] PC
- [ ] Mac
- [ ] iPhone
- [ ] iPad
- [ ] Android Phone
- [ ] Android Tablet

### Additional Information

_No response_

Closing. This repo is for documentation. The given example cannot be run given the information, so we cannot reproduce.

Don't solve the problem?

The above example code involves interface addresses, which need to be modified to copy and run locally.