cypress command.js visualize code example
Example 1: how to run cypress test
./node_modules/.bin/cypress run
Example 2: 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,
}
})
})
})