0

在此处输入图像描述在此处输入图像描述在此处输入图像描述在附件中,我放了来自同一个测试用例的屏幕截图,它们之间有几秒钟的差异。

我想知道为什么每次尝试相同的测试用例结果都是 4xx、5xx、2xx?我怎样才能避免它?会不会和等待有关?

PS 我和 DevOps 团队谈过,他们说环境是稳定的。

Spec.js

it.only("buy a fix priced vehicle", () => {
    const minPrice = 26350;
    //const maxPrice = 1000000;
    //const offerAmount = Math.floor(Math.random() * maxval) + minval;
    const vehicleIdBuyNow = "30f269ac675813a68885ce336971d897";
    const platformIdBuyNow = "yyyy";
    const platformUserIdBuyNow = 0;
[![enter image description here][1]][1]
    cy.request({
      
      method: "POST",
      url: "xxxxxx",

      headers: {
        Authorization:
          "tttttt",
        "content-type": "application/json",
      },

      body: {
        id: vehicleIdBuyNow,
        bid: minPrice,
        auctionPlatformId: platformIdBuyNow,
        auctionPlatformUserId: platformUserIdBuyNow,
      },

      failOnStatusCode: false,
    }).then((res) => {
      cy.wait(2000)
      // Assertion for one by one
      //cy.log(res)
      //if ( res.status==404 || res.status==400 || res.status==500 || res.status==503) {

        if ( res.status!=200) {
        cy.log(JSON.stringify(res))
      } else {
        expect(res.body.id).to.eq(
                vehicleIdBuyNow
              );
              expect(res.body.auctionStatus).contains("finished");
              expect(res.body.price).to.be.equal(minPrice);
              expect(res.body.winningBidPlatformId).contains(platformIdBuyNow);
              expect(true).to.be.true;
              expect(false).to.be.false;
              //Assertion in one time
              
            //   for (const index of res.body.suggestedPrices) {
            //     expect(res.body.suggestedPrices[index].amount).to.be.within(
            //       minPrice,
            //       maxPrice
            //     );
            //  }
              assert.isNotNull(res.amount, "is not null");
              assert.isNotNull(res.body.id, "is not null");
              assert.isNotNull(res.body.createdAt, "is not null");
      }
    })


4

1 回答 1

1

我不确定赛普拉斯的异步时序问题是否会导致相同的请求返回这些不同的响应。

我建议仔细查看 cy.request 中发送的内容,并比较通过和失败的场景。如果您单击 cy gui 中的请求,控制台将具有请求和响应。

有时在您的测试中发出大量请求可能会使您的服务器不堪重负,从而导致不同的响应。但是,如果您在单独运行单个测试时看到此问题,则可能会排除此问题。

尝试处理请求时,500 往往是未处理的服务器错误。也许您可以在标头中添加一个唯一的 id 并使用 devops 对其进行跟踪以查看更多详细信息。

您的请求能否使项目处于重复测试然后失败的特定状态?

如果你仍然卡住,看看你是否看到 curl/postman 的类似行为

注意:测试中的 cy.wait(2000) 不会产生任何影响,因为响应已经在该阶段传递到函数中。只是延迟验证

于 2021-10-12T15:30:51.953 回答