小编ash*_*ran的帖子

如何在 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
查看次数

赛普拉斯文件上传(图片/jpeg)

我正在尝试在 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”值

jpeg file-upload cypress

4
推荐指数
1
解决办法
3501
查看次数

标签 统计

cypress ×2

bad-request ×1

file-upload ×1

javascript ×1

jpeg ×1

testing ×1