natebell510/BestTester

GitHub: natebell510/BestTester

一个集成 Playwright、TypeScript 与 AI 的端到端测试框架,通过 LLM 评判、MCP 与自动化代理提供从安全模糊测试到 CI/CD 的一站式质量保障。

Stars: 1 | Forks: 0

# BestTester [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Node](https://img.shields.io/badge/node-%3E%3D20.x-brightgreen)](https://nodejs.org) [![Playwright](https://img.shields.io/badge/playwright-latest-blue)](https://playwright.dev) [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6)](https://www.typescriptlang.org) [![AWS Bedrock](https://img.shields.io/badge/AWS_Bedrock-AI_Testing-FF9900)](https://aws.amazon.com/bedrock/) [![MCP](https://img.shields.io/badge/MCP-Model_Context_Protocol-purple)](https://modelcontextprotocol.io) ## 为什么选择 BestTester? | 优势 | 详情 | |---|---| | **零配置启动** | 克隆 → `npm ci` → `npm run test:smoke` — 开箱即用,内置 OrangeHRM 演示 | | **完整页面对象模型** | 每个页面继承 `BasePage`;测试文件中无内联选择器 | | **AI 原生测试** | LLM 驱动的断言、语义相似度、AI 定位器回退、幻觉检测 | | **LLM 作为裁判** | 多维度评分体系(相关性、准确性、一致性、安全性、忠实性),通过 AWS Bedrock 实现,启用抗自恋偏差双模型设计 | | **MCP 集成** | 模型上下文协议服务器(支持 stdio 与 SSE)让 AI 代理可导航、截图、运行测试并列出测试用例 | | **7 个 CLI 代理** | 代码审查、测试修复、建议生成、Jenkins 触发、Jira 同步、Slack 机器人、运行并报告 — 全部在终端完成 | | **安全测试** | SQLi/XSS 模糊测试器、安全头验证器、OWASP ZAP 代理集成 | | **多环境支持** | `TEST_ENV=dev|staging|prod`,支持每个环境独立的 `.env` 文件 | | **多浏览器支持** | Chromium、Firefox、WebKit、移动端 Chrome、移动端 Safari(通过 `ALL_BROWSERS=true`) | | **变异测试** | Stryker Mutator,支持可配置阈值与 HTML/JSON 报告 | | **完整 CI/CD** | 10 个 GitHub Actions 工作流:CI、夜间构建、冒烟测试、PR 门禁、安全扫描、变异测试、AI 测试、API 测试、报告发布、GitHub Copilot 审查 | | **Jenkins 流水线** | Jenkinsfile 包含 EC2 配置脚本、单测触发器、远程作业管理 | | **Jira 集成** | 自动创建/更新/关闭 Jira 缺陷,附加 JUnit XML 并关联测试执行与故事 | | **Slack 通知** | 实时构建结果、失败告警与报告链接推送到 Slack 频道 | | **Allure + HTML 报告** | 双重报告输出,Allure 自动发布至 GitHub Pages,Playwright HTML 报告 | | **数据工厂** | Faker 驱动的数据工厂,支持自动清理机制确保测试隔离 | | **文件操作** | 下载验证、Excel 读写、Word 文档生成、PDF 解析与内容断言 | | **国际化测试** | 语言切换器、RTL 检测,支持 `en`、`fr`、`ar`、`ja` 的字符串校验 | | **权限矩阵** | 多角色测试(管理员、经理、员工),支持缓存存储状态 | | **脚手架 CLI** | `scaffold:page`、`scaffold:test`、`scaffold:api` 生成器确保代码结构一致 | | **代码质量** | ESLint + Prettier + Husky 提交/推送前钩子 + lint-staged | | **类型安全** | 严格 TypeScript,配合 Zod 模式校验 API 响应 | ## 架构 ``` ┌──────────────────────────────────────────────────────────────────┐ │ BestTester │ ├──────────┬──────────┬──────────┬──────────┬──────────┬───────────┤ │ UI Tests │ API Tests│ AI Tests │ Security │ i18n │ File-Ops │ │(Playwright│(Axios/PW)│(Bedrock) │(ZAP/Fuzz)│(Locale) │(xlsx/pdf) │ ├──────────┴──────────┴──────────┴──────────┴──────────┴───────────┤ │ Page Object Model (src/pages/) │ API Layer (src/api/) │ │ AI Helpers (src/ai/) │ Security (src/security/) │ │ Fixtures (src/fixtures/) │ Data Factories (src/data/) │ │ Utils (src/utils/) │ i18n (src/i18n/) │ ├──────────────────────────────────────────────────────────────────┤ │ AI: LLM Client │ AI Assert │ Semantic Assert │ LLM Judge │ │ AI Locator │ Embeddings (Titan) │ MCP Server (stdio/SSE) │ ├──────────────────────────────────────────────────────────────────┤ │ Agents: Code Review │ Test Healer │ Suggestions │ Jenkins │ │ Jira Sync │ Slack Bot │ Run-and-Report │ ├──────────────────────────────────────────────────────────────────┤ │ CI/CD: GitHub Actions (10 workflows) │ Jenkins (EC2) │ │ Reports: Allure │ Playwright HTML │ Slack │ JUnit XML │ Jira │ └──────────────────────────────────────────────────────────────────┘ ``` ## 快速开始 ``` # 1. 克隆 git clone https://github.com/your-org/BestTester.git && cd BestTester # 2. 安装 npm ci # 3. 配置 cp .env.example .env # edit with your credentials — NEVER commit .env # 4. 安装浏览器 npm run setup # 5. 运行冒烟测试 npm run test:smoke ``` ## 目录结构 ``` BestTester/ ├── .github/workflows/ # 10 CI/CD pipelines (ci, nightly, smoke, pr-gate, security, mutation, ai, api, report, copilot-review) ├── agents/ # 7 AI CLI agents (review, heal, suggest, jenkins, jira-sync, slack-bot, run-and-report) ├── config/ # Playwright config, global-setup, per-environment .env files (dev/staging/prod) ├── mcp/ # MCP server (stdio + SSE) and AI test generator client ├── mutation/ # Stryker mutation testing config and HTML/JSON reports ├── scripts/ # Shell & TS utilities (Jenkins provisioning, Slack, scaffolding, EC2) ├── src/ │ ├── ai/ # LLM client (Bedrock), AI assertions, semantic assertions, AI locator │ │ └── judge/ # LLM-as-Judge: multi-rubric evaluation, safety checks, pairwise comparison │ ├── api/ # API client layer (BaseAPI + auth, employee, leave clients) │ ├── auth/ # Multi-role auth (Admin/Manager/Employee), storage state caching │ ├── components/ # Reusable UI components (form, modal, navbar, table) │ ├── constants/ # Shared constants │ ├── data/ # Test data factories (Faker) + teardown registry │ ├── fixtures/ # Custom Playwright fixtures (base, api, auth) │ ├── i18n/ # Locale switcher, RTL detection, string validator │ ├── pages/ # Page Object Model (login, dashboard, employee, leave, reports) │ ├── security/ # SQLi/XSS fuzzer, security header validator, OWASP ZAP client │ ├── types/ # TypeScript interfaces (API responses, config, employee, Jira) │ └── utils/ # Logger (Winston), Slack, Jenkins, Jira, file-handler, download-verifier, Excel, webhook ├── tests/ │ ├── ai/ # AI/LLM response validation and content tests │ ├── api/smoke/ # API smoke tests │ ├── api/regression/ # API regression tests with Zod schema validation │ ├── auth-matrix/ # Multi-role access control tests │ ├── file-ops/ # File download, Excel, Word, PDF tests │ ├── i18n/ # Internationalization smoke tests │ ├── security/ # Security header and penetration tests │ ├── ui/smoke/ # UI smoke suite (@smoke) │ ├── ui/regression/ # UI regression suite (@regression) │ ├── ui/e2e/ # End-to-end journeys (@e2e) │ └── ui/visual/ # Visual regression tests (@visual) ├── Jenkinsfile # Main Jenkins pipeline ├── Jenkinsfile.single-test # Single-test Jenkins pipeline └── README.md ``` ## 运行测试 ``` # 所有测试 npm test # 按类型 npm run test:ui # UI tests npm run test:api # API tests npm run test:ai # AI/LLM tests npm run test:file-ops # File operation tests npm run test:security # Security tests npm run test:i18n # Internationalization tests npm run test:auth-matrix # Multi-role auth tests # 按标签 npm run test:smoke # @smoke npm run test:regression # @regression npm run test:e2e # @e2e npm run test:visual # @visual # 调试模式 npm run test:headed # Headed browser npm run test:debug # Playwright inspector # 变异测试 npm run test:mutation # Stryker mutation analysis ``` ### 按环境运行 ``` TEST_ENV=dev npm test TEST_ENV=staging npm test TEST_ENV=prod npm test ``` ### 跨浏览器测试 ``` ALL_BROWSERS=true npm test # Chromium + Firefox + WebKit + mobile Chrome + mobile Safari ``` ## AI 驱动的测试 ### LLM 客户端(AWS Bedrock) 基于 AWS Bedrock Converse API 构建,默认使用 Amazon Nova Pro 模型。支持聊天、摘要与嵌入(Titan Embed v2)。 ### AI 断言 - **语义相似度** — 基于 Titan 嵌入的余弦相似度,带可配置阈值 - **幻觉检测** — 关键词级 grounding 检查 - **AI 定位器回退** — 将 DOM 快照发送给 LLM 以解析失效选择器 ### LLM 作为裁判 六维度评估体系: | 维度 | 用途 | 通过阈值 | |---|---|---| | Standard | 通用响应质量 | 3.5 | | RAG Faithfulness | 源文档 grounding | 4.0 | | Customer Support | 共情、准确、可行动 | 3.5 | | Code Generation | 正确性、安全性、结构 | 4.0 | | Summarization | 覆盖、简洁、忠实 | 3.5 | | Toxicity & Safety | 仇恨言论、PII、提示注入 | 4.5 | 六维度评分项:相关性、准确性、一致性、安全性、忠实性、指令遵循性。 **抗自恋偏差**:主模型(Nova Pro)与裁判模型(Claude Haiku)采用不同架构,防止自评估偏差。边界分数(2–3)触发自动严格重评。 ### 语义断言 API ``` import { semanticExpect } from '@ai/semantic-assert'; await semanticExpect(response).toBeRelevantTo(prompt); await semanticExpect(response).toBeGroundedIn(sourceContext); await semanticExpect(response).toBeSafe(); await semanticExpect(response).toNotHallucinate(knownFacts); await semanticExpect(response).toBeBetterThan(alternativeResponse); await semanticExpect(response).toHaveScore({ min: 4.0, rubric: RUBRICS.CODE_GENERATION }); ``` ## MCP 服务器 用于 AI 驱动测试编排的 Model Context Protocol 服务器,支持 stdio 与 SSE 传输。 ``` npm run mcp:server # stdio mode npm run mcp:server:sse # SSE mode on port 3001 npm run mcp:generate # AI test generator client ``` **可用的 MCP 工具:** | 工具 | 描述 | |---|---| | `navigate` | 打开 URL,返回标题与截图 | | `screenshot` | 全页截图 | | `get_page_text` | 提取可见文本 | | `run_test` | 执行指定测试文件 | | `list_tests` | 列出所有测试用例 | ## AI 代理 ### 代码审查代理 ``` npm run agent:review -- --file tests/ui/login.spec.ts npm run agent:review -- --file tests/ui/login.spec.ts --slack # post to Slack ``` ### 测试修复代理 自动检测失败测试中的失效定位器,并在新 Git 分支中提出 AI 修复建议。 ``` npm run agent:heal -- --test-result reports/playwright-report/results.json ``` ### 建议生成代理 分析页面对象与现有测试覆盖,生成 5–10 条新测试用例建议。 ``` npm run agent:suggest -- --page src/pages/employee.page.ts ``` ### Jenkins 触发代理 ``` npm run agent:jenkins -- --job playwright-tests --params ENV=staging npm run agent:jenkins -- --job playwright-tests --build 42 npm run agent:jenkins -- --job playwright-tests --build 42 --logs ``` ### Jira 同步代理 自动创建/更新/关闭 Jira 缺陷,附加 JUnit XML 并关联测试执行与故事。 ``` npm run agent:jira -- --build latest npm run agent:jira -- --junit reports/playwright-report/junit.xml --build 42 npm run agent:jira -- --junit reports/playwright-report/junit.xml --dry-run ``` ### 运行并报告代理 完整工作流:触发 Jenkins → 流式控制台 → 下载制品 → 同步 Jira → 通知 Slack。 ``` npm run agent:run-and-report npm run agent:run-and-report -- --suite smoke --jira-key SCRUM-5 npm run agent:run-and-report -- --suite regression --jira-key SCRUM-5 --dry-run ``` ### Slack 机器人代理 ``` npx ts-node agents/slack-bot-agent.ts --report reports/playwright-report/results.json ``` ## 安全测试 - **SQLi/XSS 模糊测试** — 使用常见注入载荷自动模糊表单,验证无 500 错误或反射型 XSS - **安全头验证器** — 校验 CSP、HSTS(≥1 年)、X-Frame-Options、X-Content-Type-Options、Referrer-Policy - **OWASP ZAP 集成** — 代理模式下的被动/主动扫描,支持蜘蛛与告警提取 ## CI/CD 流水线 | 工作流 | 触发条件 | 作用 | |---|---|---| | `ci.yml` | 推送 / PR | 代码检查 → 冒烟测试 → Playwright 报告 → Slack 通知 | | `nightly.yml` | 每日 02:00 UTC | 完整回归 → Allure 报告 → Slack 通知 → 失败时自动创建 GitHub Issue | | `smoke.yml` | 手动 / 可复用 | 仅运行冒烟套件 | | `pr-gate.yml` | 拉取请求 | 质量门禁检查 | | `api-tests.yml` | 手动 / 定时 | API 冒烟与回归 | | `ai-tests.yml` | 手动 / 定时 | AI / LLM 验证测试 | | `security-scan.yml` | 手动 / 定时 | 安全测试套件 | | `mutation.yml` | 手动 | Stryker 变异测试 | | `report.yml` | 夜间之后 | 发布 Allure 至 GitHub Pages | | `copilot-review.yml` | PR | AI 辅助代码审查 | ### - `Jenkinsfile` — 带参数化套件选择的完整流水线 - `Jenkinsfile.single-test` — 远程运行单个测试文件 - EC2 配置脚本用于 Jenkins 服务器搭建 - 远程作业创建与配置工具 ## 报告 ``` npm run report:allure # Generate + open Allure report npm run report:playwright # Open Playwright HTML report ``` 报告以 4 种格式生成:HTML、JSON、JUnit XML 与 Allure。Allure 在夜间运行后自动发布至 GitHub Pages。 ## 脚手架 ``` npm run scaffold:page -- --name MyFeature # → src/pages/my-feature.page.ts + test stub npm run scaffold:test -- --name my-feature # → tests/ui/regression/my-feature.spec.ts npm run scaffold:api -- --name my-resource # → src/api/my-resource.api.ts ``` ## 添加新的页面对象 ``` import { Page } from '@playwright/test'; import { BasePage } from './base.page'; export class MyFeaturePage extends BasePage { private readonly submitButton = this.page.getByRole('button', { name: 'Submit' }); constructor(page: Page) { super(page); } async goto(): Promise { await this.navigate('/my-feature'); } async submit(): Promise { await this.submitButton.click(); } } ``` 然后在 `src/fixtures/base.fixture.ts` 中注册。 ## 技术栈 | 类别 | 技术 | |---|---| | 测试框架 | Playwright、TypeScript | | AI/LLM | AWS Bedrock(Nova Pro、Claude Haiku、Titan 嵌入)、OpenAI | | MCP | @modelcontextprotocol/sdk(stdio + SSE) | | API 测试 | Axios、Zod 模式校验 | | 安全 | OWASP ZAP、自定义 SQLi/XSS 模糊器 | | 数据 | Faker.js、ExcelJS、pdf-parse、PDFKit、docx | | CI/CD | GitHub Actions、Jenkins | | 报告 | Allure、Playwright HTML、JUnit XML | | 集成 | Jira(REST API)、Slack(Webhooks + Web API)、GitHub API | | 代码质量 | ESLint、Prettier、Husky、lint-staged | | 变异测试 | Stryker Mutator | | 日志 | Winston | | 版本控制 | simple-git | ## 关键词 `playwright`, `typescript`, `test-automation`, `e2e-testing`, `api-testing`, `ai-testing`, `llm-testing`, `aws-bedrock`, `page-object-model`, `playwright-typescript`, `playwright-framework`, `playwright-boilerplate`, `playwright-template`, `test-framework`, `qa-automation`, `qe-framework`, `selenium-alternative`, `ui-testing`, `visual-regression`, `security-testing`, `owasp-zap`, `mutation-testing`, `stryker`, `allure-report`, `ci-cd`, `github-actions`, `jenkins`, `jira-integration`, `slack-bot`, `mcp`, `model-context-protocol`, `llm-as-judge`, `ai-assertions`, `semantic-testing`, `hallucination-detection`, `cross-browser-testing`, `i18n-testing`, `data-factory`, `test-data-management`, `download-verification`, `excel-testing`, `pdf-testing`, `playwright-best-practices`, `playwright-page-object`, `playwright-fixtures`, `playwright-ci-cd`, `playwright-ai`, `bedrock-testing`, `nova-pro`, `claude-haiku`, `titan-embeddings` ## 许可证 MIT MIT https://nodejs.org https://playwright.dev https://www.typescriptlang.org https://aws.amazon.com/bedrock/ https://modelcontextprotocol.io
标签:AI测试, AWS Bedrock, BestTester, Chrome移动版, Chromium, dev staging prod, .env, Firefox, GitHub Actions, GNU通用公共许可证, HTML报告, Jenkins触发, Jira同步, JSON报告, LLM-as-Judge, MCP, MITM代理, Model Context Protocol, Node >=20, Node.js, OWASP ZAP, Page Object Model, Playwright, Safari移动版, Slack通知, Stryker, TypeScript, WebKit, XSS, 代码审查, 变更测试, 多浏览器, 安全头验证, 安全扫描, 安全插件, 安全模糊测试, 建议生成, 开源测试框架, 插件即用, 时序注入, 测试修复, 漏洞情报, 特征检测, 环境配置, 移动测试, 突变测试, 端到端测试, 自动化攻击, 自动笔记, 运行并报告, 零配置