Testing / Playwright Interview questions
What is a fixture in Playwright?
A fixture is a reusable, self-contained piece of setup and teardown logic that Playwright Test injects into a test function as a parameter, rather than something the test author has to instantiate manually.
test('shows dashboard', async ({ page }) => { await page.goto('/dashboard'); });
Here page is a built-in fixture: Playwright creates a fresh browser context and page before the test, hands it to the test, and disposes of it afterward. Beyond the built-ins (page, context, browser, request), you can define custom fixtures with test.extend() - for example a loggedInPage fixture that performs login once and hands back an authenticated page.
Fixtures differ from a plain beforeEach hook because they're lazily created only when a test actually requests them, and they can depend on and compose with other fixtures.
More Related questions...