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
- Write a test with the Playwright Test runner.
- Use the page fixture to open a browser tab.
- Find elements with locators such as getByRole or getByLabel.
- Perform user actions and assert the expected result.
- 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
- What is Playwright used for?
- How is Playwright different from Selenium?
- Why are locators and auto-waiting important?
- 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.