Basic Test Structure in Playwright

From the Playwright cheat sheet ยท Writing Tests ยท verified Jul 2026

Basic Test Structure

Write tests with test blocks, navigation, and assertions

typescript
import { test, expect } from '@playwright/test';

test('has correct title', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveTitle(/My App/);
});

test('navigates to about page', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('link', { name: 'About' }).click();
  await expect(page).toHaveURL('/about');
});
๐Ÿ’ก Each test gets a fresh browser context โ€” no state leaks between tests
โšก Playwright auto-waits for elements before interacting โ€” no manual waits needed
๐Ÿ“Œ Use test.skip() with a condition to skip tests based on platform or environment
๐ŸŸข The page fixture is the most common โ€” it provides a fresh page for each test
teststructure

More Playwright tasks

Back to the full Playwright cheat sheet