Playwright Interview Questions: 50+ Questions From Beginner to Advanced With Answers
Everyone talks about Playwright. Few learn it properly. That gap is what companies hire for. Here are 50+ interview questions organized by difficulty — with model answers for each.
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Contents
Basic Questions (10)
- What is Playwright and how does it differ from Selenium? — Playwright communicates directly with browsers via CDP/BiDi protocol (WebSocket), while Selenium uses HTTP-based WebDriver protocol through a driver middleman. This makes Playwright faster and eliminates driver version management.
- What is Playwright’s auto-wait mechanism? — Before every action (click, fill, etc.), Playwright automatically waits for the element to be attached, visible, stable, enabled, and not obscured. No explicit waits needed.
- What is a BrowserContext? — An isolated browser session with its own cookies, localStorage, and cache. Each test gets its own context by default, enabling parallel execution without interference.
- What locator strategies does Playwright support? — getByRole, getByLabel, getByText, getByPlaceholder, getByAltText, getByTitle, getByTestId, CSS, XPath. Semantic locators (getByRole) are preferred.
- How does Playwright handle multiple browsers? — Single API for Chromium, Firefox, and WebKit. Configure in playwright.config.ts using projects array. All browsers bundled with the package.
- What is the difference between page.locator() and page.getByRole()? — locator() accepts CSS/XPath selectors. getByRole() uses ARIA roles and is more resilient to DOM changes. Always prefer getByRole.
- How do you take screenshots in Playwright? —
await page.screenshot({ path: 'screenshot.png' })or configurescreenshot: 'only-on-failure'in config for automatic capture. - What is playwright.config.ts? — The central configuration file that defines test directory, parallel workers, retries, reporters, browser projects, base URL, and global test settings.
- How do you run tests in parallel? — Set
fullyParallel: truein config. Playwright creates separate BrowserContexts per test. Useworkersto control concurrency. - What is Codegen? — A tool that records browser interactions and generates test code. Run
npx playwright codegen. Useful for scaffolding but output should be refactored.
Intermediate Questions (10)
- How does network interception work? —
page.route('**/api/**', handler)intercepts matching requests. You can fulfill with mock data, abort, or modify headers in flight. - What are Playwright fixtures? — Dependency injection for tests. Custom fixtures provide reusable setup (authenticated page, API client, test data) without inheritance. Defined with
test.extend(). - How do you handle authentication across tests? — Use
storageState: authenticate once in a setup project, save cookies/localStorage to JSON, load in all subsequent tests. - What is the Trace Viewer? — A debugging tool that records every action, DOM snapshot, network request, and console log. Open with
npx playwright show-trace trace.zip. - How do you test APIs with Playwright? — Use
requestfixture:const response = await request.get('/api/users'). Validates status, body, headers without a browser. - How do you handle iframes? —
page.frameLocator('#iframe-id').getByRole('button'). Playwright pierces iframes natively without switching context. - What is visual regression testing? —
await expect(page).toHaveScreenshot()compares current screenshot to a baseline. Flags pixel-level differences. - How do you handle file uploads? —
await page.getByLabel('Upload').setInputFiles('file.pdf'). Supports single, multiple, and drag-and-drop uploads. - What is test tagging? — Add
@smoke,@regressionto test names. Run with--grep @smoke. Alternative: usetest.describe.configure({ tag: '@smoke' }). - How do you handle popups and new tabs? —
const popup = await page.waitForEvent('popup'). Playwright tracks all pages in a context automatically.
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
Advanced Questions (10)
- How do you create custom reporters? — Implement the
Reporterinterface with onBegin, onTestEnd, onEnd methods. Register in config under reporters array. - What is Playwright Component Testing? — Test individual React/Vue/Svelte components in isolation using
@playwright/experimental-ct-react. Renders real components in a real browser. - How does sharding work in CI? —
--shard=1/4splits tests across N runners. Each shard runs a subset. Merge reports post-job withmerge-reports. - What is the MCP integration? — Model Context Protocol lets AI agents interact with Playwright programmatically. Enables AI-driven test generation and execution.
- How do you test WebSocket connections? —
page.routeWebSocket('**/ws', handler)intercepts WebSocket messages. Can mock server responses and test real-time features. - What is Browser.bind() in 1.59? — Connects multiple clients to a single browser instance. Enables collaborative debugging and multi-agent testing architectures.
- How do you implement retry logic for specific tests? —
test.describe.configure({ retries: 3 })at describe level. Or global retries in config withretries: process.env.CI ? 2 : 0. - How do you handle test data isolation in parallel execution? — Each test creates its own data via API fixtures. Use unique identifiers (timestamp + random suffix). Clean up in afterEach.
- What is the await using syntax? — Auto-cleanup:
await using page = await browser.newPage(). Page closes automatically when scope exits. Requires TS 5.2+. - How do you debug flaky tests systematically? — Enable
trace: 'retain-on-failure'. Check DOM snapshots before/after the failing action. Inspect network tab for missing API responses. Look for timing-dependent assertions.
Scenario-Based Questions (5)
- “Your CI has 30% flaky test rate. How do you fix it?” — Track flakiness per test. Quarantine tests above 5% failure rate. Fix root causes: replace hardcoded waits with assertions, isolate test data, mock external APIs.
- “Design an automation strategy for a new e-commerce platform.” — Test pyramid: unit tests for business logic, API contract tests for microservices, E2E for critical paths (checkout, payment). CI: PR gate (unit+API), nightly (full E2E).
- “You need to test a feature before the backend API is ready.” — Use page.route() to mock the API response. Define the expected contract. Write tests against the mock. Swap to real API when backend is deployed.
- “How would you handle testing across 3 environments?” — .env files per environment. Config reads BASE_URL from environment variable. CI matrix runs tests against each environment. Same tests, different configs.
- “Your test suite takes 45 minutes. How do you reduce it?” — Enable parallelization. Shard across CI runners. Move slow E2E tests to nightly. Replace UI data setup with API calls. Identify and remove redundant tests.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
