我正在使用不正确的凭据测试在 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) 我正在尝试在 cypress 中上传 jpeg 文件。我不太熟悉这是如何完成的。
我有以下代码:
cy.fixture(filename).then(fileContent =>
{
cy.get('#file').upload({ fileContent, filename, mimeType: 'image/JPEG', })
{ subjectType: 'input' }
})
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
给定文件中的一个或多个字段无效。请查看文档以查找支持的“fileOrArray”值