By caching and restoring cookies, localStorage, and sessionStorage data using the cy.session() command my Cypress tests now run considerably faster.
Before using cy.session() a long time was spent logging-in between tests.
Cypress.Commands.add('supportLogin', () => {
cy.visit('/');
cy.get('[data-test=login-identifier]').type('email@example.com');
cy.get('[data-test=login-password]').type('SuperSecurePassword');
cy.get('[data-test=login-button]').click();
cy.url().should('eq', Cypress.config('baseUrl'));
});
Using cy.session() the test run time went down from 31.94 seconds to 06.65 seconds.
Cypress.Commands.add('supportLogin', () => {
cy.session([], () => {
cy.visit('/')
cy.get('[data-test=login-identifier]').type('email@example.com');
cy.get('[data-test=login-password]').type('SuperSecurePassword');
cy.get('[data-test=login-button]').click();
})
cy.visit('/')
cy.url().should('eq', Cypress.config('baseUrl'));
});
Software tester. Automation enthusiast. Always learning.