测试框架
统一的测试框架,整合了E2E测试和开发环境测试。
目录结构
test-framework/
├── shared/ # 共享层
│ ├── config/ # 配置管理
│ ├── pages/ # 页面对象
│ ├── utils/ # 工具类
│ ├── fixtures/ # 测试fixtures
│ └── types/ # 类型定义
├── dev-audit/ # 开发环境测试
│ ├── performance/ # 性能测试
│ ├── seo/ # SEO测试
│ ├── accessibility/ # 可访问性测试
│ └── forms/ # 表单测试
├── e2e/ # E2E测试示例
├── reports/ # 测试报告
├── docs/ # 文档
├── playwright.config.ts # Playwright配置
├── package.json # 依赖和脚本
├── tsconfig.json # TypeScript配置
└── run-all-tests.sh # 一键测试脚本
快速开始
安装依赖
npm install
npm run test:install
运行测试
# 运行所有测试
npm run test
# 运行特定类型的测试
npm run test:dev-audit:performance
npm run test:dev-audit:seo
npm run test:dev-audit:accessibility
npm run test:dev-audit:forms
# 一键运行所有测试
./run-all-tests.sh
查看报告
npm run test:report
测试类型
性能测试
- 页面加载性能
- Core Web Vitals
- 资源加载时间
SEO测试
- Meta标签验证
- 标题结构检查
- 链接验证
可访问性测试
- WCAG 2.1 AA合规性
- 颜色对比度检查
- Alt文本验证
表单测试
- 必填字段验证
- 格式验证
- 提交功能测试
配置
测试配置位于 shared/config/ 目录:
base.config.ts- 基础配置environments.ts- 环境配置test-pages.ts- 测试页面配置test-data.ts- 测试数据配置
页面对象
所有页面对象位于 shared/pages/ 目录,继承自 BasePage。
可用的页面对象:
BasePage- 基础页面对象HomePage- 首页AboutPage- 关于页面ContactPage- 联系页面ProductsPage- 产品页面ServicesPage- 服务页面CasesPage- 案例页面NewsPage- 新闻页面
工具类
PerformanceMonitor- 性能监控LighthouseRunner- Lighthouse审计CoreWebVitals- Core Web VitalsAccessibilityTester- 可访问性测试SEOValidator- SEO验证TestReporter- 测试报告生成器
Fixtures
测试fixtures位于 shared/fixtures/ 目录:
base.fixture.ts- 基础fixtures(页面对象和配置)performance.fixture.ts- 性能测试fixturesaccessibility.fixture.ts- 可访问性测试fixtures
环境变量
TEST_ENV- 测试环境(development/staging/production)BASE_URL- 基础URL(可选,覆盖配置)
报告
测试报告生成在 reports/ 目录:
html/- HTML格式的可视化报告json/- JSON格式的结构化数据
贡献
请遵循项目的代码规范和测试最佳实践。
许可证
MIT