skip to content

Playwright

4 roadmaps287 questionsupdated

Driving Chromium, Firefox and WebKit from one API: auto-waiting locators, isolated contexts, a fixture-based runner and traces. Asked because it is the default choice for new browser suites.

on this pageshow

guide

overview

~1 min

Playwright is a browser automation library and test runner, from Microsoft, that drives Chromium, Firefox and WebKit through one API. Interviewers ask about it because it is the usual pick for a new end-to-end suite, and because its main design choices are deliberate answers to the flakiness that sank older suites: locators resolved at the last moment, actions that wait for the page to be ready, and a fresh, isolated profile for every test. A good Playwright answer says what the tool waits for, what it isolates, and what is still left for you to decide. The hub follows the life of a test. [Browsers and contexts](/topics/dev-playwright-browsers-contexts) covers the engines and the isolated profile each test receives. [Locators and auto-waiting](/topics/dev-playwright-locators) is the core model: how you name an element and when the framework decides it may act on it. [Assertions](/topics/dev-playwright-assertions) carries the same waiting into checks. [Fixtures and test config](/topics/dev-playwright-fixtures-config) is the runner's setup model, signed-in state included. [Network interception](/topics/dev-playwright-network) lets a test own the request layer, [tracing and debugging](/topics/dev-playwright-tracing-debugging) is how a failure gets read back, and [run orchestration](/topics/dev-playwright-execution) is workers, retries, shards and CI. [Isolated component runs](/topics/dev-playwright-component) and [positioning and migration](/topics/dev-playwright-positioning) sit at the edges: one asks how much a mounted component really proves, the other when Playwright is the right tool at all. Junior rounds check that you understand the API's model: what a context isolates, what a locator matches, why an unawaited check proves nothing. Senior and principal rounds turn to suite design — where setup belongs, how to keep hundreds of tests parallel and debuggable in CI, and what moving an existing suite across really costs. Start with contexts and locators. Every other section assumes them.

primer

### A locator is a recipe, not an element A locator describes how to find something — by role and accessible name, label, text or test id — and is resolved afresh on each use, never when it is created. That is why a locator survives re-renders that leave a stored element reference pointing at a detached node, and why chaining and filtering build new descriptions rather than narrowing a cached result. Interviewers expect user-facing queries first, and CSS or XPath only when the page offers nothing better. ### Waiting is built into actions and assertions Before an action fires, Playwright checks that the target can receive it, and keeps checking until it can or the timeout runs out. Web-first assertions do the same for a condition on the page. Together they remove most explicit waits from a suite, a large part of why Playwright suites flake less. The price is that a test can now wait, or pass, quietly: a missing `await`, a negated check that is true from the start, or a generous timeout can each hide a real failure. ### Strictness turns ambiguity into an error An action aimed at one element refuses to run when its locator matches several. The failure is loud on purpose — guessing the first match is how older suites clicked the wrong row. A good answer treats the error as a prompt to describe the element better, not to reach for `.first()`. ### One browser, many cheap contexts Launching a browser is slow; opening a context inside it is fast, and the context is isolated from its siblings, with its own cookies, storage, permissions and emulated device. Playwright Test builds on that: every test gets a fresh context, so isolation is the default and running tests side by side is safe. Sharing state — a saved signed-in state, a worker-scoped fixture — is then an explicit choice. ### The runner is a fixture system `@playwright/test` gives a test the objects it names in its signature (`page`, `context`, `request`) and builds and disposes of them around it. Your own setup goes through the same mechanism, scoped per test or per worker. The config's projects multiply a suite across browsers, devices or environments, and policy such as retries, timeouts and trace capture lives there rather than in test code. ### The test owns the edges A test can intercept, stub or replay any request, call the backend directly over HTTP, and record a trace of everything that happened. That is how a browser suite reaches states a real backend will not produce on demand, and explains failures a rerun does not reproduce.

