webapp-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWeb App Testing
Web应用测试
Discover and test everything. Leave no route untested.
发现并测试所有内容,不要遗漏任何路由。
🔧 Runtime Scripts
🔧 运行时脚本
Execute these for automated browser testing:
| Script | Purpose | Usage |
|---|---|---|
| Basic browser test | |
| With screenshot | | |
| Accessibility check | |
Requires:
pip install playwright && playwright install chromium执行以下脚本以进行自动化浏览器测试:
| Script | 用途 | 使用方式 |
|---|---|---|
| 基础浏览器测试 | |
| 带截图 | | |
| 可访问性检查 | |
依赖要求:
pip install playwright && playwright install chromium1. Deep Audit Approach
1. 深度审计方法
Discovery First
先进行发现
| Target | How to Find |
|---|---|
| Routes | Scan app/, pages/, router files |
| API endpoints | Grep for HTTP methods |
| Components | Find component directories |
| Features | Read documentation |
| 目标 | 查找方式 |
|---|---|
| 路由 | 扫描app/、pages/、路由文件 |
| API端点 | 搜索HTTP方法 |
| 组件 | 查找组件目录 |
| 功能 | 阅读文档 |
Systematic Testing
系统化测试
- Map - List all routes/APIs
- Scan - Verify they respond
- Test - Cover critical paths
- 梳理 - 列出所有路由/API
- 扫描 - 验证它们是否正常响应
- 测试 - 覆盖关键路径
2. Testing Pyramid for Web
2. Web应用测试金字塔
/\ E2E (Few)
/ \ Critical user flows
/----\
/ \ Integration (Some)
/--------\ API, data flow
/ \
/------------\ Component (Many)
Individual UI pieces /\ E2E (少量)
/ \ 关键用户流程
/----\
/ \ 集成测试(部分)
/--------\ API、数据流
/ \
/------------\ 组件测试(大量)
独立UI片段3. E2E Test Principles
3. E2E测试原则
What to Test
测试内容
| Priority | Tests |
|---|---|
| 1 | Happy path user flows |
| 2 | Authentication flows |
| 3 | Critical business actions |
| 4 | Error handling |
| 优先级 | 测试项 |
|---|---|
| 1 | 用户流程顺畅路径 |
| 2 | 认证流程 |
| 3 | 关键业务操作 |
| 4 | 错误处理 |
E2E Best Practices
E2E测试最佳实践
| Practice | Why |
|---|---|
| Use data-testid | Stable selectors |
| Wait for elements | Avoid flaky tests |
| Clean state | Independent tests |
| Avoid implementation details | Test user behavior |
| 实践方式 | 原因 |
|---|---|
| 使用data-testid | 稳定的选择器 |
| 等待元素加载 | 避免不稳定的测试 |
| 清理测试状态 | 保证测试独立性 |
| 避免测试实现细节 | 测试用户行为 |
4. Playwright Principles
4. Playwright测试原则
Core Concepts
核心概念
| Concept | Use |
|---|---|
| Page Object Model | Encapsulate page logic |
| Fixtures | Reusable test setup |
| Assertions | Built-in auto-wait |
| Trace Viewer | Debug failures |
| 概念 | 用途 |
|---|---|
| Page Object Model | 封装页面逻辑 |
| Fixtures | 可复用的测试设置 |
| Assertions | 内置自动等待 |
| Trace Viewer | 调试失败案例 |
Configuration
配置
| Setting | Recommendation |
|---|---|
| Retries | 2 on CI |
| Trace | on-first-retry |
| Screenshots | on-failure |
| Video | retain-on-failure |
| 设置项 | 推荐配置 |
|---|---|
| 重试次数 | CI环境下重试2次 |
| 追踪 | 首次重试时启用 |
| 截图 | 测试失败时启用 |
| 录屏 | 失败时保留录屏 |
5. Visual Testing
5. 视觉测试
When to Use
适用场景
| Scenario | Value |
|---|---|
| Design system | High |
| Marketing pages | High |
| Component library | Medium |
| Dynamic content | Lower |
| 场景 | 价值 |
|---|---|
| 设计系统 | 高价值 |
| 营销页面 | 高价值 |
| 组件库 | 中等价值 |
| 动态内容 | 较低价值 |
Strategy
策略
- Baseline screenshots
- Compare on changes
- Review visual diffs
- Update intentional changes
- 基准截图
- 在变更时进行对比
- 审核视觉差异
- 更新有意的变更
6. API Testing Principles
6. API测试原则
Coverage Areas
覆盖范围
| Area | Tests |
|---|---|
| Status codes | 200, 400, 404, 500 |
| Response shape | Matches schema |
| Error messages | User-friendly |
| Edge cases | Empty, large, special chars |
| 领域 | 测试项 |
|---|---|
| 状态码 | 200, 400, 404, 500 |
| 响应结构 | 符合数据模型 |
| 错误信息 | 对用户友好 |
| 边缘案例 | 空值、大体积数据、特殊字符 |
7. Test Organization
7. 测试组织
File Structure
文件结构
tests/
├── e2e/ # Full user flows
├── integration/ # API, data
├── component/ # UI units
└── fixtures/ # Shared datatests/
├── e2e/ # 完整用户流程
├── integration/ # API、数据
├── component/ # UI单元
└── fixtures/ # 共享数据Naming Convention
命名规范
| Pattern | Example |
|---|---|
| Feature-based | |
| Descriptive | |
| 模式 | 示例 |
|---|---|
| 基于功能 | |
| 描述性命名 | |
8. CI Integration
8. CI集成
Pipeline Steps
流水线步骤
- Install dependencies
- Install browsers
- Run tests
- Upload artifacts (traces, screenshots)
- 安装依赖
- 安装浏览器
- 运行测试
- 上传产物(追踪文件、截图)
Parallelization
并行化
| Strategy | Use |
|---|---|
| Per file | Playwright default |
| Sharding | Large suites |
| Workers | Multiple browsers |
| 策略 | 适用场景 |
|---|---|
| 按文件 | Playwright默认方式 |
| 分片 | 大型测试套件 |
| 多工作进程 | 多浏览器测试 |
9. Anti-Patterns
9. 反模式
| ❌ Don't | ✅ Do |
|---|---|
| Test implementation | Test behavior |
| Hardcode waits | Use auto-wait |
| Skip cleanup | Isolate tests |
| Ignore flaky tests | Fix root cause |
Remember: E2E tests are expensive. Use them for critical paths only.
| ❌ 不要做 | ✅ 应该做 |
|---|---|
| 测试实现细节 | 测试行为 |
| 硬编码等待 | 使用自动等待 |
| 跳过清理工作 | 隔离测试 |
| 忽略不稳定测试 | 修复根本原因 |
注意: E2E测试成本较高,仅用于关键路径测试。