Page 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.
Transcript
Imagine ten tests that all log in. Each one repeats the same locators. Then the Log in button is renamed to Sign in, and you have to fix ten files.
A page object puts everything about one page in one class. The locators, and the actions you can do on that page, like log in.
Now your test reads like a manual test case. Create the login page, call log in, then check the result. No locators in the test, just steps.
When the page changes, you edit one place, and every test is fixed. Keep the locators and actions in the page object, and keep the assertions in the tests.
Remember: one page, one class. Locators and actions live in the page object, and tests read like steps.
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: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.