Day 58 of 100: Typing Fixtures — test.extend Decoded
Day 58 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: TypeScript. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Playwright fixtures are typed through one generic: test.extend
Contents
The Shape (Pure TS View)
// Simplified model of what Playwright does:
type TestFn = (name: string, fn: (fixtures: Fx) => Promise) => void;
type BaseFixtures = { page: { goto(u: string): Promise } };
// extend merges your fixtures into the base:
declare function extend(setup: {
[K in keyof Extra]: (
deps: BaseFixtures & Extra,
use: (value: Extra[K]) => Promise,
) => Promise;
}): TestFn;
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
What You Actually Write
// fixtures.ts — the real Playwright pattern:
// import { test as base } from '@playwright/test';
// import { LoginPage } from '@pages/LoginPage';
//
// type MyFixtures = {
// loginPage: LoginPage;
// adminUser: { email: string; password: string };
// };
//
// export const test = base.extend({
// loginPage: async ({ page }, use) => {
// await use(new LoginPage(page));
// },
// adminUser: async ({}, use) => {
// const user = { email: `admin-${Date.now()}@t.io`, password: 'Pw1!' };
// await use(user); // test runs while 'used'
// // teardown after use() resolves
// },
// });
// export { expect } from '@playwright/test';
Type Flow
- MyFixtures keys become destructurable test args: async ({ loginPage, adminUser })
- Each setup receives (deps, use) — deps typed as base + your fixtures
- Code before use() = setup; after = teardown. The generic enforces value types end to end
Tomorrow (Day 59): satisfies and typed config objects.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
