相关疑难解决方法(0)

如何在 cypress 中测试错误的请求

我正在使用不正确的凭据测试在 cypress 中登录 POST 方法。这将返回 400 个我需要测试的错误请求。

这就是我所拥有的:

describe('Login API Test - Correct user login', () => {
  it('Validate the header', () => {
    cy.request({
      method: 'POST',
      url: 'https://myrAPI',
      auth: {
        username: 'user@user',
        password: 'user123',
      },
      headers: {
        'Authorization': 'Basic dXNlckB1c2VyOnVzZXI=',
        'Content-Type': 'text/plain'
      }
    }).then((response) => {
      // expect(response.body).to.exist // true
      // expect(response.body).('User.Access: Exception occured:User.Access : CheckUser: Exception occurred:Error with Authentication Header. result =') // true
      // expect(response.headers).should.contain('text/plain; charset=utf-8')
      // expect(response.body).statusCode.should.equal(400)
      response.status.should.equal(400)
      //expect(response).to.have.property('headers')
    })
  }})
Run Code Online (Sandbox Code Playgroud)

发送的请求:

Method: POST
URL: https://myapi …
Run Code Online (Sandbox Code Playgroud)

javascript testing bad-request cypress

13
推荐指数
2
解决办法
8765
查看次数

标签 统计

bad-request ×1

cypress ×1

javascript ×1

testing ×1