# 通用 Web 测试框架使用指南 ## 概述 这个通用测试框架可以测试任意网站,不再局限于特定系统。支持多种测试模式和配置方式。 ## 快速开始 ### 1. 最简单的使用方式 ```bash # 测试任意网站(默认使用 claude 模型) python tests/quick_test.py https://github.com # 使用其他模型 python tests/quick_test.py https://github.com --model glm # 无头模式(不显示浏览器窗口) python tests/quick_test.py https://github.com --headless # 限制点击次数 python tests/quick_test.py https://github.com --max-clicks 20 # 需要登录的测试 python tests/quick_test.py https://example.com --login --username user@example.com --password yourpassword ``` ### 2. 使用配置文件 #### JSON 配置示例 ```bash # 使用 JSON 配置文件 python tests/universal_tester.py --config tests/configs/github_example.json ``` #### YAML 配置示例 ```bash # 使用 YAML 配置文件 python tests/universal_tester.py --config tests/configs/enterprise_system.yaml ``` ### 3. 命令行参数 ```bash python tests/universal_tester.py --url https://example.com --mode explore --model claude --headless --output report.json ``` ## 配置文件格式 ### 基本配置 ```json { "name": "测试名称", "url": "https://example.com", "mode": "explore", // explore, goal, hybrid "model": "claude", // claude, openai, glm, mimo "headless": true } ``` ### 登录配置 ```json { "login": { "url": "https://example.com/login", "username": "user@example.com", "password": "password", "username_field": "email", "password_field": "password", "submit_button": "登录" } } ``` ### 探索配置 ```json { "explore_config": { "max_depth": 20, "max_clicks": 100, "focus_patterns": ["管理", "设置", "新增"], "dangerous_patterns": ["删除", "退出", "注销"] } } ``` ### 混合模式步骤 ```json { "mode": "hybrid", "steps": [ {"action": "goal", "goal": "点击登录按钮"}, {"action": "wait", "duration": 2000}, {"action": "explore", "config": {"max_clicks": 10}}, {"action": "verify", "target": "显示登录成功"} ] } ``` ### 验证规则 ```json { "verifications": [ {"type": "url_contains", "value": "/dashboard"}, {"type": "element_exists", "value": ".user-profile"}, {"type": "text_contains", "value": "欢迎"} ] } ``` ## 测试模式说明 ### 1. Explore 模式(探索模式) - AI 自动探索页面功能 - 发现可交互元素 - 适合了解新网站 ### 2. Goal 模式(目标模式) - 执行特定目标 - 适合单一任务测试 ### 3. Hybrid 模式(混合模式) - 结合目标导向和智能探索 - 支持多步骤业务流程测试 ## 实际使用示例 ### 测试 GitHub ```bash # 快速测试 python tests/quick_test.py https://github.com --headless # 使用配置文件 python tests/universal_tester.py --config tests/configs/github_example.json ``` ### 测试企业系统 ```yaml # enterprise_system.yaml name: 企业系统测试 url: "https://your-system.com" mode: hybrid login: username: "test@company.com" password: "password" steps: - action: goal goal: "点击登录按钮" - action: explore config: max_clicks: 20 ``` ```bash python tests/universal_tester.py --config enterprise_system.yaml ``` ## 报告输出 测试完成后会生成详细的测试报告,包括: - 测试步骤 - 发现的元素 - 错误信息 - 验证结果 ## 注意事项 1. **登录信息**:不要在配置文件中硬编码敏感信息,建议使用命令行参数或环境变量 2. **网站兼容性**:不同网站可能需要调整定位策略 3. **测试频率**:避免过于频繁的测试,以免被网站封禁 4. **法律合规**:确保你有权限测试目标网站 ## 扩展开发 如需添加自定义功能,可以: 1. 继承 `UniversalWebTester` 类 2. 添加新的验证类型 3. 扩展配置选项 4. 自定义报告格式