Log in once, and use fixtures
Stop logging in through the form in every test: save the session as storage state in a setup project, reuse it in the config, and share helpers with fixtures.
Transcript
Most tests need a logged in user. If every test logs in through the form, you waste seconds hundreds of times, and a bug in the login page breaks every single test.
Instead, log in once in a setup step, and save the session to a file. Playwright calls it storage state. It stores the cookies and local storage of the logged in browser.
In the config, point the browser project at that file, and make it depend on the setup. Now every test starts already logged in, and goes straight to the page it wants to test.
For anything else you repeat, like creating the login page object, use a fixture. A fixture is a ready made helper that Playwright hands to your test, when the test asks for it by name.
Remember: log in once, save the storage state, reuse it in every test, and share helpers with fixtures.
More in this series
1:217Structure your tests: describe, hooks, tags
Group tests with describe, share setup in beforeEach, keep every test independent in a fresh browser context, and pick what to run with tags like @smoke.
1:178Page Object Model
Stop repeating locators across tests: put each page's locators and actions in a class, so tests read like manual steps and a UI change is fixed in one place.
1:2010API testing and mocking the network
Use the request fixture to prepare data through the API, and page.route to fake server responses so you can test empty lists, errors and slow responses.