Speeding Up Cypress

By caching and restoring cookies, localStorage, and sessionStorage data using the cy.session() command my Cypress tests now run considerably faster.

Slow

Before using cy.session() a long time was spent logging-in between tests.

Slow

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'));
});

Speedy

Using cy.session() the test run time went down from 31.94 seconds to 06.65 seconds.

Slow

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'));
});

Emma Elkan

Software tester. Automation enthusiast. Always learning.