testcafe api 测试使用角色进行身份验证

问题描述 投票:0回答:0

我已经能够使用 testcafe 的

Roles
来验证 UI 测试,但现在我正在尝试编写一些 API 测试。 API测试似乎不支持经过身份验证的角色(通过
t.request
)b / c我注意到当使用
authorization
角色时,
t.request
标头未附加到请求。这是我试图开始工作的代码示例,但是当我检查服务器中的请求对象时,请求中缺少
authorization
标头。如果我需要为 API 测试的身份验证做一些不同的事情,有什么想法吗?

顺便说一句,我在登录页面中使用 AWS Cognito 进行身份验证。

fixture`api test`
  .beforeEach(async t => {
    // qaRole is defined separately, but it basically goes through our login screen
    // which makes authentication request to AWS Cognito
    await t.useRole(qaRole) 
  })

test('make api call', async t => {
  const result = await t.request({url: `/api/orders`})
  await t.expect(result.status).eql(200)
})
testcafe
© www.soinside.com 2019 - 2024. All rights reserved.