fixtures
Skill222 starsChanged 4 months agoMITView on GitHub
Playwright fixture conventions for the Playwright scaffold — dependency-injection pattern, the single import point from fixtures/pom/test-options.ts (merged via mergeTests), the three fixture categories (page objects in fixtures/pom/, API request in fixtures/api/, lifecycle setup/teardown in fixtures/helper/), and the workflow for adding a new fixture. Use when adding a new page object fixture, registering a new fixture category, extending FrameworkFixtures or HelperFixtures, or deciding whether a reusable piece of code should be a Playwright fixture. For plain (non-fixture) utility functions used from tests or fixtures use the helpers skill; for the deep decision on when to promote API setup into a helper fixture vs calling apiRequest directly see the api-testing skill (Phase 8).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- efficience-it/claude-skills-phptheir own version, first seen Mar 31, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- efficience-it/claude-skills-php★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository37 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/rules.mdcCursor rule
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- selectorsSkill
- skill-creatorSkill
- test-standardsSkill
- type-safetySkill
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- selectorsSkill
- skill-creatorSkill
- test-standardsSkill
- type-safetySkill
- skill-creatorSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 11
ALWAYS: use fixtures for dependency injection.
- Very specific: line 12
ALWAYS: import test and expect from fixtures/pom/test-options.ts.
- Very specific: line 16
Every new fixture: must be typed: extend FrameworkFixtures (for page objects) or HelperFixtures (for lifecycle) — do not add untyped …
- Distinctive: line 58
If the need fits none of these rows, stop and ask.
- Distinctive: line 62
Before registering a page object fixture, confirm the page object itself was built correctly:
- Distinctive: line 123
If you added a completely new fixture category (not a page object, not a lifecycle helper), merge it so consumers pick it up automatically:
- Very specific: line 167
Use apiRequest directly for all API calls in tests.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Fixtures and Dependency Injection
Critical
- ALWAYS use fixtures for dependency injection. NEVER instantiate a page object manually in a test file (
new AppPage(page)is forbidden). - ALWAYS import
testandexpectfromfixtures/pom/test-options.ts. NEVER import them from@playwright/testin spec files. - Page object fixtures live in
fixtures/pom/page-object-fixture.ts. Do not create per-page fixture files. - Lifecycle (setup/teardown) fixtures live in
fixtures/helper/helper-fixture.ts. They use the Playwrightuse()callback pattern. - Plain utility functions (no fixture lifecycle) live in
helpers/— not infixtures/. See thehelpersskill. - Every new fixture must be typed: extend
FrameworkFixtures(for page objects) orHelperFixtures(for lifecycle) — do not add untyped fixtures. - Teardown uses
use(). Setup runs beforeuse(), data is yielded viause(data), teardown runs afteruse()— even if the test fails. - New fixture categories (not page objects, not lifecycle helpers) must be declared in their own
fixtures/{category}/{name}-fixture.tsfile and merged intotest-options.tsviamergeTests(). - Do not promote one-off API calls to helper fixtures. Helper fixtures are reserved for setup/teardown reused across 3+ spec files — see the
api-testingskill (Phase 8).
Fixture Architecture
fixtures/pom/test-options.ts ← Single import point (merges all fixtures)
├── fixtures/pom/page-object-fixture.ts ← Page object fixtures
├── fixtures/api/api-request-fixture.ts ← API request fixture (apiRequest for tests)
└── fixtures/helper/helper-fixture.ts ← Setup/teardown fixtures (important recurring operations)test-options.ts uses mergeTests() to combine fixture layers:
import { test as base, mergeTests, request } from '@playwright/test';
import { test as pageObjectFixture } from './page-object-fixture';
import { test as apiRequestFixture } from '../api/api-request-fixture';
import { test as helperFixture } from '../helper/helper-fixture';
const test = mergeTests(pageObjectFixture, apiRequestFixture, helperFixture);
const expect = base.expect;
export { test, expect, request };Instructions
Phase 1: Classify what you're adding
Match the need to the correct home. This table exists to stop fixtures from creeping into places they don't belong.
| Need | Home |
| New page object wired into tests via DI | Page object fixture in fixtures/pom/page-object-fixture.ts (extend, don't create new file) |
| One-off API call in a single test or describe | No fixture. Call apiRequest directly (see the api-testing skill) |
| Multi-step API setup/teardown reused across 3+ spec files with guaranteed lifecycle | Helper fixture in fixtures/helper/helper-fixture.ts (see the api-testing skill, Phase 8) |
| Reusable pure function (no fixture lifecycle) called from tests/fixtures | Plain function in helpers/ — not fixtures/ (see the helpers skill) |
| A genuinely new fixture category (not a page object, not API setup) | New file fixtures/{category}/{name}-fixture.ts, merged into test-options.ts via mergeTests() |
| Tweak to global Playwright config (timeouts, workers, retries, projects) | playwright.config.ts — not a fixture (see the config skill) |
If the need fits none of these rows, stop and ask. Do not invent a new location.
Phase 2: Prerequisites (only for page object fixtures)
Before registering a page object fixture, confirm the page object itself was built correctly:
- The page object was created after exploring the live application with
playwright-cli(see theselectorsskill → "Exploration-First Workflow"). - The page object includes feedback/validation message locators (success, error, field validation) — not just form inputs and buttons (see the
selectorsskill → "Feedback & Validation Message Selectors").
Registering a page object that was generated from guesses rather than observed UI defeats the purpose of the DI pattern. Stop and run the exploration first.
Phase 3: Create or extend the fixture file
For most additions, you are extending an existing file — page-object-fixture.ts or helper-fixture.ts. A brand-new file is only needed when you're introducing a new fixture category (Phase 5).
Scaffold of a standalone fixture file (used only for new categories):
// fixtures/[category]/[name]-fixture.ts
import { test as base } from '@playwright/test';
import { MyNewPage } from '../../pages/app/my-new.page';
export type MyFixtures = {
myNewPage: MyNewPage;
};
export const test = base.extend<MyFixtures>({
myNewPage: async ({ page }, use) => {
await use(new MyNewPage(page));
},
});Phase 4: Register the fixture type and implementation
For a page object, extend FrameworkFixtures in fixtures/pom/page-object-fixture.ts:
// fixtures/pom/page-object-fixture.ts
export type FrameworkFixtures = {
appPage: AppPage;
myNewPage: MyNewPage; // Add the type
resetStorageState: () => Promise<void>;
};
export const test = base.extend<FrameworkFixtures>({
appPage: async ({ page }, use) => {
await use(new AppPage(page));
},
myNewPage: async ({ page }, use) => {
await use(new MyNewPage(page)); // Add the fixture
},
resetStorageState: async ({ context }, use) => {
await use(async () => {
await context.clearCookies();
await context.clearPermissions();
});
},
});For a lifecycle fixture, extend HelperFixtures in fixtures/helper/helper-fixture.ts following the same shape. Helper fixtures use plain-function.ts internally (not the apiRequest fixture) because fixture-level code needs the raw request context — this is already wired in the scaffold.
Phase 5: (Only for new categories) Merge into test-options.ts
If you added a completely new fixture category (not a page object, not a lifecycle helper), merge it so consumers pick it up automatically:
// fixtures/pom/test-options.ts
const test = mergeTests(
pageObjectFixture,
apiRequestFixture,
helperFixture,
newCategoryFixture // ← add here
);Page objects added in Phase 4 need no mergeTests() change — pageObjectFixture is already merged.
Phase 6: Handle teardown via the use() callback
Any fixture that needs cleanup uses the Playwright lifecycle:
myFixture: async ({ page }, use) => {
// Setup -- runs BEFORE the test
const resource = await createResource();
// Yield -- passes data into the test
await use(resource);
// Teardown -- runs AFTER the test (even on failure)
await resource.cleanup();
},Order matters: code after await use(...) is the teardown. Do not teardown before use() — it won't run at all.
Built-in Fixtures
| Fixture | Source | Purpose |
appPage | page-object-fixture.ts | Main application page object |
resetStorageState | page-object-fixture.ts | Clears cookies and permissions (for login tests) |
apiRequest | api-request-fixture.ts | Type-safe API request function (primary tool for API calls in tests) |
createdResource | helper-fixture.ts | Example setup/teardown fixture (replace with your own) |
apiRequest fixture vs. helper fixtures
Use apiRequest directly for all API calls in tests. Create helper fixtures only for critical, recurring setup/teardown reused across many test files. See the api-testing skill (Phase 8) for the full decision guide, lifecycle pattern, and rule of thumb.
See Also
api-testingskill — Phase 8 owns the deep decision for helper fixtures (3+ files rule of thumb, lifecycle, apiRequest-vs-helper table).helpersskill — plain utility functions that are not Playwright fixtures (nouse()lifecycle).page-objectsskill — what a page object must look like before it's wrapped in a fixture.selectorsskill — exploration-first workflow and feedback-locator requirements for page objects.playwright-cliskill — how to run the live-app exploration before building the page object.common-tasksskill — prompt templates for "Add a New Page Object Fixture", "Add a Helper Fixture", "Add a New Fixture Category".debuggingskill —appPage is undefined/cannot read property of undefined/ fixture-lifecycle / merge-not-applied failures live here.references/examples.md— three worked walkthroughs (new page-object fixture, when NOT to create a fixture for a one-off call, brand-new fixture category).references/troubleshooting.md— common fixture pitfalls (wrongtestimport, fixture creep, teardown not running, missingmergeTests, helper-vs-fixture decision, manual instantiation temptation).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

