基于 Playwright + Pytest 的 Web UI 自动化测试框架
版本: 2.0 | 更新时间: 2025-12-11
- 🎯 Page Object 模式 - 页面元素与业务逻辑分离
- 📊 数据驱动测试 - 支持 Excel/JSON 数据源
- 🔄 登录态持久化 - 自动保存登录状态,提升效率
- 📈 Allure 测试报告 - 可视化报告,支持趋势分析
- 🔔 钉钉/邮件通知 - 测试结果实时推送
- ⚡ 用例顺序控制 - 灵活控制测试执行顺序
- 🐳 Docker 容器化 - 支持容器化部署和Jenkins集成
- 🌐 多环境支持 - QA4/PR/ON环境自动切换
# 克隆项目
git clone https://gitee.com/super_coding/playwright_ui_test.git
cd playwright_ui_test
# 创建虚拟环境
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Linux/Mac
# 安装依赖
pip install -r requirements.txt
playwright install chromium编辑 conf/login_conf.ini 和 conf/env_config.ini
# 执行所有测试
python run.py -w
# 执行测试并发送通知
python run.py -w -notify
# 查看报告
allure open case_report/allure-reportpw_test/
├── base/ # 基础框架层
├── page/ # 页面对象层(Page Object)
├── business/ # 业务逻辑层
├── case_scripts/ # 测试用例脚本
├── case_data/ # 测试数据(Excel/JSON)
├── case_report/ # 测试报告输出
├── conf/ # 配置文件
├── tools/ # 工具模块
├── run.py # 主执行脚本 ⭐
├── pytest.ini # Pytest配置
├── Dockerfile # Docker镜像构建
└── Jenkinsfile # Jenkins流水线
详细文档请查看: WMS自动化测试框架文档.md
文档包含:
- 技术架构详解
- 环境搭建指南
- 配置文件说明
- 测试用例开发
- Docker部署
- Jenkins集成
- 常见问题解答
- 开发规范
# 运行测试
python run.py -w # 执行所有测试
python run.py -w -env qa4 # 指定环境
python run.py -w -notify # 发送通知
# 查看报告
allure open case_report/allure-report
# Pytest直接运行
pytest -v -s
pytest case_scripts/web_ui/wms/in_warehouse_manage/test_in_asn_list_case.py| 问题 | 解决方案 |
|---|---|
| Playwright安装失败 | playwright install chromium |
| 登录失败 | rm auth/storage_state.json |
| 报告打不开 | allure open case_report/allure-report |
| 用例顺序不生效 | pip install pytest-order |
- Python 3.9+
- Playwright 1.55
- Pytest 8.4.2
- Allure 2.15
- Docker + Jenkins
祝测试愉快! 🎉