</>

Technology

Playwright

Difficulty

Beginner

Interview Question

What is Playwright and what are its key features?

Answer

What is Playwright?

Playwright is an open-source browser automation framework developed by Microsoft, released in 2020. It was built by engineers who previously developed Puppeteer at Google. Playwright enables reliable end-to-end testing for modern web applications.

Key Features

1. Cross-Browser Support

Playwright tests run on all major browsers with a single unified API:

  • Chromium (Google Chrome, Microsoft Edge)
  • Firefox
  • WebKit (Safari engine)

2. Multi-Language Support

  • JavaScript / TypeScript
  • Python
  • Java
  • C# (.NET)

3. Auto-Waiting

Playwright automatically waits for elements to be actionable before interacting — no sleep() or manual wait chains needed.

TypeScript
// No explicit wait required — Playwright handles it
await page.click('#submit-button');
await expect(page.locator('.success-msg')).toBeVisible();

4. Built-in Network Interception

Mock API responses, intercept HTTP calls, and simulate network conditions — all built-in.

5. Browser Contexts

Isolated browser sessions per test so cookies, storage, and auth never leak between tests.

6. Smart Locators

Role-based, text-based, and test-ID-based locators that are stable and don't rely on fragile CSS paths.

7. Powerful Debugging Tools

  • Playwright Inspector — step-through debugger
  • Trace Viewer — full timeline replay of test execution
  • UI Mode — interactive test runner
  • Codegen — auto-record tests by clicking in the browser

8. Parallel Execution & Sharding

Run tests in parallel workers; shard across machines in CI.

9. Soft Assertions

Collect multiple assertion failures in one test run — don't stop at first failure.

10. Built-in Screenshot & Video

Capture screenshots, full-page captures, and record videos on test failure automatically.

Quick Example

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

test('user can log in', async ({ page }) => {
  await page.goto('https://myapp.com/login');
  await page.fill('#email', 'user@example.com');
  await page.fill('#password', 'secret');
  await page.click('button[type="submit"]');
  await expect(page).toHaveURL('/dashboard');
});

Follow AutomateQA

Related Topics