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 31 of 60~18 min • Beginner
Chapter 31Playwright

Playwright introduction and architecture

Playwright automates web browsers for end-to-end testing. Playwright Test adds a runner, assertions, fixtures and reporting. An end-to-end test exercises a user journey and checks the observable result, such as a successful sign-in. Playwright sends commands to browser engines through its automation implementation. A browser process can contain isolated browser contexts, and each context can have pages. Chromium, Firefox and WebKit projects help check compatibility; WebKit is not identical to every Safari environment.

How it works

Step-by-step walkthrough

  1. Identify a user journey
  2. Describe actions
  3. Define the expected outcome

Example

This is a focused snippet. Use it in the file or test context described in the walkthrough.

TypeScript
// tests/first.spec.ts
import { test, expect } from '@playwright/test';
test('smoke check', async ({ page }) => {
  await page.setContent('<h1>Welcome</h1>');
  await expect(page.getByRole('heading')).toHaveText('Welcome');
});
Expected result: One passing smoke test

Browser, context and page example

Run as a TypeScript script using a compatible TypeScript execution setup, or adapt it into a test.

TypeScript
import { chromium } from '@playwright/test';
async function run() {
  const browser = await chromium.launch();
  try {
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.setContent('<h1>Lab</h1>');
    console.log(await page.locator('h1').textContent());
  } finally { await browser.close(); }
}
run().catch(console.error);
💡 Point to remember
Test the user-visible behavior, not internal implementation details. Prefer runner-provided fixtures for ordinary tests.

✎ Your practice task

Change the expected heading to see a failure.

Knowledge check

What makes an automated check a test?

🌐 Continue learning