pw-init – skill Lập trình cho agent AI
Thiết lập Playwright trong dự án. Dùng khi người dùng nói “thiết lập playwright”, “thêm e2e test”, “cấu hình playwright”, “thiết lập testing”, “khởi tạo playwright”, hoặc “thêm hạ tầng test”.
Cài skill pw-init bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/pw-init-b2cc7.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /pw-init – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/pw-init-b2cc7.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $pw-init – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/pw-init-b2cc7.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /pw-init – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/pw-init-b2cc7.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /pw-init – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Initialize Playwright Project
Set up a production-ready Playwright testing environment. Detect the framework, generate config, folder structure, example test, and CI workflow.
Steps
1. Analyze the Project
Use the Explore subagent to scan the project:
- Check
package.jsonfor framework (React, Next.js, Vue, Angular, Svelte) - Check for
tsconfig.json→ use TypeScript; otherwise JavaScript - Check if Playwright is already installed (
@playwright/testin dependencies) - Check for existing test directories (
tests/,e2e/,__tests__/) - Check for existing CI config (
.github/workflows/,.gitlab-ci.yml)
2. Install Playwright
If not already installed:
npm init playwright@latest -- --quietOr if the user prefers manual setup:
npm install -D @playwright/test
npx playwright install --with-deps chromium3. Generate playwright.config.ts
Adapt to the detected framework:
Next.js:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [
['html', { open: 'never' }],
['list'],
],
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: "chromium", use: { ...devices['Desktop Chrome'] } },
{ name: "firefox", use: { ...devices['Desktop Firefox'] } },
{ name: "webkit", use: { ...devices['Desktop Safari'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});React (Vite):
- Change
baseURLtohttp://localhost:5173 - Change
webServer.commandtonpm run dev
Vue/Nuxt:
- Change
baseURLtohttp://localhost:3000 - Change
webServer.commandtonpm run dev
Angular:
- Change
baseURLtohttp://localhost:4200 - Change
webServer.commandtonpm run start
No framework detected:
- Omit
webServerblock - Set
baseURLfrom user input or leave as placeholder
4. Create Folder Structure
e2e/
├── fixtures/
│ └── index.ts # Custom fixtures
├── pages/
│ └── .gitkeep # Page object models
├── test-data/
│ └── .gitkeep # Test data files
└── example.spec.ts # First example test5. Generate Example Test
import { test, expect } from '@playwright/test';
test.describe('Homepage', () => {
test('should load successfully', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/.+/);
});
test('should have visible navigation', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('navigation')).toBeVisible();
});
});6. Generate CI Workflow
If .github/workflows/ exists, create playwright.yml:
name: "playwright-tests"
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: "install-dependencies"
run: npm ci
- name: "install-playwright-browsers"
run: npx playwright install --with-deps
- name: "run-playwright-tests"
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: "playwright-report"
path: playwright-report/
retention-days: 30If .gitlab-ci.yml exists, add a Playwright stage instead.
7. Update .gitignore
Append if not already present:
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/8. Add npm Scripts
Add to package.json scripts:
{
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug"
}9. Verify Setup
Run the example test:
npx playwright testReport the result. If it fails, diagnose and fix before completing.
Output
Confirm what was created:
- Config file path and key settings
- Test directory and example test
- CI workflow (if applicable)
- npm scripts added
- How to run:
npx playwright testornpm run test:e2e
Skill liên quan
- electron-development – Làm chủ phát triển ứng dụng desktop Electron với IPC an toàn, contextIsolation, preload…
- elixir – Hướng dẫn mã nguồn chuyên biệt cho Elixir.
- track-management – Dùng skill này khi tạo, quản lý hoặc làm việc với track Conductor — đơn vị công việc…
- pw-review – Đánh giá chất lượng test Playwright. Dùng khi người dùng nói “review test”, “kiểm tra…
- system-atlas – Xây dựng atlas kiến trúc isometric có thể khám phá dưới dạng HTML.
- turborepo-caching – Cấu hình Turborepo để build monorepo hiệu quả với cache cục bộ và từ xa. Dùng khi thiết…
- systematic-debugging – Gỡ lỗi nguyên nhân gốc qua 4 giai đoạn: hiểu lỗi trước khi sửa.
- employment-contract-templates – Mẫu và cách soạn bản nháp tài liệu lao động để luật sư địa phương rà soát, gồm hợp đồng…