Testing · Senior · Question 44 of 75
How do you implement authentication once for the whole suite in Playwright?
projects: [
{ name: "setup", testMatch: /auth\.setup\.ts/ },
{ name: "chromium", use: { storageState: "playwright/.auth/user.json" }, dependencies: ["setup"] },
]- ✓Correct answer: A setup project logs in and saves
storageState; other projects depend on it and reuse the state - 2
globalSetupin every test file - 3Log in with
beforeEachin each test
Explanation
Project dependencies appear in the report and trace, unlike globalSetup. Keep the auth file out of git.