E2e Testing React SPA with Cypress

I have added user login to a React application using the following guide: Auth0 React SDK Quickstarts: Login

This all works fine, but when I want to test the application in Cypress I am having some problems. I was initially following this guide: End-to-End Testing with Cypress and Auth0 and this seems to implement the best practices from Cypress by using the password grant to log the user in before running the tests.

However, this guide isn’t using the auth0-spa-js library and implements its own container for storing the access token (auth0-cypress-demo/Auth.js at base · danlourenco/auth0-cypress-demo · GitHub).

auth0-spa-js has its own logic for caching the access token.

Is it possible to use the auth0-spa-js library and use the password grant type for Cypress tests?

Thanks

8 Likes

Having exactly same problem :frowning:. I able to retrieve the access token, but that is useless to me, since there is no way of providing this token to auth0-spa-js

1 Like

I haven’t found an official solution and I would love one if possible. So far I’ve resorted to logging in manually and maintaining the local storage between the tests.

https://github.com/cypress-io/cypress/issues/461#issuecomment-392070888

1 Like

Thanks for sharing it with the rest of community @vermvfx!

I’m also finding this to be an issue. I’m not sure what token/code or state to redirect too in order to continue the login process.

@konrad.sopala can you weigh in with an actual solution please?

1 Like

I did manage to resolve the problem in the end - How to test single page application with Cypress and Auth0 - Stack Overflow

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.