Playwright interview questions covering locators, auto-waiting, fixtures, projects, parallelism, API testing, network mocking and debugging with the trace viewer.
50 questions17 Beginner20 Intermediate13 Advanced
Interview Questions
Showing 15 of 50 questions
Answer
Playwright is an open-source end-to-end testing framework from Microsoft that drives Chromium, Firefox and WebKit through a single API. Teams pick it for built-in auto-waiting, a first-class test runner, parallelism, tracing and network control without extra libraries.
Key points
Talks to browsers over CDP/WebSocket-style protocols rather than the WebDriver HTTP protocol
@playwright/test ships fixtures, assertions, reporters, retries and sharding
Supports TypeScript, JavaScript, Python, Java and .NET
Browser contexts give fast, isolated sessions per test
Interview tip: Don't claim Selenium is obsolete. Mention that Selenium still has wider language/grid ecosystem support and real-device clouds.
Playwright is an open-source end-to-end testing framework from Microsoft that drives Chromium, Firefox and WebKit through a single API. Teams pick it for built-in auto-waiting, a first-class test runner, parallelism, tracing and network control without extra libraries.
Answer
A Browser is a launched browser instance, a BrowserContext is an isolated incognito-like session with its own cookies and storage, and a Page is a single tab inside a context. @playwright/test creates a fresh context and page per test by default.
Key points
Contexts are cheap to create, so isolation costs little
Multiple contexts let you simulate two users in one test
Interview tip: Interviewers often follow up with: how would you test a multi-user feature? Answer with multiple contexts.
A Browser is a launched browser instance, a BrowserContext is an isolated incognito-like session with its own cookies and storage, and a Page is a single tab inside a context. @playwright/test creates a fresh context and page per test by default.
Answer
Playwright recommends user-facing locators such as getByRole, getByLabel, getByText and getByPlaceholder, with getByTestId as a stable fallback. CSS and XPath work but are tied to DOM structure and break more easily.
Key points
getByRole uses the accessibility tree and doubles as an a11y check
Locators are lazy and re-resolved on every action
Chain and filter: locator.filter({ hasText }) or .and()/.or()
testIdAttribute can be configured in playwright.config
Interview tip: Common mistake: using page.$() or elementHandle APIs. Those are discouraged; use Locator instead.
Playwright recommends user-facing locators such as getByRole, getByLabel, getByText and getByPlaceholder, with getByTestId as a stable fallback. CSS and XPath work but are tied to DOM structure and break more easily.
Answer
Before each action Playwright runs actionability checks, waiting until the element is attached, visible, stable, enabled and receives events. Web-first assertions like toBeVisible also retry until they pass or time out.
Key points
No need for manual sleeps in most cases
Action timeout and expect timeout are configurable separately
Strict mode: a locator matching multiple elements throws on action
Interview tip: Never use page.waitForTimeout() as a sync strategy; it is meant for debugging only.
Before each action Playwright runs actionability checks, waiting until the element is attached, visible, stable, enabled and receives events. Web-first assertions like toBeVisible also retry until they pass or time out.
Answer
Web-first assertions are async matchers on locators or pages, like expect(locator).toHaveText(), that retry until the condition holds. They remove flakiness caused by asserting on a value read once.
Key points
Prefer expect(locator).toBeVisible() over expect(await locator.isVisible()).toBe(true)
expect.soft() continues the test after a failure
expect.poll() and toPass() retry arbitrary async code
typescript
// Flaky: reads once
expect(await page.getByTestId("status").textContent()).toBe("Paid");
// Stable: retries until timeout
await expect(page.getByTestId("status")).toHaveText("Paid");
Interview tip: Interviewers like the 'flaky vs stable' comparison above; it shows you understand retrying.
Web-first assertions are async matchers on locators or pages, like expect(locator).toHaveText(), that retry until the condition holds. They remove flakiness caused by asserting on a value read once.
Answer
I configure testDir, baseURL, timeouts, retries, workers, reporters, trace/screenshot/video settings and projects for each browser or device. Environment-specific values come from env variables.
Key points
projects enable cross-browser and setup-dependency runs
webServer can start the app before tests
use: { trace: 'on-first-retry' } is a good CI default
I configure testDir, baseURL, timeouts, retries, workers, reporters, trace/screenshot/video settings and projects for each browser or device. Environment-specific values come from env variables.
Answer
For iframes I use page.frameLocator() or locator.contentFrame() and then locate inside it. For new tabs I wait for the context's 'page' event while triggering the click.
Key points
No switchTo() like Selenium; frames are scoped locators
Start waiting for the popup before the click to avoid races
page.waitForEvent('popup') works for window.open popups
For iframes I use page.frameLocator() or locator.contentFrame() and then locate inside it. For new tabs I wait for the context's 'page' event while triggering the click.
Answer
Fixtures provide setup and teardown for what a test needs, like page or request, and are injected by name. I extend the base test with test.extend to add page objects, authenticated pages or test data.
Key points
Fixtures are lazy: only created if a test uses them
Scope can be 'test' or 'worker'
Code after use() is teardown
Replaces most beforeEach/afterEach boilerplate
typescript
import { test as base } from "@playwright/test";
import { LoginPage } from "./pages/login-page";
type Fixtures = { loginPage: LoginPage };
export const test = base.extend<Fixtures>({
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await use(loginPage);
},
});
export { expect } from "@playwright/test";
Interview tip: Follow-up: worker-scoped fixtures for expensive resources like a seeded DB account per worker.
Fixtures provide setup and teardown for what a test needs, like page or request, and are injected by name. I extend the base test with test.extend to add page objects, authenticated pages or test data.
Answer
Each page class takes a Page in the constructor, exposes locators as readonly properties and user-level methods like login(). Assertions mostly stay in tests, and page objects are injected through fixtures.
Key points
Store Locators, not element handles; they resolve lazily
Keep methods business-focused, not one per click
Component objects for reusable widgets like headers or modals
Each page class takes a Page in the constructor, exposes locators as readonly properties and user-level methods like login(). Assertions mostly stay in tests, and page objects are injected through fixtures.
Answer
I log in once in a setup project, save the session with storageState, and have other projects reuse that file. Tests start already authenticated, which is faster and less flaky.
I log in once in a setup project, save the session with storageState, and have other projects reuse that file. Tests start already authenticated, which is faster and less flaky.
Answer
I use page.route() with a URL pattern and then route.fulfill(), route.abort() or route.continue(). route.fetch() lets me modify a real response before returning it.
Key points
Useful for error states, empty states and slow responses
Interview tip: Mention balance: mocking everything hides integration bugs, so keep a smaller set of full end-to-end tests.
I use page.route() with a URL pattern and then route.fulfill(), route.abort() or route.continue(). route.fetch() lets me modify a real response before returning it.
Answer
Yes, the request fixture (APIRequestContext) sends HTTP requests and works with the same expect assertions. I use it for pure API tests and to seed or clean data before UI tests.
Key points
Shares cookies with the browser context when using page.request
Yes, the request fixture (APIRequestContext) sends HTTP requests and works with the same expect assertions. I use it for pure API tests and to seed or clean data before UI tests.
Answer
Playwright runs test files in parallel across worker processes, and fullyParallel also parallelizes tests within a file. Sharding splits the suite across machines with --shard=1/4, and merge-reports combines the blob reports.
Key points
Each worker has its own browser; tests must be independent
test.describe.configure({ mode: 'serial' }) for dependent flows (use sparingly)
Use testInfo.workerIndex or unique data to avoid collisions
Interview tip: Common mistake: sharing one test account across parallel workers causes random failures.
Playwright runs test files in parallel across worker processes, and fullyParallel also parallelizes tests within a file. Sharding splits the suite across machines with --shard=1/4, and merge-reports combines the blob reports.
Answer
Locally I use UI mode (--ui) or --debug with the Inspector, and page.pause(). For CI failures I open the trace with npx playwright show-trace, which shows DOM snapshots, network, console and each action.
Key points
trace: 'on-first-retry' or 'retain-on-failure' in CI
Codegen helps pick robust locators
VS Code extension supports breakpoints and live locators
Interview tip: Saying 'I look at the trace first' is what interviewers want to hear for CI debugging.
Locally I use UI mode (--ui) or --debug with the Inspector, and page.pause(). For CI failures I open the trace with npx playwright show-trace, which shows DOM snapshots, network, console and each action.
Answer
I download the trace, screenshot and video from the CI artifacts and compare against a local run. Typical causes are timing under slower CPUs, different viewport or headless behavior, environment data, or tests sharing state under higher parallelism.
Key points
Reproduce with the same workers count and headless mode locally
Run in the official Playwright Docker image to match CI
Check baseURL, secrets and time zone/locale differences
Replace any hard waits or one-time reads with web-first assertions
Interview tip: Avoid answering 'just increase the timeout'; find the root cause.
I download the trace, screenshot and video from the CI artifacts and compare against a local run. Typical causes are timing under slower CPUs, different viewport or headless behavior, environment data, or tests sharing state under higher parallelism.