Search code examples
typescripttestingplaywrightplaywright-typescript

Setup for Playwright test suit for authentication


I have Playwright suite to test an Angular 15 app and I'm trying to set up an auth scheme so tests could use it to simulate an authenticated user.

According to the basic setup docs, I've added a globalSetup file that runs before all tests.

But, according to these authentication docs, I need to create a setup project to run the auth scheme:

Create a new setup project in the config and declare it as a dependency for all your testing projects. This project will always run and authenticate before all the tests. All testing projects should use the authenticated state as storageState.

What is the right way to do it? Are there supposed to be two "setup" places?


Solution

  • Project dependencies are still fairly new and were released in 1.31. It might be that the docs aren't entirely caught up with their recommendations.

    Compared with globalSetup, project dependencies are a more flexible and future-proof approach to running code with setup dependencies. Assume that you only want to log in some tests; with a single globalSetup definition, that's a little tricky, but project dependencies enable you to define dependencies for all tests.