skip to content

Fixtures and Test Config

The runner's setup model: what it hands a test, what you write yourself, and the config file shaping projects, ordering, timeouts and signed-in state. Interviewers probe where setup belongs.

on this pageshow

explore

questions

page 2 of 2

Playwright loads a saved storageState, yet the admin console still renders signed out — how do you diagnose it?

level: seniorimportance: should knowfreq 52%

basics

~20 s

Open the JSON and compare it with the address under test. Usual causes are an origins entry recorded for a different origin, a session kept in sessionStorage which the file never captures, or state saved before the application had written it.

open as a page

A Playwright fixture that seeds admin-console staff accounts takes 45 seconds and every test times out. What do you change?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Fixture setup is charged to the test timeout by default, so a 45-second fixture blows a 30-second budget. Give that fixture its own timeout in its options tuple instead of raising the suite-wide timeout for every test.

open as a page

Why do a Playwright suite's tests pass alone yet fail in sequence once their setup moved to a worker-scoped fixture?

level: seniorimportance: should knowfreq 47%

basics

~20 s

A Playwright worker-scoped fixture is built once and the same instance is given to every test that worker runs, so a mutation by one test survives into the next. Run alone, a test always gets a freshly built value.

open as a page

In Playwright, how do you decide what becomes a custom fixture and what stays in test.beforeEach?

level: principalimportance: should knowfreq 40%

basics

~20 s

Setup that produces something the test uses belongs in a fixture: it names what it provides, pairs its own teardown, and runs only for tests that ask for it. Local arrangement for one file can stay in a hook.

open as a page

Your Playwright suite spends six minutes in setup projects before any test starts -- how do you decide what stays a suite-level precondition?

level: principalimportance: should knowfreq 27%

basics

~20 s

Judge each step by who needs it, how often it must run, and whether it needs a browser. Split one broad setup project into narrow ones so a project waits only for what it lists.

open as a page

When should a new variation in a Playwright suite become another entry in `projects` rather than a `test.use()` in the spec files?

level: principalimportance: should knowfreq 31%

basics

~20 s

Make it a project when the variation is an axis the whole suite should run under and be reported on separately. Keep it in test.use when only certain specs need it, since a project re-runs everything.

open as a page

In Playwright, what does a run-wide globalTimeout buy a CI pipeline that per-test timeouts cannot?

level: principalimportance: should knowfreq 33%

basics

~20 s

globalTimeout caps the wall-clock duration of an entire Playwright run and defaults to no limit. Per-test budgets bound one test each, so a large suite and its retries can still run for hours with no test misbehaving.

open as a page

In a growing Playwright suite, how do you decide which setup earns worker scope over test scope?

level: principalimportance: should knowfreq 34%

basics

~20 s

Promote a Playwright fixture to worker scope only when its value is read-only once built and its setup cost is measured and material. Test scope stays the default, because per-test isolation is what keeps a suite diagnosable as it grows.

open as a page

In Playwright Test, how does a test find out which browser engine it is running in?

level: juniorimportance: nice to knowfreq 36%

basics

~10 s

By destructuring the built-in browserName fixture, which is a plain string: chromium, firefox or webkit. Tests use it to branch, most often to skip a case that cannot run on one engine.

open as a page

In Playwright, how do you use two separately extended test objects in one spec file?

level: middleimportance: nice to knowfreq 26%

basics

~20 s

Combine them with mergeTests from the Playwright test package: mergeTests(staffTest, auditTest) returns one test object carrying both fixture sets. Importing both objects side by side does not work, and mergeExpects does the same job for custom matchers.

open as a page

When would you pass the object from context.storageState() to browser.newContext instead of a file path?

level: seniorimportance: nice to knowfreq 33%

basics

~20 s

Use the object when one process both mints and consumes the session: context.storageState() with no path returns it, and browser.newContext accepts it directly. Use a file path when another process, run or config must read the state.

open as a page

showing 31–41 of 41