Here's an example of adding a command cy.login()
that you can use in any Cypress test, or put in a beforeEach
hook.
Cypress.Commands.add('login', () => {
cy.request({
method: 'POST',
url: 'http://localhost:3000/api/users/login',
body: {
user: {
email: '[email protected]',
password: 'jakejake',
}
}
})
.then((resp) => {
window.localStorage.setItem('jwt', resp.body.user.token)
})
})
Then in your test:
beforeEach(() => {
cy.login()
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…