Playwright Test Bootstrap
Purpose
Scaffold a production-ready Playwright project or generate structured test files following best practices — organized for maintainability, reliability, and QA team reuse.
Input Accepted
- Request to init a new Playwright project from scratch
- Feature name or module to add tests for
- User Story or Gherkin scenarios to automate
- API endpoint to validate through UI + API setup
- Existing Playwright suite to extend
Project Structure (Full Bootstrap)
[project-name]/
├── playwright.config.ts
├── package.json
├── tsconfig.json
├── .env.example
├── .gitignore
├── tests/
│ ├── auth.setup.ts ← API login + storage state setup
│ └── [module]/
│ └── [feature].spec.ts
├── pages/
│ └── [FeatureName]Page.ts ← Page Object Model
└── utils/
└── api-client.ts ← API helper functions
Generation Process
Full Project Bootstrap — generates:
playwright.config.ts— config with projects, artifacts, retries, base URLpackage.json— dependencies and run scriptstsconfig.json— TypeScript configuration.env.example— environment variable template.gitignore— excludes artifacts, credentials, node_modulestests/auth.setup.ts— API login + storage state bootstraputils/api-client.ts— reusable API helper functionspages/TransferPage.ts— sample page object- Sample transfer spec ready to adapt to the target feature
Single Spec File — generates:
test.describe()block for the featurebeforeEachwith navigation and stable setuptest()blocks for Happy Path / Negative / Boundary cases- Assertions with
await expect(...)— neverwaitForTimeout() - Stable locators with
getByTestId()when available
Key Conventions
✅ For authenticated features, create auth state via API in setup — not via UI in every test
✅ Use getByTestId() or equally stable locators
✅ Use await expect(...) for web-first assertions
✅ Use test.describe() and test.step() for readable structure
✅ Avoid waitForTimeout() and brittle sleeps
✅ Keep each test independent and cleanup-friendly
✅ Store credentials and URLs in environment variables only
References
references/playwright-conventions.md— selector, assertion, auth, and config rulesreferences/page-object-pattern.md— Page Object Model implementation guide for Playwrightexamples/playwright.config.ts— production-ready configurationexamples/auth.setup.ts— authenticated storage state exampleexamples/transfer.spec.ts— complete spec file examplescripts/init-project.sh— CLI scaffold script