0

我被困在尝试使用发送 POST 请求和正文的自定义命令以注册和登录用户身份运行测试。

然后在 beforeEach 钩子中的测试套件中,我尝试创建用户然后登录:

beforeEach(() => {
    cy.createUser().then((user) => {
      cy.login(user);
    });
  });

每当我运行测试 cypress trhows 错误时:

CypressError: `cy.request()` failed on:

http://localhost:3000/register

The response we received from your web server was:

  > 404: Not Found

This was considered a failure because the status code was not `2xx` or `3xx`.

If you do not want status codes to cause failures pass the option: `failOnStatusCode: false`

这是我在自定义命令中所做的:

cy.visit('/').then(() => {
    cy.request({
      url: '/register',
      method: 'POST',
      body: user,
    }).then((response) => ({ ...response.body.user, ...user }));
  });

为什么会这样?请任何反馈将不胜感激。我也尝试过使用旗帜failOnStatusCode: false,但没有奏效。

非常感谢。

4

0 回答 0