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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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
- How do you write a stable Playwright test?
- What is auto-waiting and what are web-first assertions?
- How do you handle login in E2E tests without logging in through the UI every time?
- A test passes locally and fails in CI 1 time in 20. How do you debug it?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.