多网站测试自动化框架
此仓库包含了使用Playwright对多个网站进行的自动化测试。每个网站都有一个专属的文件夹,其中包含测试、配置和结果。
项目结构
litmus-mcp-demo/
├── sauce-demo/ # SauceDemo website tests
│ ├── tests/ # Test specifications
│ ├── pom/ # Page Object Model
│ ├── fragments/ # Reusable fragments
│ ├── config/ # Test data & config
│ ├── test-plans/ # Documentation
│ ├── playwright.config.js # SauceDemo-specific config
│ └── test-results/ # SauceDemo test results
├── playwright.config.js # Main config (runs all websites)
└── package.json # Project dependencies & scripts设置说明
- 安装 Node.js (版本16或更高)
- 安装依赖项:
npm install- 安装 Playwright 浏览器:
npm run install-browsers运行测试
运行来自所有网站的所有测试
npm test在带界面模式(可见浏览器)下运行测试
npm run test:headed在调试模式下运行测试
npm run test:debug网站特定命令
仅限SauceDemo测试:
npm run test:sauce-demo
npm run test:sauce-demo:headed
npm run test:sauce-demo:debug
npm run test:sauce-demo:report运行特定的测试文件
npx playwright test sauce-demo/tests/login.spec.js针对特定浏览器运行测试
npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit并行运行测试(速度更快)
npx playwright test --workers=4测试报告
查看所有测试报告:
npm run test:report查看SauceDemo专用报告:
npm run test:sauce-demo:report报告按网站分类:
- 所有测试:
test-results/html-report/ - SauceDemo:
sauce-demo/test-results/html-report/
添加新网站
为新网站添加测试:
- 创建一个新文件夹(例如。,
new-website/) - 复制来自(某处/某文件)的结构
sauce-demo/:
- tests/ - 你的测试文件 - pom/ - 页面对象 - fragments/ - 可重复使用的片段 - config/ - 测试数据 - playwright.config.js - 网站特定配置
- 更新主(部分/内容)
playwright.config.js如需需要 - 为网站添加特定的npm脚本
package.json
