Created
January 7, 2020 12:59
-
-
Save Mamaduka/d8b1582e37ba1d15a25aa774f26d79e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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', () => { | |
cy.request({ | |
url: '/wp-login.php', | |
method: 'POST', | |
form: true, | |
body: { | |
log: Cypress.env('wp_user'), | |
pwd: Cypress.env('wp_pass'), | |
rememberme: 'forever', | |
testcookie: 1, | |
}, | |
}); | |
}); | |
/** | |
* Logout by clearing whitelisted/preserved cookies. | |
* | |
* Currently `cy.clearCookies()` doesn't work for this. | |
* | |
* @see https://github.com/cypress-io/cypress/issues/781 | |
* @see https://github.com/cypress-io/cypress/issues/808 | |
*/ | |
Cypress.Commands.add('logout', () => { | |
cy.getCookies().then( ( cookies ) => { | |
cookies.forEach( cookie => cy.clearCookie(cookie.name) ) | |
}); | |
}); | |
/** | |
* Preserve cookies accross multiple tests. | |
* Useful when running multiple tests in same context. | |
*/ | |
Cypress.Commands.add('preserveCookies', () => { | |
Cypress.Cookies.defaults({ | |
whitelist: () => true, | |
}); | |
cy.getCookies().then( ( cookies ) => { | |
cookies.forEach( cookie => Cypress.Cookies.preserveOnce(cookie.name) ) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment