使用说明
多网站测试自动化框架
此仓库包含了使用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