Cypress-带请求负载的API调用-如何在代码中处理负载

Cypress-带请求负载的API调用-如何在代码中处理负载,cypress,Cypress,我需要帮助了解如何使用cy.route()和cy.wait()检查下面三个API调用的结果是200还是成功 HTTP地址 请求URL: 申请方式:邮寄 状态代码:200 OK 请求有效负载-根据该值,我看到三个API调用使用上述Http请求,如下所示 {CountryCode: "USA", countryRatingType: "A"} {CountryCode: "USA", countryRatingType: "B"} {CountryCode: "USA", countryRating

我需要帮助了解如何使用cy.route()和cy.wait()检查下面三个API调用的结果是200还是成功

HTTP地址

请求URL: 申请方式:邮寄 状态代码:200 OK

请求有效负载-根据该值,我看到三个API调用使用上述Http请求,如下所示

{CountryCode: "USA", countryRatingType: "A"}
{CountryCode: "USA", countryRatingType: "B"}
{CountryCode: "USA", countryRatingType: "C"}
在上述三个API调用中,countryRatingType对于各个API保持静态,但国家代码值会根据输入而变化

比如说,如果我选择CAN作为一个国家,它将是

{CountryCode: "CAN", countryRatingType: "A"}
{CountryCode: "CAN", countryRatingType: "B"}
{CountryCode: "CAN", countryRatingType: "C"}

3个API调用使用相同的url和不同的请求?这是正确的。我今天在玩,能够找到解决方案。我使用了“expect(xhr.requestBody)。包括({countryCode:CAN,countryRatingType:“A”})”并且它起了作用。后来我用fixture替换了CAN,使之成为dynamicHi@user2214507,欢迎来到stackoverflow!你回答的问题已经超过4个月了。请尝试回答新问题,这更有帮助。不要只添加代码块。解释你的答案,让造物主能够向你学习。
cy.server()
cy.route({
      method: 'POST',
      url: 'https://......../ABC',
    }).as('abc')
cy.visit('https://......../ABC') 
cy.wait('@abc').then((xhr) => {
      assert.isNotNull(xhr.response.body.data, 'call to server has data')
    })   
cy.get('@abc').should('have.property', 'status', 200)