cypress custom commands call with parameters with synchronous code example
Example: cypress custom command with this
Cypress.Commands.add('login', (userType, options = {}) => {
const types = {
admin: {
name: 'Jane Lane',
admin: true,
},
user: {
name: 'Jim Bob',
admin: false,
}
}
const user = types[userType]
cy.request({
url: '/seed/users',
method: 'POST',
body: user,
})
.its('body')
.then((body) => {
cy.request({
url: '/login',
method: 'POST',
body: {
email: body.email,
password: body.password,
}
})
})
})