Playwright Init
Set up a production-ready Playwright environment: detect framework, generate config, structure, example test, and CI.
Steps
Analyze project —
package.jsonframework (React/Next/Vue/Angular/Svelte),tsconfig.json→ TS else JS, whether@playwright/testis installed, existing test dirs (tests//e2e//__tests__/), existing CI config.Install (if absent):
npm init playwright@latest -- --quiet, or manualnpm install -D @playwright/test && npx playwright install --with-deps chromium.Generate
playwright.config.ts— framework-adapted. Core:testDir: './e2e',fullyParallel: true,forbidOnly: !!process.env.CI,retries: CI ? 2 : 0,workers: CI ? 1 : undefined, reporters[['html',{open:'never'}],['list']],use: { baseURL, trace: 'on-first-retry', screenshot: 'only-on-failure' }, projects chromium/firefox/webkit,webServer: { command, url, reuseExistingServer: !CI }. baseURL/webServer per framework: Next/Vue/Nuxthttp://localhost:3000npm run dev; React-Vite:5173npm run dev; Angular:4200npm run start; none → omit webServer.Folder structure —
e2e/{fixtures/index.ts, pages/.gitkeep, test-data/.gitkeep, example.spec.ts}.Example test — homepage loads (
toHaveTitle(/.+/)), visible navigation (getByRole('navigation')).CI workflow — if
.github/workflows/exists, createplaywright.yml(checkout, setup-node lts,npm ci,npx playwright install --with-deps,npx playwright test, uploadplaywright-report/artifact retention 30d). If.gitlab-ci.yml, add a Playwright stage instead..gitignore— append/test-results/,/playwright-report/,/blob-report/,/playwright/.cache/.npm scripts —
test:e2e,test:e2e:ui(--ui),test:e2e:debug(--debug).Verify — run
npx playwright test; if it fails, diagnose and fix before finishing.
Output
Confirm: config path + key settings, test dir + example, CI workflow (if added), npm scripts, how to run.