Whenever my test case fails i need to go & clear the cookies manually form cypress dashboard browser otherwise my url does not load whenever i re-run the test case
describe('My Test Suite', () => {
beforeEach(() => {
cy.fixture('login').then((loginData) => {
data = loginData
cy.clearCookies()
cy.clearLocalStorage()
cy.login(data.UserName, data.Password)
})
})
it('Click on Project Inventory & verify Headers', () => {
CustPage.ProjectInventoryIcon().click()
})
afterEach(() => {
cy.clearCookies()
CustPage.MenuContainer().click()
CustPage.Logout().click()
})
I tried the above code but when my test case fails i need to clear cookies from cypress dashboard browser i want to clear through script once it fails
As long as during the startup sequence you are performing the
cy.visit()after you clear cookies, you should have no problem.Make sure you use the All version to cover all domains
The docs say that
clearAllCookies()is asynchronous, so if you follow up with an assertion that cookies are empty, the test guarantee that the cleardown has happened.Also make sure to have
testIsolationon, in fact Cypress should be removing session data automatically for you.afterEach()is not recommended for cleardown precisely for that reason - test fails might block the afterEach hook.