Skip to content

Instantly share code, notes, and snippets.

@abhilashshettigar
Created December 3, 2018 12:40
Show Gist options
  • Save abhilashshettigar/48f5d54e788c776fbfa3090b383a8379 to your computer and use it in GitHub Desktop.
Save abhilashshettigar/48f5d54e788c776fbfa3090b383a8379 to your computer and use it in GitHub Desktop.
Sample code for login via Custom command
Cypress.Commands.add("Login", () => { //Making A custom command for loggin in to the application
cy.request({
method: 'POST',
url: '/users/authenticate', // Base URL will be prepended which is decalred in cypress.json
body: { //Passing Email and Password for log in
"email": "{email}",
"password": "{pass}"
}
}).then(($body) => { //Assertion for Response status should be 200
if (expect($body.status).to.eq(200)) {
localStorage.setItem('currentUser', JSON.stringify($body.body)) //Saving Auth token for further user Interactions
} else {
console.log('Login Failed', $body)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment