Login flows deserve dedicated coverage: happy path, validation, error messages, and security redirects. These tests typically run without pre-seeded storageState.
Login Test Scenarios
Cover valid login redirect, invalid credentials error, empty field validation, and access to protected routes when unauthenticated.
Use role locators on the login form; mock auth API with route if backend unavailable in test env.
Assert error messages with await expect(page.getByRole('alert')).toContainText('Invalid') — keep happy-path login in one test, negative cases in separate tests.
Common Mistakes
Login tests using storageState — never hits login UI.
Not clearing cookies between login tests in same file.
Testing against real user passwords in repo.
Skipping negative cases — only happy path.
Key Takeaways
Login specs start logged out explicitly.
Cover success, failure, and validation paths.
Mock auth API when backend isolated.
Keep credentials in env vars.
Pro Tip
Parameterize email/password via env so the same tests run against staging test accounts without code changes.
Continue with Storage State to build on what you learned here.