Preserve cookies / localStorage session across tests in Cypress

前端 未结 6 807
抹茶落季
抹茶落季 2020-12-30 21:58

I want to save/persist/preserve a cookie or localStorage token that is set by a cy.request(), so that I don\'t have to use a custom command to login on ever

6条回答
  •  没有蜡笔的小新
    2020-12-30 22:27

    I can see suggestions to use whitelist. But it does not seem to work during cypress run. Tried below methods in before() and beforeEach() respectively:

    Cypress.Cookies.defaults({
      whitelist: "token"
    })
    

    and

    Cypress.Cookies.preserveOnce('token');
    

    But none seemed to work. But either method working fine while cypress open i.e. GUI mode. Any ideas where I am coming short?

提交回复
热议问题