Browser context
An isolated, incognito-like profile inside one running browser, with its own cookies, storage, permissions and emulation settings. Playwright Test creates a new one for every test.
Locator
A lazy description of how to find elements on a page, resolved again on every use. Actions and many assertions are called on it.
Element handle
A reference to one specific DOM node. Unlike a locator it is never re-resolved, so it goes stale when the page re-renders that part of the tree.
Actionability checks
The conditions Playwright verifies before an action, such as visible, stable, enabled and able to receive the pointer, retried until they pass or the action times out.
Strict mode
The rule that a locator used to act on a single element must match exactly one; matching more raises a strict mode violation instead of guessing.
Web-first assertion
An expect matcher on a locator or page that keeps re-checking its condition until it holds or the expect timeout expires, instead of checking once.
Fixture
A named value the runner builds on request for a test or a worker, with setup before the code that uses it and teardown after.
Project
A named run variant in the config, with its own options and file filters. Every matching test runs once per project.
Storage state
A saved file of a context's cookies and per-origin local storage, used to start new contexts already signed in without repeating the login flow.
Route
A handler registered on a page or context that intercepts matching requests and lets them continue, changes them, answers them itself or aborts them.
APIRequestContext
Playwright's HTTP client for calling a server directly, with no page involved. It can stand alone or share a browser context's cookies.
Trace
A zip of one test's recorded actions, DOM snapshots, network traffic and console output, opened in the Trace Viewer to replay what happened.
Worker
A separate operating-system process that runs tests one at a time. The workers setting decides how many run in parallel on one machine.

A run starts in a Node process, not in the page. The runner reads the config, expands it into projects, and starts worker processes; each worker launches a browser, usually one of the builds Playwright installed, and keeps a single connection open to it. For each test, fixtures build whatever the test asks for — usually a new context and its page — and the test body sends commands down that connection. An action's readiness checks are retried on the browser side, so waiting for a button costs one command rather than a polling loop of round trips. Everything else in the hub attaches to one of those objects: - **Routes** are registered on a page or a context and sit between the browser and the network; HAR replay is a recorded set of answers served the same way. - **API requests** come from a request context, either standalone or sharing a browser context's cookie jar. - **Signed-in state** is a saved file that a new context is created from. - **Traces, screenshots and video** are captured around each test and land in its output folder, where reporters and the Trace Viewer pick them up. - **Component mounting** replaces the application server with a page that renders one component, then hands back a locator like any other. CI is the same machinery scaled out: workers within a machine, shards across machines, and retries that re-run only failing tests and, with the right trace mode, capture evidence on the second attempt. A config and a test show the layers meeting. The config decides the device, the retry policy and what evidence to keep; the test takes over one endpoint, then relies on a locator and a retrying assertion: ```ts export default defineConfig({ retries: process.env.CI ? 2 : 0, use: { baseURL: 'http://localhost:3000', trace: 'on-first-retry' }, projects: [{ name: 'mobile-safari', use: { ...devices['iPhone 15'] } }], }); test('applies a coupon', async ({ page }) => { await page.route('**/api/coupons/*', (r) => r.fulfill({ json: { percentOff: 10 } })); await page.goto('/cart'); await page.getByRole('button', { name: 'Apply coupon' }).click(); await expect(page.getByText('10% off')).toBeVisible(); }); ``` Nothing in the test waits explicitly, and if it still fails in CI, the retry leaves a trace to open.

  1. Browsers and Contexts →

    The engines and the isolated context every test runs in; isolation explains much of what the runner does later.

  2. Locators and Auto-Waiting →

    The core model: naming elements by role or text, strictness, and the readiness checks before every action.

  3. Assertions →

    Retrying checks complete the waiting story and replace most explicit waits in a suite.

  4. Fixtures and Test Config →

    How the runner supplies setup, shapes projects and timeouts, and reuses signed-in state across tests.

  5. Network Interception →

    Stubbing, replaying and calling APIs directly to reach states the real backend will not produce on demand.

  6. Tracing and Debugging →

    Reading a failure back from traces and screenshots, the skill every CI-scale question assumes.

  • Leaving out await on an action or a web-first assertion: the test body moves on, and a failing check may never fail the test it belongs to.

  • Adding waitForTimeout sleeps where a retrying assertion on the expected state would wait only as long as needed and fail with a useful message.

  • Silencing a strict mode violation with .first() instead of writing a locator that names the one element a user would mean.

  • Asserting that something is gone without first asserting that the page loaded; a negated check passes on a page that never rendered at all.

  • Starting a waitForResponse or popup wait after the click that triggers it, so the event fires before anything is listening for it.

  • Letting parallel tests share one signed-in account while they change server data, then blaming the resulting flakiness on the tool.

  • Assuming the Python, Java and .NET bindings ship the whole runner — see which parts are JavaScript-only.

  • Treating a test that passed on retry as fixed: Playwright reports it as flaky, and the trace from the retry is where the cause usually shows.

