Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright e2e testing. What to do with oauth2 or email-passwordless authentication

I am starting to do e2e tests with playwright. Most of the application requires to be authenticated. Automating this with a username/password mechanism is quite easy. The problem is that the app I want to test has only two authentication mechanisms: Github OAuth and email authentication links. Specifically I am using next-auth in a NextJS project.

I don't know how should I e2e test this with Playwright, the options I have considered are:

  • Completly mocking the authentication using a mock user and a mock session and then append the session token in the test context (as it is described here in the official docs).
  • Creating a Github user and/or an email account for the tests and somehow truly use them in playwrigth.

The first option is much easier to implement but then it's not e2e testing anymore. The second option looks difficult to implement and I don't know if it is recommended. I don't know if there are smarter or more standarized ways to proceed with this.

like image 409
Daniel Mateos Labrador Avatar asked Nov 06 '22 00:11

Daniel Mateos Labrador


1 Answers

The keynote here is that you don't need to write e2e test to test the authentication flow because you're using next-auth ( which I think is a well-tested library). So I think you should go for the first option .

like image 164
mostafa Avatar answered Nov 12 '22 16:11

mostafa