SuperAPI AI 工具集

webapp-testing

测试与质量

查看项目

更新于 10-16 05:46

技能介绍

用途:测试本地 Web 应用,通过编写原生 Python Playwright 脚本完成交互与验证,可验证前端功能、调试 UI 行为并截图。

主要能力与脚本:提供 scripts/with_server.py,用于管理服务器生命周期,支持同时管理多个服务器。使用脚本前应先运行 --help 查看用法,不要先读取源码。

选择方式:若目标是静态 HTML,可直接读取 HTML 文件识别选择器;失败或不完整时按动态应用处理。动态应用若服务器未运行,先执行 python scripts/with_server.py --help,再结合辅助脚本编写简化 Playwright 脚本;若服务器已在运行,采用“先侦察后操作”:导航并等待 networkidle、截图或检查 DOM、从渲染状态识别选择器、再执行操作。

用法示例:单服务器 python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py;多服务器可重复使用 --server 与 --port,如 --server "cd backend && python server.py" --port 3000 --server "cd frontend && npm run dev" --port 5173 -- python your_automation.py。自动化脚本只写 Playwright 逻辑,服务器由脚本自动管理。

最佳实践:使用 sync_playwright();headless 模式启动 chromium;完成后关闭浏览器;使用描述性选择器(text=、role=、CSS 选择器或 ID);使用 page.wait_for_selector() 或 page.wait_for_timeout() 等待;动态应用在检查 DOM 前务必等待 page.wait_for_load_state('networkidle')。参考文件包括 examples/ 下的 element_discovery.py、static_html_automation.py、console_logging.py。其它信息暂未提供。