Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Created January 7, 2020 12:59
Show Gist options
  • Save Mamaduka/d8b1582e37ba1d15a25aa774f26d79e8 to your computer and use it in GitHub Desktop.
Save Mamaduka/d8b1582e37ba1d15a25aa774f26d79e8 to your computer and use it in GitHub Desktop.
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