Automated tests 我们可以在cypress cy.route函数中读取和断言响应吗?

Automated tests 我们可以在cypress cy.route函数中读取和断言响应吗?,automated-tests,cypress,Automated Tests,Cypress,我在文档中找不到关于在页面上断言xhr响应的任何内容。想知道如何在代码中实现它吗?您可以使用expect 假设您按照以下方式设置cypress服务器: cy.server() cy.route({<your route details>}).as('aliasName') 然后在代码的后面,您可以使用 cy.wait('@aliasName').then(xhr => { expect(xhr.responseBody.<your Item>).to.eql(

我在文档中找不到关于在页面上断言xhr响应的任何内容。想知道如何在代码中实现它吗?

您可以使用expect 假设您按照以下方式设置cypress服务器:

cy.server()
cy.route({<your route details>}).as('aliasName')
然后在代码的后面,您可以使用

cy.wait('@aliasName').then(xhr => {
  expect(xhr.responseBody.<your Item>).to.eql('something')
})

在xhr应答器上使用回拨功能Hi Prany,您能用代码详细说明吗?对不起,刚才看到了,现在使用回拨进行应答,这是我之前的意思