This guide assumes Playwright 1.63, the release the answers below are written against. Playwright ships a new minor release every month or two and is still on the 1.x line, so "which version" means which 1.x — and several interview topics still reflect when an API arrived: - **1.27** added the user-facing locator methods — `getByRole`, `getByText`, `getByLabel`, `getByTestId` and their siblings — which is why older suites are full of CSS strings passed to `page.locator()`. - **1.32** introduced UI mode, the watching explorer that changed how many teams debug locally. - **1.38** deprecated `locator.type()` in favour of `pressSequentially()`, so older code and older answers use the earlier name. Component testing is still published as experimental packages, so its setup and API can move between minor releases. Browser builds are pinned to each Playwright release: upgrading the library upgrades the engines, which is one reason a version bump can shift screenshot baselines.

Playwright is mostly weighed against three neighbours. **Selenium** and the WebDriver standard drive real installed browsers, including ones Playwright cannot reach, from many languages and through a mature grid; Playwright trades that reach for its own pinned engines, built-in waiting and a richer event model. **Cypress** runs test code inside the browser beside the app, which gives a tight interactive loop but makes multi-tab flows and some cross-origin work harder; Playwright keeps the test outside the browser and drives it remotely. **Puppeteer** is a Chromium-first automation library from the same lineage; Playwright adds the other engines and a full test runner. Around it, unit and most component tests usually stay in a Node runner such as Jest or Vitest with a simulated DOM, while Playwright covers flows in real browsers. Its role-based queries follow the same accessibility-first idea as Testing Library. A device cloud or grid usually joins it only when real phones or legacy browsers are required. [Positioning and migration](/topics/dev-playwright-positioning) covers these choices in depth.

explore

report an issue with this guide →

questions

287 · 9 sections

Why would a Playwright test call page.clock.install instead of page.clock.setFixedTime?

level: juniorimportance: must knowfreq 56%
basics
~10 s

page.clock.setFixedTime only pins what Date.now and new Date report; timers keep running on real time. page.clock.install replaces the whole timer stack, so the test can pause, tick or jump the page's clock.

open as a page

In Playwright, what does spreading `devices['iPhone 15']` into a project's `use` block actually configure?

level: juniorimportance: must knowfreq 74%
basics
~20 s

A device descriptor is a bundle of browser context options under one name. Spreading it sets viewport, screen, userAgent, deviceScaleFactor, isMobile and hasTouch together, plus defaultBrowserType, which tells the test runner which engine to launch.

open as a page

Why does Playwright download its own Chromium, Firefox and WebKit builds instead of driving your installed browsers?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Playwright pins a patched build of each engine to its own release, so every machine runs an identical browser. Its WebKit is built from WebKit sources rather than Safari, and its Chromium is not the Chrome you have installed.

open as a page

In Playwright, what does the headless option on browserType.launch() control, and what is its default?

level: juniorimportance: must knowfreq 76%
basics
~20 s

Playwright's headless launch option decides whether the browser draws a visible window. It defaults to true, so launch() starts an invisible browser; passing headless: false opens a real window you can watch a failing flow in.

open as a page

In Playwright, which browser context options set the page's language and time zone?

level: juniorimportance: must knowfreq 66%
basics
~10 s

Playwright's locale and timezoneId context options. locale sets navigator.language, the Accept-Language header and Intl formatting; timezoneId sets the IANA zone that Date and Intl.DateTimeFormat resolve to.

open as a page

In Playwright, how does locator.setInputFiles() attach a file without the OS picker?

