Files
empty 1f1cc4db9a
Some checks failed
AI Web Tester CI / test (push) Has been cancelled
feat: 增强测试框架功能
主要改进:
- 新增统一测试器 (universal_tester.py) 支持多种测试模式
- 优化测试报告生成器,支持汇总报告和操作截图
- 增强探索器 DFS 算法和状态指纹识别
- 新增智能测试配置 (smart_test.yaml)
- 改进 AI 模型集成 (GLM/Gemini 支持)
- 添加开发调试工具和文档
2026-01-05 20:23:02 +08:00
..
2026-01-05 20:23:02 +08:00
2026-01-05 20:23:02 +08:00
2026-01-05 20:23:02 +08:00
2026-01-05 20:23:02 +08:00
2026-01-05 20:23:02 +08:00
2026-01-05 20:23:02 +08:00

通用 Web 测试框架使用指南

概述

这个通用测试框架可以测试任意网站,不再局限于特定系统。支持多种测试模式和配置方式。

快速开始

1. 最简单的使用方式

# 测试任意网站(默认使用 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 配置示例

# 使用 JSON 配置文件
python tests/universal_tester.py --config tests/configs/github_example.json

YAML 配置示例

# 使用 YAML 配置文件
python tests/universal_tester.py --config tests/configs/enterprise_system.yaml

3. 命令行参数

python tests/universal_tester.py --url https://example.com --mode explore --model claude --headless --output report.json

配置文件格式

基本配置

{
  "name": "测试名称",
  "url": "https://example.com",
  "mode": "explore",  // explore, goal, hybrid
  "model": "claude",  // claude, openai, glm, mimo
  "headless": true
}

登录配置

{
  "login": {
    "url": "https://example.com/login",
    "username": "user@example.com",
    "password": "password",
    "username_field": "email",
    "password_field": "password",
    "submit_button": "登录"
  }
}

探索配置

{
  "explore_config": {
    "max_depth": 20,
    "max_clicks": 100,
    "focus_patterns": ["管理", "设置", "新增"],
    "dangerous_patterns": ["删除", "退出", "注销"]
  }
}

混合模式步骤

{
  "mode": "hybrid",
  "steps": [
    {"action": "goal", "goal": "点击登录按钮"},
    {"action": "wait", "duration": 2000},
    {"action": "explore", "config": {"max_clicks": 10}},
    {"action": "verify", "target": "显示登录成功"}
  ]
}

验证规则

{
  "verifications": [
    {"type": "url_contains", "value": "/dashboard"},
    {"type": "element_exists", "value": ".user-profile"},
    {"type": "text_contains", "value": "欢迎"}
  ]
}

测试模式说明

1. Explore 模式(探索模式)

  • AI 自动探索页面功能
  • 发现可交互元素
  • 适合了解新网站

2. Goal 模式(目标模式)

  • 执行特定目标
  • 适合单一任务测试

3. Hybrid 模式(混合模式)

  • 结合目标导向和智能探索
  • 支持多步骤业务流程测试

实际使用示例

测试 GitHub

# 快速测试
python tests/quick_test.py https://github.com --headless

# 使用配置文件
python tests/universal_tester.py --config tests/configs/github_example.json

测试企业系统

# 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
python tests/universal_tester.py --config enterprise_system.yaml

报告输出

测试完成后会生成详细的测试报告,包括:

  • 测试步骤
  • 发现的元素
  • 错误信息
  • 验证结果

注意事项

  1. 登录信息:不要在配置文件中硬编码敏感信息,建议使用命令行参数或环境变量
  2. 网站兼容性:不同网站可能需要调整定位策略
  3. 测试频率:避免过于频繁的测试,以免被网站封禁
  4. 法律合规:确保你有权限测试目标网站

扩展开发

如需添加自定义功能,可以:

  1. 继承 UniversalWebTester
  2. 添加新的验证类型
  3. 扩展配置选项
  4. 自定义报告格式