dimanche 16 août 2020

Cypress.io doesn't persist Auth0 login for Angular app

I followed the Auth0 tutorial (https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/) for using Cypress.io but I'm not able to get Cypress to persist a successful sign-in.

I am able to sign in with the Cypress Login command, but as soon as I redirect to another page, my auth.guard (which checks for Auth0 login status), prompts for login again and I get this error in Cypress:

myapp.auth0.com refused to connect.

And in the console: Refused to frame 'https://red5.us.auth0.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".

So the auth guard is not finding the login. I suspect this might be because Cypress is clearing cookies and local storage, but I haven't found a workaround.

I tried adding this (from some old code I had) to the top of the test file, but it didn't help.

const clear = Cypress.LocalStorage.clear
Cypress.LocalStorage.clear = function (keys, ls, rs) {
  if (keys) {  }
}

And in the test:

beforeEach(() => {
    cy.restoreLocalStorageCache();
  });

...

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

Aucun commentaire:

Enregistrer un commentaire