🤖 AI测试浏览器
使用Claude AI+MCP自动生成真实页面扫描的PlayWright测试
智能系统,自动扫描网页,提取真实的选择器,并使用内置的自动修复生成PlayWright测试。它包括对受保护页面的认证扫描和交互式对话模式。
  
______________________________________________________________________
✨ 特点
🔍 实际页面扫描
- 使用PlayWright浏览网页
- 其他元素交互(输入、按钮、选择、链接)
- 标识ID、名称、类型和属性 真实的
- 没有猜测-仅验证选择器
🔐 验证扫描
- 浏览需要登录的页面
- 配置凭据
auth.yaml - 站点自动检测
- 支持多个应用程序
🤖 智能发电
- 克劳德分析页面结构
- 使用选择器生成测试 从一开始就正确
- 自动模式: 完整的2-5测试套件
- 互动模式: 与克劳德讨论测试什么
- 带有类型提示和文档的干净代码
🔧 自动修复
- 检测选择器何时更改
- 自动重新扫描页面
- 使用新的选择器更新测试
- 在修改之前创建备份
- 预览更改
--dry-run
💻 CLI专业
- 8个直观命令
- 更改预览(-dry-run)
- 多URL的批处理
- 智能处理重复文件
- 交互元素验证
______________________________________________________________________
🚀 安装
要求
- Python 3.11+
- 人类账户(API密钥)
设置
# Clonar repositorio
git clone https://github.com/TU_USUARIO/ai-test-explorer.git
cd ai-test-explorer
# Crear entorno virtual
python3 -m venv venv
source venv/bin/activate # En Windows: venv\Scripts\activate
# Instalar dependencias
pip install -r requirements.txt
# Instalar navegadores de Playwright
python -m playwright install
# Configurar API Key
echo "ANTHROPIC_API_KEY=tu_api_key_aqui" > .env______________________________________________________________________
📖 使用
🎮 可用命令
python cli.py --help
Commands:
explore 🔍 Explora una página web
explore-auth 🔐 Explora página con autenticación
generate 🤖 Genera test básico
generate-auth 🤖🔐 Genera test con autenticación
batch 📦 Genera múltiples tests
heal 🔧 Repara test roto (auto-healing)
list 📋 Lista tests generados
run ▶️ Ejecuta tests______________________________________________________________________
1️⃣ 浏览页面
基本探索(公共页面)
# Exploración simple
python cli.py explore https://www.saucedemo.com
# Con detalles de elementos
python cli.py explore https://www.saucedemo.com --show-details退出:
📦 Elementos encontrados:
• 2 inputs
• 1 botones
• 5 links
🔹 INPUTS:
1. type=text, id=user-name, name=user-name
2. type=password, id=password, name=password______________________________________________________________________
带身份验证的扫描(受保护的页面) 🔐
对于需要登录的页面:
帕索1: 在中配置凭据 auth.yaml
mi-app:
login_url: https://mi-app.com/login
username: testuser
password: testpass
username_selector: "#email"
password_selector: "#password"
submit_selector: "button[type='submit']"帕索2: 浏览经过验证的页面
python cli.py explore-auth https://mi-app.com/dashboard -s mi-app它是做什么的:
1. ✅ Navega a login
2. ✅ Ingresa credenciales automáticamente
3. ✅ Hace login
4. ✅ Navega a la página objetivo
5. ✅ Explora elementos del dashboard (NO del login)______________________________________________________________________
二️⃣ 生成测试
基本测试
# Suite completa (2-5 tests automáticos)
python cli.py generate https://www.saucedemo.com
# Test específico con descripción
python cli.py generate https://www.saucedemo.com \
--description "login con credenciales válidas"
# Personalizar salida
python cli.py generate https://www.saucedemo.com \
--output tests \
--filename test_custom.py结果:
import pytest
from playwright.async_api import Page
@pytest.mark.asyncio
async def test_login(page: Page):
'''Test de login con credenciales válidas'''
await page.goto("https://www.saucedemo.com")
# Selectores REALES extraídos de la página
await page.fill("#user-name", "standard_user")
await page.fill("#password", "secret_sauce")
await page.click("#login-button")
await page.wait_for_url("**/inventory.html")
assert "inventory.html" in page.url______________________________________________________________________
认证测试 🔐
对于需要登录的页面(仪表板、个人资料等):
自动模式:
python cli.py generate-auth https://mi-app.com/dashboard -s mi-app克劳德:
- 自动登录
- Explora el仪表板
- 确定主要行动
- 2-4次流量一致性测试
______________________________________________________________________
互动模式(与克劳德对话):
python cli.py generate-auth https://mi-app.com/dashboard -s mi-app --interactive对话:
💬 MODO INTERACTIVO
Elementos encontrados en la página:
• 3 inputs
• 5 botones
Botones principales:
1. Exportar Reporte
2. Crear Nuevo
3. Filtrar Datos
💡 ¿Qué quieres testear? (describe en una frase)
Tú: exportar reporte con fechas personalizadas
🤖 Generando test específico...
✅ Test generado生成的测试包括:
@pytest.mark.asyncio
async def test_exportar_reporte_fechas_personalizadas(page: Page):
# PASO 1: Login
await page.goto("https://mi-app.com/login")
await page.fill("#email", "testuser")
await page.fill("#password", "testpass")
await page.click("button[type='submit']")
# PASO 2: Navegar a dashboard
await page.goto("https://mi-app.com/dashboard")
# PASO 3: Exportar reporte
await page.fill("#fecha-inicio", "2024-01-01")
await page.fill("#fecha-fin", "2024-12-31")
await page.click("#exportar-btn")
# PASO 4: Verificar descarga
# ... verificaciones ...______________________________________________________________________
智能文件管理:
如果文件已经存在,系统会询问:
⚠️ El archivo test_dashboard_auth.py ya existe
¿Qué quieres hacer?
1. Sobrescribir (se creará backup: test_dashboard_auth.py.backup)
2. Crear nuevo (test_dashboard_auth_2.py)
3. Cancelar
Opción [1/2/3]:______________________________________________________________________
3.️⃣ 批处理
为多个URL生成测试:
# Crear archivo de URLs
cat > urls.txt > auth.yaml -s --interactive
2. Conversar con Claude sobre qué testear
3. Ejecutar
Tiempo por test: 2-5 minutos
Tasa de error: ~5% (selectores verificados)
Auto-healing: Sí
Páginas con login: Manejo automático节省:80-90%的时间\ 精度提高:75%\ 认证支持:✅
______________________________________________________________________
🛠️ 技术
______________________________________________________________________
📁 项目结构
ai-test-explorer/
├── cli.py # CLI principal (8 comandos)
├── src/
│ ├── ai_test_generator.py # Generador de tests
│ ├── auto_healer.py # Sistema de auto-reparación
│ ├── auth_config.py # Manejo de autenticación
│ └── __init__.py
├── tests/
│ ├── conftest.py # Fixtures compartidas
│ └── test_*.py # Tests generados
├── auth.yaml # Credenciales (no subir a Git)
├── screenshots/ # Screenshots de tests
├── pytest.ini # Configuración de Pytest
├── requirements.txt
├── LICENSE
├── EXAMPLES.md # Ejemplos detallados
└── README.md______________________________________________________________________
⚙️ 配置
auth.yaml
配置认证扫描的凭据:
saucedemo:
login_url: https://www.saucedemo.com
username: standard_user
password: secret_sauce
username_selector: "#user-name"
password_selector: "#password"
submit_selector: "#login-button"
mi-app:
login_url: https://mi-app.com/login
username: admin
password: admin123
username_selector: "#email"
password_selector: "#pwd"
submit_selector: "button[type='submit']"⚠️ 重要提示: 添加 auth.yaml 一 .gitignore 为了不上传凭据。
______________________________________________________________________
pytest.ini
[pytest]
asyncio_mode = auto
pythonpath = .
testpaths = tests______________________________________________________________________
conftest.py
PlayWright Global Fixtures在所有测试中都自动可用。
______________________________________________________________________
📄 许可证
MIT许可证-ve 许可证 更多细节
______________________________________________________________________
👤 作者
布莱恩·罗德里格斯
- 领英: 布莱恩·罗德里格斯-32a9a8211
- github: 布莱恩0422
______________________________________________________________________
⭐ 明星历史
如果这个项目对你有帮助,考虑给他一颗星⭐
______________________________________________________________________
Hecho con ❤️ y ☕ por Bryan Rodriguez
