| |

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)

  1. 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.
  2. 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.
  3. 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.
  4. What locator strategies does Playwright support? — getByRole, getByLabel, getByText, getByPlaceholder, getByAltText, getByTitle, getByTestId, CSS, XPath. Semantic locators (getByRole) are preferred.
  5. 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.
  6. 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.
  7. How do you take screenshots in Playwright?await page.screenshot({ path: 'screenshot.png' }) or configure screenshot: 'only-on-failure' in config for automatic capture.
  8. 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.
  9. How do you run tests in parallel? — Set fullyParallel: true in config. Playwright creates separate BrowserContexts per test. Use workers to control concurrency.
  10. 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)

  1. How does network interception work?page.route('**/api/**', handler) intercepts matching requests. You can fulfill with mock data, abort, or modify headers in flight.
  2. 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().
  3. 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.
  4. 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.
  5. How do you test APIs with Playwright? — Use request fixture: const response = await request.get('/api/users'). Validates status, body, headers without a browser.
  6. How do you handle iframes?page.frameLocator('#iframe-id').getByRole('button'). Playwright pierces iframes natively without switching context.
  7. What is visual regression testing?await expect(page).toHaveScreenshot() compares current screenshot to a baseline. Flags pixel-level differences.
  8. How do you handle file uploads?await page.getByLabel('Upload').setInputFiles('file.pdf'). Supports single, multiple, and drag-and-drop uploads.
  9. What is test tagging? — Add @smoke, @regression to test names. Run with --grep @smoke. Alternative: use test.describe.configure({ tag: '@smoke' }).
  10. 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)

  1. How do you create custom reporters? — Implement the Reporter interface with onBegin, onTestEnd, onEnd methods. Register in config under reporters array.
  2. 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.
  3. How does sharding work in CI?--shard=1/4 splits tests across N runners. Each shard runs a subset. Merge reports post-job with merge-reports.
  4. What is the MCP integration? — Model Context Protocol lets AI agents interact with Playwright programmatically. Enables AI-driven test generation and execution.
  5. How do you test WebSocket connections?page.routeWebSocket('**/ws', handler) intercepts WebSocket messages. Can mock server responses and test real-time features.
  6. What is Browser.bind() in 1.59? — Connects multiple clients to a single browser instance. Enables collaborative debugging and multi-agent testing architectures.
  7. How do you implement retry logic for specific tests?test.describe.configure({ retries: 3 }) at describe level. Or global retries in config with retries: process.env.CI ? 2 : 0.
  8. 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.
  9. What is the await using syntax? — Auto-cleanup: await using page = await browser.newPage(). Page closes automatically when scope exits. Requires TS 5.2+.
  10. 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)

  1. “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.
  2. “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).
  3. “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.
  4. “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.
  5. “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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.