如何捕获赛普拉斯中的所有API调用?

问题描述:

我在加载聊天应用程序时有API调用,每组30个调用(每个组中加载最后30条消息)。假设某情况下,我测试的用户只有两个组。因此,我希望能看到60个API调用。

I have API call when loading a chat app, 30 calls/group (it's to load last 30 messages on each group). Let's say in a case, I test a user which has 2 groups only. So I expect to see 60 API calls for this.

我尝试了以下代码。

it('Call 30 group messages APIs for every favorite group', () => {
    cy.server()
    cy.route(awsUrl + '/**').as('apiMessageContent')

    for (let i = 0; i < 60; i++) {
      cy.wait('@apiMessageContent', { timeout: 30000 }).then(res => {
        expect(res.status).not.to.be.null
      })
    }
  })

但是结果赛普拉斯随机只能捕获28-30个API调用,此后其他路由等待失败。实际上,在赛普拉斯的左侧面板中,我可以看到列出了所有的60 XHR。对此有什么解决方案?

But the result cypress randomly only can capture 28-30 API calls, and other route waits after that are failing. In fact, in cypress left panel I can see the 60 XHR are all listed. What is the solution for this?

cy.wait 可以接受别名数组,因此您可以等待 @apiMessageContent 这样,而不是循环并等待60次。虽然尚不清楚您的解决方案为何不起作用。

cy.wait can accept an array of Aliases, so you might be able to wait for @apiMessageContent in this way, rather than looping and waiting 60 times. Although it's unclear why your solution does not work.

cy.wait(Array(60).fill('@apiMessageContent'), { timeout: 30000 }).then((xhrs) => {
    xhrs.forEach((res) => {
        expect(res.status).not.to.be.null
    })
})