Reputation: 1739
I don't want to log in every time I start tests. Can I get cookies from Chrome? Or from the previous Cypress run?
Upvotes: 1
Views: 1073
Reputation: 11931
I have a tried this way, create a login()
test in commands.js
file and grab the session
details and pass it in Cypress.Cookies.preserveOnce("some_session");
I have written the test like this. Login once for rest of the tests.
note: After login > Chrome > press F12 > Application > Cookies > get the session details
//cypress/support/commands.js
Cypress.Commands.add('login', () => {
cy.visit('/')
cy.get('#email_id').type("some email");
cy.get('#password_field').type("some password");
cy.get('#submit_button_id').click();
});
describe('Preserve the login details for every test', () => {
beforeEach(() => {
cy.wait(1000);
cy.clearCookies();
cy.login();
Cypress.Cookies.preserveOnce("some_session");
});
it('Verify some tab here Test-1', function(){
//some test to do..
})
it('Verify some button here Test-2', function(){
//some test to do..
})
it('Verify some text here Test-3', function(){
//some test to do..
})
});
Upvotes: 1