如何测试赛普拉斯禁止访问?
How to test for access prohibited in Cypress?
如何测试如果我尝试访问我未获得授权的页面,我会收到 403 响应?
这是我目前正在尝试的:
cy.visit('/sys-ops')
cy.location('pathname').should('eq', '/error/unauthorized')
你可以使用这样的东西
describe('showcase Cypress request', () => {
it('checks for 403', () => {
cy.request({
url: '/my-unauthorized-url',
followRedirect: false,
failOnStatusCode: false
}).then((resp) => {
expect(resp.status).to.eq(403)
})
})
})
在此处查找更多详细信息https://docs.cypress.io/api/commands/request#Request-a-page-while-disabling-auto-redirect
如何测试如果我尝试访问我未获得授权的页面,我会收到 403 响应?
这是我目前正在尝试的:
cy.visit('/sys-ops')
cy.location('pathname').should('eq', '/error/unauthorized')
你可以使用这样的东西
describe('showcase Cypress request', () => {
it('checks for 403', () => {
cy.request({
url: '/my-unauthorized-url',
followRedirect: false,
failOnStatusCode: false
}).then((resp) => {
expect(resp.status).to.eq(403)
})
})
})
在此处查找更多详细信息https://docs.cypress.io/api/commands/request#Request-a-page-while-disabling-auto-redirect