With 2–3 years of Playwright experience, interviewers expect you to own a framework: design decisions, advanced fixtures, network interception and mocking, preventing flaky tests, sharding and CI, Docker, reporting, and where Playwright fits in a broader test strategy.

Playwright interview questions by experience: Freshers · 2 years · 3 years · 5 years

102 questions with concise answers. Focus: framework design, flaky-test debugging, parallel/sharding, data strategy, auth, network/mocking, CI/CD, cross-browser.

Framework Design & Architecture

Walk me through your framework structure. Layered: tests(assert) → fixtures(DI) → pages/components(act) → utils/data/config(support), with central config + CI + Docker.

Where do assertions belong?

In tests, never in page objects.

How do specs get dependencies?

Custom fixtures inject them (dependency injection).

How do you keep a framework scalable?

Layer boundaries, composition, suite separation, unique data, parallel-safe isolation.

How do you structure test folders?

By suite (smoke/regression/api/e2e) for selective runs.

BasePage — what goes in it?

Only genuinely shared helpers; keep it thin.

Inheritance vs composition?

Prefer composition (components); avoid deep hierarchies.

How do you share the custom test?

Export extended test/expect from fixtures/test.ts, imported everywhere.

How do you handle repeated widgets?

Component objects (Header/ProductCard).

How do you onboard new engineers?

Documented conventions, fixtures hiding boilerplate, clear architecture.

What makes tests readable?

Intent-named methods, steps, assertions in tests, business-like specs.

How do you enforce standards?

ESLint/Prettier/strict tsconfig in CI, PR review, branch protection.

Advertisement

Authentication

How do you avoid logging in every test?

storageState saved once in setup, loaded via use.storageState.

How does the setup project work?

A setup project logs in and saves state; browser projects depend on it.

How to test multiple roles?

Separate storageState files per role; load per test/fixture.

Why not commit storageState?

It contains live session tokens (a secret).

What if the session expires?

Regenerate storageState in setup each run.

UI login vs API login?

UI for login tests; API/token seeding for speed elsewhere (Strategy pattern).

How to seed a token into the browser?

addInitScript to set localStorage, or set cookies via context.

Data Strategy

How do you manage test data?

Static JSON for reference, Faker factories for dynamic unique data.

How to prevent parallel collisions?

Unique data per test (Faker/UUID/timestamp).

How do you seed/clean data?

Via API in hooks/fixtures; clean up in teardown.

Factory vs Builder?

Factory creates from defaults/overrides; Builder assembles complex/optional fields step-by-step.

Where do factories live?

In data/ or utils/, typed.

How do you handle environment-specific data?

Env-keyed files/config; validated at startup.

How do you keep data out of the repo?

Secrets in env/CI stores; .gitignore .env*.

Parallel Execution & Scale

How does Playwright parallelize?

Multiple worker processes with isolated contexts; fullyParallel within files.

What is fullyParallel?

Parallelizes tests within a file too (requires independence).

How to run 5,000 tests fast?

Parallel workers + CI sharding + API/storageState setup + isolation.

What is sharding?

Splitting the suite across machines with --shard=k/n.

How to merge sharded reports?

--reporter=blob per shard, then merge-reports.

How many workers should you use?

Tuned to CPU/memory; too many thrash and flake.

When to use serial mode?

Rare truly-ordered flows: test.describe.configure({ mode: 'serial' }).

Common parallel pitfall?

Shared/duplicate data → collisions; fix with unique data + isolation.

Flaky Tests (deep)

How do you handle flaky tests?

Reproduce (--repeat-each), diagnose via trace, fix root cause; retries for infra only.

Most common cause?

Timing/races — fixed by web-first assertions + event-based waits.

How to reproduce a flake?

npx playwright test spec.ts --repeat-each=20.

How to prevent data flakiness?

Unique data + isolation.

Assert final state; disable animations in test builds.

Third-party flakiness?

Mock/abort non-essential calls (ads/analytics).

Is bumping retries a fix?

No — it masks bugs; cap retries and treat “flaky” as a ticket.

How do you track flakiness?

A flakiness metric/dashboard; investigate every flaky-tagged run.

Retries

When to use retries?

Transient CI/infra flakiness only.

Where to set them?

CI only, 1–2, with trace: 'on-first-retry'.

How do retries surface in reports?

As “flaky” when a retry passes — your signal to fix.

Network & Mocking

waitForResponse vs route?

Observe vs intercept (modify/block/fulfill).

How to block analytics?

page.route('**/analytics/**', r => r.abort()).

How to mock an API?

route(pattern, r => r.fulfill({status, body})).

How to test an error state deterministically?

Fulfill with 4xx/5xx and assert the error UI.

How to modify a real response?

route.fetch() the original, mutate, fulfill({response, json}).

