Skip to the page

End-to-end and component testing · mid

Playwright essentials: locators, auto-waiting, fixtures, traces

Playwright drives Chromium, Firefox and WebKit from Node; you find elements with user-facing locators (getByRole), rely on auto-waiting actions and web-first assertions instead of sleeps, isolate each test in a fresh browser context through fixtures, and debug CI failures with the trace viewer.

The notes

What you must know

  • Locators: page.getByRole('button', { name: 'Add to cart' }), getByLabel, getByText, getByTestId; chain and filter (locator.filter({ hasText })). Avoid long CSS/XPath selectors.
  • Actions auto-wait for the element to be attached, visible, stable, enabled and receiving events. No page.waitForTimeout in real tests.
  • Web-first assertions retry until true or timeout: await expect(locator).toBeVisible(), toHaveText, toHaveURL. Always await them; locator.isVisible() does not wait.
  • Isolation: each test gets a new browser context (fresh cookies/storage). Log in once in a setup project and reuse storageState for speed.
  • Fixtures: built-in page, context, request; custom ones via test.extend (for example a logged-in page or seeded data) with automatic teardown.
  • Debugging: trace viewer (trace: 'on-first-retry' in CI), UI mode, --debug, codegen. Projects run the same tests on several browsers; tests run in parallel and can be sharded across machines.
  • Current: Playwright 1.65 (Nov 2026). Since 1.56 it ships AI test agents (planner, generator, healer); the MCP server and CLI are bundled since 1.62.

The red pen

Common traps: mistake → fix

  • Mistake: "Add waitForTimeout(2000) to fix flakiness"

    Fix: it slows the suite and still flakes; wait for a condition with web-first assertions.

  • Mistake: "expect(await locator.isVisible()).toBe(true)"

    Fix: it checks once without waiting; use await expect(locator).toBeVisible().

  • Mistake: "Share one logged-in page across tests"

    Fix: tests become order-dependent; reuse storageState but keep contexts separate.

Easy to hard

Questions interviewers ask, easy to hard

  1. How do you write a stable Playwright test?
  2. What is auto-waiting and what are web-first assertions?
  3. How do you handle login in E2E tests without logging in through the UI every time?
  4. A test passes locally and fails in CI 1 time in 20. How do you debug it?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview