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

  1. Import test and expect.
  2. Create a named test.
  3. Use the page fixture.
  4. Navigate to a URL.
  5. Assert the expected result.

Run and Verify

npx playwright test

Improve It

  • Add a user action.
  • Use a role or text locator.
  • Assert visible content after the action.