Risk of over-mocking?

Tests pass on fake data while real integrations break.

How to verify the UI hit the right endpoint?

waitForRequest with a URL/method predicate.

What must a route handler do?

Resolve via continue/abort/fulfill or the request hangs.

Cross-Browser

How to run cross-browser?

One project per browser/device.

How to emulate mobile?

devices['Pixel 7']/iPhone 14 in a project.

Handle a WebKit-only difference?

Branch on browserName or skip with a reason; prefer outcome assertions.

Why not test only Chromium?

You’ll ship Firefox/WebKit-specific bugs.

API & Integration (deeper)

How to validate a response contract?

JSON-schema validation on the body.

How do you test UI+API integration?

Seed via API, act via UI, verify via API (or reverse).

Why verify at both layers?

UI “success” can hide persistence failures; API-only misses rendering bugs.

How do you share auth across API and UI?

A common token/storageState.

How do you clean up API-seeded data?

Delete in teardown using captured ids.

CI/CD

CI stages for a suite?

checkout → install → browsers(--with-deps) → test(shard) → report → gate.

Smoke vs regression in CI?

Smoke on PRs (fast gate), regression on merge/nightly.

How to publish results?

JUnit for the dashboard + HTML/traces as artifacts.

Why if: always() on artifact upload?

Keep reports/traces when tests fail.

How do you gate merges?

Branch protection requiring the workflow to pass.

How to speed CI installs?

Cache npm + browser binaries; npm ci.

GitHub Actions vs Jenkins?

Hosted/YAML/quick vs self-hosted/Groovy/enterprise control.

How to handle CI secrets?

Actions secrets / Jenkins credentials injected as env vars.

Reporting & Logging

Which reporters do you use?

HTML + JUnit at minimum; blob for sharding; custom for notifications.

How do you debug a CI-only failure?

Download the trace/video; inspect DOM/network at the failing step.

How to capture browser console errors?

page.on('console'/'pageerror'); assert none on key pages.

How to merge reports across shards?

merge-reports --reporter=html.

Debugging

Debugging tools?

--debug (Inspector), --ui (UI mode), trace viewer, page.pause(), --headed.

Strict mode violation — fix?

Narrow/scope the locator to be unique.

“Element not actionable” cause?

Overlay/animation covering it or off-screen — wait/dismiss/scroll.

“Passes locally, fails in CI” approach?

Trace/video, check deps/TZ/locale/headless/env; Docker for parity.

TypeScript / Code Quality

Why typed page objects?

Autocomplete, refactor safety, fewer runtime errors.

How do you add a custom assertion?

expect.extend({...}).

How do you keep utilities maintainable?

Small, pure, typed, single-purpose modules by concern.

How do you avoid a monolithic helpers file?

Split by domain (strings/dates/files/api).

Environment Management

One suite, many environments — how?

Env-driven config (TEST_ENV → .env.<env>), reading vars.

How to prevent missing-config failures?

Validate required env vars at startup (fail fast).

How do you guard against PROD accidents?

Explicit opt-in flag + env validation.

Where do secrets live?

CI stores/local gitignored .env; commit .env.example.

Scenario Starters (be ready to expand)

Design a framework for an e-commerce app. Requirements → layered architecture → reliability → speed → CI/CD → trade-offs.

Reduce a 3-hour suite to minutes. Parallel + shard + API/storageState setup + mock non-essentials + isolation.

A test fails only in Jenkins. Trace from the agent; check deps/TZ/locale/env; run on the Playwright image locally.

Handle dynamic locators. Semantic locators + data-testid + relative locators; avoid volatile ids/XPath.

Reusable POM for a large app. BasePage + components + name-parameterized locators + fixtures.

Multi-env + secrets. dotenv keyed by TEST_ENV, validated; secrets from CI stores.

Intermittent failures in CI. Reproduce with --repeat-each, trace, fix waits/data; retries for infra only.

Test data at scale. Factories for unique data; API seed/clean; isolation.

Auth across many tests. setup project + storageState per role; ApiLogin strategy for speed.

Run only impacted tests. Tags + --grep; folder/suite separation; (advanced) test impact analysis.

Rapid-fire Concepts

What is test.step for?

Readable, grouped report/trace steps.

What is a worker?

A process running a slice of tests in isolation.

What is on-first-retry trace?

Records a trace only when a retry happens.

What is frameLocator?

Scopes locators into an iframe (auto-waiting, cross-origin capable).

What is storageState?

Saved cookies/localStorage representing a session.

What is fullyParallel?

Parallelize tests within files, not just across files.

FAQs

How do I show framework experience in a Playwright interview?

Walk through your structure (fixtures, page objects, config, data), how tests run in parallel and in CI, how failures are diagnosed with traces, and one flaky test you fixed and why it was flaky.