Setup
First Playwright Test
Write your first Playwright test with page navigation, a locator, an action, and a meaningful assertion.
Test Goal
The first test should prove the setup works and teach the basic Playwright flow: open page, locate element, act, and assert.
Test File
import { test, expect } from '@playwright/test';
test('home page title is visible', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example/);
});Line-by-Line
- Import test and expect.
- Create a named test.
- Use the page fixture.
- Navigate to a URL.
- Assert the expected result.
Run and Verify
npx playwright testImprove It
- Add a user action.
- Use a role or text locator.
- Assert visible content after the action.