Structure 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.
Transcript
A test file groups related tests. Use test dot describe to name a group, like Login. Inside it, each test checks one behavior and has a clear name, so the report reads like a list of test cases.
Put the steps that every test repeats into before each. It runs before every single test, for example to open the login page.
Keep every test independent. A test must never depend on another test running first, or on data it left behind. Each test gets a fresh browser context, like a brand new private window.
Use tags like at smoke to choose what to run. Run only the smoke tests on every commit, and the full suite every night.
Remember: describe groups tests, before each shares setup, every test stands alone, and tags choose what to run.
More in this series
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:229Log 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.
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.