Writing your first tests
test() blocks, locators, web-first expect assertions, and the page fixture.
Anatomy of a test
A test is a function passed to test('name', async ({ page }) => { ... }). Playwright injects fixtures (page, context, request, …) into the destructured argument. Each test gets a fresh isolated browser context, so there is no shared cookie or storage pollution between tests by default.
Locators
Locators are how Playwright finds elements. Prefer user-facing locators: getByRole, getByLabel, getByText, getByPlaceholder, getByAltText, getByTitle. They are auto-waiting and re-resolving: every action retries until the locator points to exactly one actionable element or the timeout is reached.
Use CSS or XPath only when there is no semantic alternative. Locators chain: page.getByRole('list').getByRole('listitem').nth(0).
Web-first assertions
expect() from @playwright/test auto-retries until the assertion passes or the assertion timeout expires. This removes most manual waitFor calls and the dreaded sleep(...). Prefer assertions like toBeVisible, toHaveText, toHaveURL over checking DOM state immediately.