我正在使用不正确的凭据测试在 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)