|
|
há 1 mês atrás | |
|---|---|---|
| .. | ||
| fixtures | há 2 meses atrás | |
| pages | há 2 meses atrás | |
| specs | há 1 mês atrás | |
| utils | há 2 meses atrás | |
| README.md | há 2 meses atrás | |
| global-setup.ts | há 1 mês atrás | |
| global-teardown.ts | há 1 mês atrás | |
| playwright.config.ts | há 2 meses atrás | |
基于 Playwright 的端到端测试框架,用于验证完整的用户流程和系统功能。
tests/e2e/
├── specs/ # 测试用例
│ ├── auth/ # 认证相关测试
│ │ ├── login.spec.ts
│ │ ├── register.spec.ts
│ │ └── logout.spec.ts
│ ├── users/ # 用户管理测试
│ │ ├── user-crud.spec.ts
│ │ └── profile.spec.ts
│ └── admin/ # 管理后台测试
├── fixtures/ # 测试数据
│ └── test-users.json
├── pages/ # 页面对象模型
│ ├── login.page.ts
│ ├── register.page.ts
│ ├── dashboard.page.ts
│ └── user-management.page.ts
├── utils/ # 测试工具
│ ├── test-setup.ts
│ ├── test-teardown.ts
│ └── helpers.ts
├── playwright.config.ts # Playwright 配置
├── global-setup.ts # 全局设置
└── global-teardown.ts # 全局清理
pnpm install
npx playwright install --with-deps
pnpm test:e2e
pnpm test:e2e tests/e2e/specs/auth/login.spec.ts
pnpm test:e2e:ui
pnpm test:e2e:debug
pnpm test:e2e:chromium
测试用户账号:
测试在每次 push 到 main/develop 分支和 pull request 时自动运行。
pnpm devpnpm test:e2e测试完成后会生成以下报告:
tests/e2e/playwright-report/test-results/junit.xml使用页面对象模式封装页面交互逻辑:
class LoginPage {
async login(username: string, password: string) {
await this.usernameInput.fill(username);
await this.passwordInput.fill(password);
await this.loginButton.click();
}
}
test.describe('用户认证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/login');
});
test('成功登录', async ({ loginPage, dashboardPage }) => {
await loginPage.login('admin', 'admin123');
await dashboardPage.expectToBeVisible();
});
});
page.waitForLoadState('networkidle')npx playwright installtest.e2e:debug 启动调试模式page.pause() 暂停测试执行fullyParallel: true 并行执行测试workers 配置控制并发数retries 处理偶发性失败