level: juniorimportance: must knowfreq 80%
basics
~20 s

Playwright sets the file input's file list directly through the browser protocol instead of driving the native dialog. Pass one path, several paths, an in-memory buffer object, or an empty array to clear the selection.

open as a page

In Playwright, how does locator.fill() differ from locator.pressSequentially() in what the page receives?

level: juniorimportance: must knowfreq 82%
basics
~20 s

locator.fill() focuses the field, selects any existing text and replaces it in one insertion, firing a single input event. locator.pressSequentially() sends keydown, keypress, input and keyup per character and does not clear the field first.

open as a page

In Playwright, what does locator.press('Control+Enter') send to the page, and how are key names resolved?

level: juniorimportance: must knowfreq 71%
basics
~10 s

locator.press focuses the matched element, holds Control, presses and releases Enter, then releases Control. The argument is one logical key name or a single character, with modifiers joined by plus signs.

open as a page

In Playwright, what must be true of an element before locator.click() actually clicks it?

level: juniorimportance: must knowfreq 82%
basics
~20 s

Playwright retries a set of actionability checks until they all pass or the call times out: the element must be visible, stable in position, able to receive pointer events at the click point, and enabled.

open as a page

In Playwright, what does locator.filter({ hasText: 'Blocked' }) return compared with the locator it was called on?

level: juniorimportance: must knowfreq 78%
basics
~20 s

A new locator matching the same kind of elements, minus the ones whose subtree lacks that text. The original locator is untouched, the match stays on the outer elements, and a string is matched case-insensitively as a substring.

open as a page

In Playwright, what does expect(locator).toMatchAriaSnapshot() compare, and what does it ignore?

level: juniorimportance: must knowfreq 45%
basics
~20 s

It compares an element's accessibility tree, meaning the roles, accessible names and a few ARIA states of its non-hidden nodes, against a YAML template. It ignores pixels, CSS, tag names, class names and hidden nodes.

open as a page

In Playwright, how does expect(locator).toBeHidden() differ from expect(locator).not.toBeVisible()?

level: juniorimportance: must knowfreq 58%
basics
~20 s

In outcome they are the same. Both retry until the element is hidden or absent from the DOM, and both pass when it never existed at all. The difference is readability and the failure message, not semantics.

open as a page

In Playwright, what happens the first time expect(page).toHaveScreenshot() runs and no reference image exists?

level: juniorimportance: must knowfreq 74%
basics
~20 s

Playwright captures the page, writes that capture to the snapshots folder as the new reference image, and still fails the test. A later run, or an automatic retry, compares against the file just written and passes.

open as a page

In Playwright, what does expect.soft() do that a plain expect() does not?

level: juniorimportance: must knowfreq 56%
basics
~10 s

A soft assertion records its failure and lets the test keep running, while a plain expect throws and stops the test at that line. Both end with the test reported as failed.

open as a page

In Playwright, what happens if you forget to await expect(locator).toBeVisible()?

level: juniorimportance: must knowfreq 84%
basics
~20 s

Playwright's web-first matchers return a promise. Without await, the test body runs on and the test finishes before the matcher decides anything, so the assertion can never fail it — the error is dropped or blamed on a later test.

open as a page

In Playwright Test, what do you get when a test destructures the page fixture?

level: juniorimportance: must knowfreq 88%
basics
~20 s

Playwright Test builds a brand-new BrowserContext for that one test and hands back the single page opened inside it. The runner creates it before the test body and closes it afterwards, so no test inherits another test's page.

open as a page

In Playwright, what does the await use(value) call do inside a test.extend fixture?

level: juniorimportance: must knowfreq 74%
basics
~20 s

It hands the fixture's value to the test and pauses the fixture there. Everything written above the call is setup; everything below it is teardown, which runs once the test finishes, whether it passed or failed.

open as a page

What does Playwright's webServer config option do before the first test runs?

level: juniorimportance: must knowfreq 71%
basics
~10 s

Playwright's webServer option spawns a command before the suite and waits until the url or port it names answers, then runs the tests and stops the process it started when the run ends.

open as a page

