我正在尝试测试我们的API,但是每个API都带有承载令牌。
当我通过整个承载令牌时,测试通过
但是我如何在不必放入整个令牌的情况下重新生成令牌?
// const bearerToken = 'adakdkadamdamdaksdwe232'
const urlConstructed = 'https://someAPI.com/admin/api/v1/customers?orgId=79649057-5edc9ff5b377'
describe('API TEST', function () {
before(() => {
preventClearStorage();
Login(auth.admin2.email, auth.admin2.password);
cy.reload()
})
it('Test API', () => {
//const token = cy.window.localStorage.getItem('access_token')
const token = cy.window().its('sessionStorage')
console.log(JSON.stringify(token))
cy.request({
method: 'GET',
url: urlConstructed,
headers: {
Accept: 'application/json',
Authorization: 'Bearer ' + token,
},
timeout: 120000,
failOnStatusCode: false
}).then((response) => {
expect(response).to.have.property('status', 200)
})
})
})