TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 34 of 60~18 min • Beginner
Chapter 34Playwright

First Playwright test

A test has a readable name and an asynchronous body. The page fixture is an isolated page provided by Playwright Test. Arrange the state, perform an action and assert an observable outcome. setContent makes a small reproducible example without an external website.

How it works

Step-by-step walkthrough

  1. Create tests/first.spec.ts
  2. Paste the example
  3. Run npx playwright test tests/first.spec.ts

Example

TypeScript
import { test, expect } from '@playwright/test';
test('button is visible', async ({ page }) => {
  await page.setContent('<button>Start</button>');
  await expect(page.getByRole('button', { name: 'Start' })).toBeVisible();
});
Expected result: A passing test
💡 Point to remember
Use descriptive names that explain the expected behavior.

✎ Your practice task

Change Start to Stop only in the assertion.

Knowledge check

Which fixture gives you a browser page?

🌐 Continue learning