Foundation

What is Playwright

Playwright is a modern end-to-end testing framework for automating real browsers, validating UI behavior, supporting API setup, and running reliable tests in CI.

Definition and Brief Explanation

Definition: Playwright is an open-source automation framework used to test web applications in real browsers such as Chromium, Firefox, and WebKit.

Explanation: It lets QA engineers and developers write tests that behave like users: open a page, locate elements, click, type, wait for results, verify UI state, inspect network behavior, and collect debugging evidence such as traces, screenshots, videos, and reports.

Why It Matters

  • It supports modern end-to-end testing with auto-waiting and reliable locators.
  • It can test Chromium, Firefox, and WebKit from one framework.
  • It includes a test runner, reports, trace viewer, screenshots, videos, fixtures, and projects.
  • It fits QA, developer, and DevOps workflows because tests can run locally and in CI.

How It Works

  1. Write a test with the Playwright Test runner.
  2. Use the page fixture to open a browser tab.
  3. Find elements with locators such as getByRole or getByLabel.
  4. Perform user actions and assert the expected result.
  5. Review reports or traces when a test fails.

Syntax and Examples

Basic Playwright test

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

test('home page loads', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example/);
});

Explanation: The test opens a page and uses a retrying assertion to verify the page title.

Common Mistakes

  • Thinking Playwright is only a recorder instead of a full test framework.
  • Using fixed waits instead of locators and assertions.
  • Writing one huge test that checks many unrelated features.
  • Ignoring trace viewer and reports when debugging failures.

Interview Notes

  1. What is Playwright used for?
  2. How is Playwright different from Selenium?
  3. Why are locators and auto-waiting important?
  4. What debugging evidence can Playwright collect?

Practice Task

Install Playwright, create one test that opens a page, clicks a visible control, and asserts the result. Then run it in headed and headless mode.