In Playwright, how do you run one spec as an admin and another as a read-only staff user?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Capture one storage-state file per role, then choose the file explicitly: a project per role carrying use.storageState in the config, or test.use with that role's file at the top of a spec or describe block.

open as a page

In a Playwright config, what does the `projects` array do?

level: juniorimportance: must knowfreq 78%
basics
~20 s

The projects array lists named run variants, each with its own use options and file filters. Playwright runs every matching spec once per project, so one test yields one result per project, and --project=<name> runs a single variant.

open as a page

In Playwright, what does the built-in request fixture let a test do without opening a page?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Playwright's request fixture is an APIRequestContext, a per-test HTTP client. It sends get, post, put, patch, delete or fetch calls straight to the server, with no browser page and no navigation, honouring config options such as baseURL.

open as a page

In Playwright, how do you capture a page's API response and assert on its body?

level: juniorimportance: must knowfreq 74%
basics
~10 s

Create the wait first with page.waitForResponse, matching by URL glob, RegExp or predicate, then trigger the action and await the promise. The resolved Response exposes status(), headers() and json() for assertions.

open as a page

In Playwright, how does route.fulfill() answer a request without it reaching the network?

level: juniorimportance: must knowfreq 84%
basics
~20 s

route.fulfill() completes a Playwright route by returning a response the test supplies, so the browser never contacts the real server. You set the status, headers and body, or pass a JSON object or a file path instead.

open as a page

In Playwright, what does browserContext.routeFromHAR() do to the requests a page makes?

level: juniorimportance: must knowfreq 62%
basics
~20 s

It installs a route that answers matching requests from a previously recorded HAR archive instead of the real server, so the test replays saved traffic. Requests the archive does not contain are aborted by default.

open as a page

In Playwright, what URL matchers can you pass to page.route() when intercepting a request?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Playwright's page.route() accepts three matcher forms: a glob string, a RegExp tested against the whole URL, or a predicate function receiving a parsed URL object. Only the URL is matched; method and headers are checked inside the handler.

open as a page

What does `npx playwright codegen <url>` open, and what does it produce?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Playwright's codegen command opens a browser plus a recorder window, transcribes every click, keystroke and navigation into runnable test code as you go, and hands back a first draft you copy or save with -o.

open as a page

What does npx playwright test --ui give you that a plain headed run does not?

level: juniorimportance: must knowfreq 62%
basics
~20 s

Playwright's UI mode opens a watching test explorer: pick tests, re-run them on save, and step through a recorded timeline with before and after DOM snapshots, plus a Pick locator button. A headed run only shows the browser flying past.

open as a page

In Playwright Test, what does the screenshot: 'only-on-failure' option capture, and where does the file land?

level: juniorimportance: must knowfreq 76%
basics
~20 s

The runner itself photographs every page open in the test at the moment the test ends failed, and only then. Each PNG is written into that test's folder under outputDir, test-results by default, and attached to the result.

open as a page

In Playwright, what does the config option trace: 'on-first-retry' record?

level: juniorimportance: must knowfreq 78%
basics
~10 s

Playwright records a trace only while a test runs its first retry. The original failing attempt is never traced, and if the project allows no retries, no trace is produced at all.

open as a page

How do you open a Playwright trace zip to step through a failed run?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Run npx playwright show-trace path/to/trace.zip to open it in Playwright's Trace Viewer, or drag the same zip onto trace.playwright.dev, which renders it in the browser with nothing installed.

open as a page

In Playwright, what does `npx playwright install --with-deps` do that plain `npx playwright install` does not?

level: juniorimportance: must knowfreq 70%
basics
~20 s

It also installs the operating-system packages the browsers link against, using the system package manager, before downloading them. Plain install only downloads the browser binaries, which then fail to launch on a bare Linux runner.

open as a page

In Playwright, what does the fullyParallel config option change about test scheduling?

level: juniorimportance: must knowfreq 82%
basics
~20 s

Playwright runs test files in parallel but keeps tests inside a file in order in one worker. Setting fullyParallel true schedules every individual test independently, so tests in the same file can also run at the same time.

open as a page

