Created
December 3, 2018 12:40
-
-
Save abhilashshettigar/48f5d54e788c776fbfa3090b383a8379 to your computer and use it in GitHub Desktop.
Sample code for login via Custom command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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