'Cypress cache - server session expired

Can Cypress clear browser cookies/cache before each test?

The problem I am experiencing is the first execution is ok, but the second fails due to the cache. I tried cy.clearCookies(), but it doesn't work.

During the second execution, I receive the message server session expired.



Solution 1:[1]

Though I think by default each it block starts with a clear cache. The following command may be useful for your purposes

cy.clearLocalStorage()

Doc here: https://docs.cypress.io/api/commands/clearlocalstorage#Command-Log

You could possibly wrap this like so

before(function () {
cy.clearLocalStorage();
});

describe("Some useful description", () => {
// your 'it' blocks here
})

Alternatively, if you wanted to programmatically clear your cache after each test, try:

describe("Some useful description", () => {

 afterEach(() => {
    cy.clearLocalStorage()
});

// your 'it' blocks here
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1