init by alirezarezvani/claude-skills
npx skills add https://github.com/alirezarezvani/claude-skills --skill init设置一个生产就绪的 Playwright 测试环境。检测框架,生成配置、文件夹结构、示例测试和 CI 工作流。
使用 Explore 子代理扫描项目:
package.json 以确定框架(React、Next.js、Vue、Angular、Svelte)tsconfig.json → 使用 TypeScript;否则使用 JavaScript@playwright/test)tests/、e2e/、__tests__/).github/workflows/、)广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
.gitlab-ci.yml如果尚未安装:
npm init playwright@latest -- --quiet
或者如果用户偏好手动设置:
npm install -D @playwright/test
npx playwright install --with-deps chromium
playwright.config.ts根据检测到的框架进行调整:
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):
baseURL 改为 http://localhost:5173webServer.command 改为 npm run devVue/Nuxt:
baseURL 改为 http://localhost:3000webServer.command 改为 npm run devAngular:
baseURL 改为 http://localhost:4200webServer.command 改为 npm run start未检测到框架:
webServer 块baseURL 或保留为占位符e2e/
├── fixtures/
│ └── index.ts # 自定义 fixtures
├── pages/
│ └── .gitkeep # 页面对象模型
├── test-data/
│ └── .gitkeep # 测试数据文件
└── example.spec.ts # 第一个示例测试
import { test, expect } from '@playwright/test';
test.describe('主页', () => {
test('应成功加载', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/.+/);
});
test('应有可见的导航栏', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('navigation')).toBeVisible();
});
});
如果存在 .github/workflows/,则创建 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: "安装依赖"
run: npm ci
- name: "安装-playwright-浏览器"
run: npx playwright install --with-deps
- name: "运行-playwright-测试"
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: "playwright-报告"
path: playwright-report/
retention-days: 30
如果存在 .gitlab-ci.yml,则改为添加一个 Playwright 阶段。
.gitignore如果尚未存在,则追加:
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
添加到 package.json 的 scripts 部分:
{
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug"
}
运行示例测试:
npx playwright test
报告结果。如果失败,则在完成前进行诊断和修复。
确认创建的内容:
npx playwright test 或 npm run test:e2e每周安装量
100
代码仓库
GitHub 星标数
4.3K
首次出现
8 天前
安全审计
已安装于
codex94
cursor93
github-copilot93
amp93
cline93
kimi-cli93
Set up a production-ready Playwright testing environment. Detect the framework, generate config, folder structure, example test, and CI workflow.
Use the Explore subagent to scan the project:
package.json for framework (React, Next.js, Vue, Angular, Svelte)tsconfig.json → use TypeScript; otherwise JavaScript@playwright/test in dependencies)tests/, e2e/, __tests__/).github/workflows/, .gitlab-ci.yml)If not already installed:
npm init playwright@latest -- --quiet
Or if the user prefers manual setup:
npm install -D @playwright/test
npx playwright install --with-deps chromium
playwright.config.tsAdapt 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):
baseURL to http://localhost:5173webServer.command to npm run devVue/Nuxt:
baseURL to http://localhost:3000webServer.command to npm run devAngular:
baseURL to http://localhost:4200webServer.command to npm run startNo framework detected:
webServer blockbaseURL from user input or leave as placeholdere2e/
├── fixtures/
│ └── index.ts # Custom fixtures
├── pages/
│ └── .gitkeep # Page object models
├── test-data/
│ └── .gitkeep # Test data files
└── example.spec.ts # First 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();
});
});
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: 30
If .gitlab-ci.yml exists, add a Playwright stage instead.
.gitignoreAppend if not already present:
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Add to package.json scripts:
{
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug"
}
Run the example test:
npx playwright test
Report the result. If it fails, diagnose and fix before completing.
Confirm what was created:
npx playwright test or npm run test:e2eWeekly Installs
100
Repository
GitHub Stars
4.3K
First Seen
8 days ago
Security Audits
Gen Agent Trust HubPassSocketFailSnykPass
Installed on
codex94
cursor93
github-copilot93
amp93
cline93
kimi-cli93
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
102,600 周安装