# AutoTaskSuite **Repository Path**: mzk6/auto-task-suite ## Basic Information - **Project Name**: AutoTaskSuite - **Description**: 一个基于 Python + Playwright + Pytest 的现代化 UI 自动化测试框架 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-14 - **Last Updated**: 2026-05-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UI 自动化测试框架 一个基于 **Python + Playwright + Pytest** 的现代化 UI 自动化测试框架,专为初学者设计,简单易懂。 ## 📁 项目结构 ``` auto-task-suite/ ├── config/ # 配置文件夹 │ ├── __init__.py │ └── settings.py # 配置文件 ├── pages/ # 页面对象文件夹 │ ├── __init__.py │ ├── base_page.py # 页面基类(封装通用方法) │ ├── baidu_page.py # 百度首页示例 │ └── yingdao_page.py # 影刀RPA测试页面 ├── tests/ # 测试用例文件夹 │ ├── __init__.py │ ├── conftest.py # Pytest配置和Fixture │ ├── test_baidu.py # 百度搜索测试示例 │ ├── test_example.py # 基础操作示例 │ └── test_yingdao.py # 影刀RPA功能测试 ├── reports/ # 测试报告目录 │ └── screenshots/ # 失败截图目录 ├── requirements.txt # 依赖包列表 ├── pytest.ini # Pytest配置文件 ├── .env.example # 环境变量示例 ├── run_tests.py # 测试运行脚本 └── README.md # 说明文档 ``` ## 🚀 快速开始 ### 1. 安装依赖 ```bash # 安装Python依赖 pip install -r requirements.txt # 安装Playwright浏览器 playwright install chromium ``` ### 2. 配置环境变量 ```bash # 复制示例文件 cp .env.example .env # 编辑 .env 文件,配置你的测试环境 ``` ### 3. 运行测试 ```bash # 运行所有测试 pytest # 或使用运行脚本 python run_tests.py # 运行特定测试套件 python run_tests.py smoke # 冒烟测试 python run_tests.py yingdao # 影刀RPA测试 python run_tests.py regression # 回归测试 # 生成HTML报告 python run_tests.py report # 无头模式运行 python run_tests.py headless ``` ## 📖 核心概念 ### 1. 页面对象模式 (Page Object Model) 将页面元素和操作封装在页面对象中,测试用例只关心业务逻辑。 ```python # pages/baidu_page.py class BaiduPage(BasePage): SEARCH_INPUT = "#kw" SEARCH_BUTTON = "#su" def search(self, keyword: str): self.fill(self.SEARCH_INPUT, keyword) self.click(self.SEARCH_BUTTON) self.wait_for_load_state("networkidle") ``` ### 2. 编写测试用例 ```python # tests/test_baidu.py class TestBaiduSearch: @pytest.mark.smoke @pytest.mark.search def test_search_function_works(self, page): baidu_page = BaiduPage(page) baidu_page.open() baidu_page.search("Playwright Python") baidu_page.assert_title_contains("Playwright") ``` ### 3. 使用标记 (Markers) ```python @pytest.mark.smoke # 冒烟测试 @pytest.mark.regression # 回归测试 @pytest.mark.search # 搜索相关 @pytest.mark.yingdao # 影刀RPA相关 ``` ## 🛠️ 常用命令 | 命令 | 说明 | |------|------| | `pytest` | 运行所有测试 | | `pytest -v` | 详细输出 | | `pytest -m smoke` | 运行冒烟测试 | | `pytest -m yingdao` | 运行影刀RPA测试 | | `pytest --headed=false` | 无头模式 | | `pytest --browser=firefox` | 使用Firefox浏览器 | | `pytest -k "search"` | 运行名称包含search的测试 | | `pytest --html=report.html` | 生成HTML报告 | ## 📝 添加新页面 1. 在 `pages/` 目录创建新文件 2. 继承 `BasePage` 类 3. 定义元素定位器 4. 封装页面操作方法 ```python # pages/login_page.py from pages.base_page import BasePage class LoginPage(BasePage): USERNAME_INPUT = "#username" PASSWORD_INPUT = "#password" LOGIN_BUTTON = "#login-btn" def login(self, username: str, password: str): self.fill(self.USERNAME_INPUT, username) self.fill(self.PASSWORD_INPUT, password) self.click(self.LOGIN_BUTTON) ``` ## 🔧 配置说明 编辑 `.env` 文件: ```env # 基础配置 BASE_URL=https://www.baidu.com HEADLESS=false SLOW_MO=100 # 测试账号 TEST_USERNAME=your_username TEST_PASSWORD=your_password ``` ## 📊 查看报告 测试完成后,打开 `reports/report.html` 查看详细报告。 失败测试会自动截图,保存在 `reports/screenshots/` 目录。 ## 💡 学习建议 1. **先阅读 `test_example.py`** - 了解基础操作 2. **再看 `test_baidu.py`** - 学习页面对象模式 3. **参考 `base_page.py`** - 了解封装的方法 4. **查看 `test_yingdao.py`** - 学习更复杂的测试场景 5. **动手实践** - 修改示例,添加自己的测试 ## 📚 相关文档 - [Playwright 官方文档](https://playwright.dev/python/) - [Pytest 官方文档](https://docs.pytest.org/) ## 许可证 本项目仅供学习交流使用。