Skip to main content

ai-ui-testing

AI 驱动的 Web UI 自动化测试框架 —— 基于 Playwright + pytest 封装,用 AI 解决传统 UI 自动化两大痛点:定位器维护失败分析

特色

  • 开箱即用ai-ui init 生成骨架 → ai-ui run 跑用例 → 自动出 Allure 报告
  • AI 定位器:自然语言描述元素("登录按钮"),AI 生成并在真实页面校验的定位器
  • 定位器自动修复:元素找不到时 AI 分析页面快照自动修复,写入学习缓存,前端改版不再抓狂
  • AI 失败分析:失败自动采集截图 + DOM 快照 + traceback,AI 给出根因与修复建议
  • 自然语言用例生成:YAML 描述用例意图 → AI 生成可直接运行的 pytest 代码
  • Mock 降级模式:无 API Key 也能完整跑通、演示、写用例
  • 登录态复用:登录一次保存 cookies/localStorage,用例间复用,绕开 SSO/扫码/验证码
  • POM + 稳定性内置:页面对象模型、失败重试、trace 录制、失败产物归档
  • CI 友好:GitHub Actions 开箱即用

架构

┌─ CLI(ai-ui init/run/gen/analyze)
├─ pytest 插件(失败截图 / 重试 / AI 分析 / Allure 附加)
├─ 核心:Driver · BasePage · Element · Config
├─ AI:client(openai/ollama/mock)· snapshot · locator · repair · failure_analysis · test_gen
└─ 底座:Playwright(chromium/firefox/webkit) + LLM

快速开始

python -m venv .venv
# Windows: .venv\Scripts\activate   |   macOS/Linux: source .venv/bin/activate
pip install -e ".[allure]"
playwright install chromium
ai-ui run --provider mock        # 5 个示例用例全部通过,无需 API Key

Windows 可一键运行 scripts/run_tests.ps1,macOS/Linux 运行 scripts/run_tests.sh

文档(docs/)

文档 内容
docs/01-快速开始.md 安装、跑通示例、看报告、接入自家系统
docs/02-POM编写指南.md 页面对象模型编写规范、Element/BasePage API
docs/03-AI能力详解.md 定位器/自动修复/失败分析/用例生成的原理与用法
docs/04-CLI参考.md ai-ui 命令与环境变量
docs/05-配置参考.md config.yaml 全字段说明
docs/06-FAQ.md 常见问题与排查
docs/07-对话式开发.md 用自然语言对话开发用例:描述需求 → AI 编写 → 运行验证 → 迭代修复
docs/08-登录态复用.md 登录一次、用例复用 cookies/localStorage(绕开 SSO/扫码/验证码)
docs/09-CI持续集成.md GitHub Actions / Jenkins / 凭据管理 / 报告与排障
docs/10-自建CI指南.md 自建 CI 三种方案(cron/GitLab/Docker)、关键坑、框架配置
docs/11-分发与使用.md 打包 wheel / 私有源 / git 依赖、使用者流程、安全红线、版本管理

CLI 速查

命令 说明
ai-ui init [-f] 生成项目骨架
ai-ui run [--headed] [--browser X] [--provider X] [路径] 运行测试
ai-ui gen <规格.yaml> [-o 目录] 自然语言规格 → pytest 用例
ai-ui analyze --last 查看最近失败的 AI 分析

目录结构

ai-ui-testing/
├── config/config.yaml          # 全局配置(字段带注释)
├── docs/                       # 使用手册(上表 6 篇)
├── src/ai_ui_testing/          # 框架源码
│   ├── driver / base_page / element / config
│   ├── ai/                     # client / snapshot / locator / repair / analysis / test_gen
│   ├── pytest_plugin.py        # fixtures + 失败处理钩子
│   ├── cli.py                  # ai-ui 命令
│   └── templates/              # ai-ui init 骨架
├── tests/                      # 开箱示例(demo 页面 + POM + 用例)
├── samples/nl_tests/           # 自然语言用例规格示例
├── scripts/                    # 一键安装运行脚本
└── .github/workflows/ci.yml    # GitHub Actions

Roadmap

  • 并行执行(pytest-xdist)与 Allure 历史趋势
  • 连接外部浏览器实例复用登录态(CDP 协议 / ego-lite 等):用例直接跑在已登录会话上,绕开 SSO、扫码登录、验证码等登录前置成本(适合本地/冒烟;CI 仍需自行处理登录)
  • 截图对比(视觉回归)+ AI 差异分析
  • 页面对象类 AI 一键生成(输入 URL → 生成 POM)
  • 定位器学习缓存的版本管理(按 URL/提交关联)
  • 关键字驱动(YAML 用例直接执行,不写代码)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_ui_testing-0.1.0.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_ui_testing-0.1.0-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file ai_ui_testing-0.1.0.tar.gz.

File metadata

  • Download URL: ai_ui_testing-0.1.0.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for ai_ui_testing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca9c57e08efb9ad5438b2bc45a4445193a8010f65d90d09a45d37b81803d5017
MD5 a3492f326b5ca7a9516be8a15997304d
BLAKE2b-256 117a518073c5ee309127ad42e59662375b889767c60337c16cee69c0907f8274

See more details on using hashes here.

File details

Details for the file ai_ui_testing-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_ui_testing-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for ai_ui_testing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2769a78831d5d05374e357ad1f3d4e9d4562284c0b5c6e3ccff77c0e758a4b7e
MD5 e3987cb2c867a081b770dbc648ce5fd6
BLAKE2b-256 0d9f6c0f4a91ec3e0f6a5305f34cd8c644d18e537e1e474a3f67d0e60edaabe7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page