Playwright Interview Questions
Playwright interview questions — locators, auto-waiting, fixtures, traces and Playwright vs Cypress — with answers.
Playwright interview questions
Playwright interviews focus on locators, auto-waiting, isolation, fixtures and debugging failures in CI.
1. What is Playwright and which browsers does it support?
An open-source testing and automation framework from Microsoft. One API drives Chromium (Chrome, Edge), Firefox and WebKit (Safari), with bindings for TypeScript/JavaScript, Python, Java and .NET.
2. What is auto-waiting?
Before an action, Playwright waits for the element to be attached, visible, stable, able to receive events and enabled. Tests don't need manual waits or sleeps.
3. What are web-first assertions?
Assertions on locators — await expect(locator).toBeVisible(), toHaveText(), toHaveCount() — that retry until they pass or time out. Non-retrying checks on a value read once are a common cause of flakiness.
4. Which locators does Playwright recommend?
User-facing locators: getByRole first, then getByLabel, getByPlaceholder, getByText and getByTestId. CSS/XPath only when necessary.
5. What does "strict mode" mean for locators?
An action on a locator matching more than one element throws an error instead of picking one, forcing you to write unambiguous locators.
6. What is a browser context?
An isolated, incognito-like browser session with its own cookies and storage. Playwright creates a new context for every test, which is fast and keeps tests independent.
7. What are fixtures?
Values a test requests by name — page, context, request — created before and torn down after the test. Custom fixtures (test.extend) provide ready-made page objects, logged-in pages or seeded data.
8. How do you avoid logging in before every test?
Log in once in a setup project, save storageState (cookies and local storage) to a file, and configure projects to load it.
9. How do you test APIs with Playwright?
With the request fixture (or request.newContext()): request.get/post/put/delete, then assert on status(), headers() and json().
10. How do you mock network requests?
page.route(url, handler) — route.fulfill() to return a fake response, route.fetch() + fulfill to modify the real one, route.abort() to block it. Register routes before navigation.
11. What is the Trace Viewer?
A recording of a test run — actions, DOM snapshots, network, console and source. Configure trace: 'on-first-retry' and open trace.zip with npx playwright show-trace or trace.playwright.dev to debug CI failures.
12. How does Playwright run tests in parallel?
Test files are distributed across worker processes (workers setting); fullyParallel: true also parallelises tests within a file. --shard=1/4 splits a suite across machines.
13. What are projects in the config?
Named configurations — usually browsers or devices — that run the same tests with different settings, such as Desktop Chrome, Firefox, WebKit and iPhone.
14. How do you handle a new tab or popup?
Wait for the event while triggering it: const popupPromise = page.waitForEvent('popup'); await page.getByText('Open').click(); const popup = await popupPromise; then work with popup like any page.
15. How do you handle file uploads and downloads?
Uploads: await page.getByLabel('Upload').setInputFiles('report.pdf'). Downloads: const download = page.waitForEvent('download'); await click; (await download).saveAs(path).
16. What is codegen?
npx playwright codegen <url> records your actions and generates test code with recommended locators — good for learning and scaffolding, then refined by hand.
17. How do you mark tests as flaky or skip them?
Playwright reports tests that fail then pass on retry as "flaky". Use test.skip(), test.fixme() and test.fail() with a linked ticket while fixing root causes.
18. Playwright vs Cypress vs Selenium?
Playwright: all engines including WebKit, multi-tab/origin, multiple languages, parallel and tracing built in. Cypress: in-browser JavaScript runner with excellent interactive debugging. Selenium: the W3C standard with the broadest language and browser support but more setup.