In Playwright, how do you run one suite with several reporters at once and give each its own options?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Set the reporter config option to an array of entries, each a reporter name plus an options object - for example list, junit with an outputFile, and html. The command line --reporter takes comma-separated names but carries no options.

open as a page

In Playwright, what does setting retries: 2 in playwright.config.ts do to a failing test?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Playwright re-runs a failing test up to two more times, so retries: 2 allows three runs in all. Only the failing test re-runs, and one that passes on a later attempt is reported as flaky rather than failed.

open as a page

What does Playwright's --shard=1/4 flag do to the set of tests a run executes?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Playwright splits the selected tests into four disjoint groups and runs only the first. Each shard is an independent run on its own machine, so all four have to be executed before the suite is covered.

open as a page

In Playwright, which parts of an application does a component test leave untested?

level: juniorimportance: must knowfreq 55%
basics
~20 s

A Playwright component test starts no application server, mounts no router and assembles no page. It proves one component in a bare harness, so API behaviour, navigation between screens and interactions between components stay uncovered.

open as a page

In a Playwright component test, what does the mount fixture hand back after it renders a story?

level: juniorimportance: must knowfreq 52%
basics
~20 s

The mount fixture resolves to a Locator pointing at the rendered component's root element. You drive and assert on it like any other locator, and the same handle also exposes update and unmount for that instance.

open as a page

In a Playwright component test, why can't you pass an onSelect callback in mount's props?

level: juniorimportance: must knowfreq 58%
basics
~20 s

Playwright sends mount's props across a process boundary into the browser, so only plain serialisable data survives. A function carries behaviour that cannot be transferred, so callbacks belong in the story file, not in the props object.

open as a page

In Playwright, what does mounting in a real browser engine catch that a simulated DOM cannot?

level: middleimportance: must knowfreq 62%
basics
~20 s

A Playwright component test renders in Chromium, Firefox or WebKit, so real CSS, real layout and real hit-testing apply. A simulated DOM in Node computes no boxes, so clipping, overlap and interception bugs stay invisible there.

open as a page

In Playwright component tests, how does calling update on a mounted component differ from mounting it again?

level: middleimportance: must knowfreq 44%
basics
~20 s

update re-renders the component already on the page with new props, so its internal state — an open menu, scroll position, focus — survives. Mounting again builds a fresh instance and throws all of that away.

open as a page

How does Playwright's test process control the browser it automates?

level: juniorimportance: must knowfreq 82%
basics
~20 s

Playwright test code runs in its own Node process, outside the browser. The library launches a browser build it ships itself and drives it over one long-lived connection that carries every command and every event for the whole session.

open as a page

In a Python Playwright suite, what does the pytest-playwright page fixture give each test?

level: juniorimportance: must knowfreq 58%
basics
~20 s

The pytest-playwright plugin's page fixture gives every test a fresh Playwright Page in its own new BrowserContext, opened on a session-scoped browser and closed automatically when the test ends, so cookies and storage never leak between tests.

open as a page

Which browser targets does Playwright leave uncovered when you weigh it against an existing browser grid?

level: middleimportance: must knowfreq 66%
basics
~20 s

Playwright 1.63 ships Chromium, Firefox and WebKit, and drives locally installed Chrome or Edge through channels. It cannot drive Internet Explorer, arbitrary historical engine builds, or real phones, so those targets still need a grid or a device cloud.

open as a page

Why can Playwright retry an action's readiness checks without paying a round trip per attempt?

level: middleimportance: must knowfreq 66%
basics
~20 s

Because the retrying happens on the browser side. One command crosses the already-open connection, and Playwright's browser-side code re-resolves the element and re-checks readiness in a loop until the action succeeds or that command's timeout expires.

open as a page

Which parts of Playwright do the Python, Java and .NET bindings get, and which are JavaScript-only?

level: middleimportance: must knowfreq 72%
basics
~20 s

Playwright's browser automation library, covering browser, context, page, locators, assertions, routing and tracing, ships in Python, Java and .NET. The @playwright/test runner does not: projects, retries, sharding, custom fixtures, component mounting and its reporters stay JavaScript-only.

open as a page