mcpField
T
test-automation-framework

test-automation-framework

github.com/aj-geddes测试与质量373501 次安装34 周前更新
代码仓库

关于 test-automation-framework

用于构建易维护自动化测试套件的技能,提供可复用工具、测试数据、配置和报告方面的指南,涉及 TypeScript 的 Playwright 及 Python 的 pytest。

主要功能

  1. 01可复用测试工具
  2. 02测试夹具与工厂
  3. 03多环境配置
  4. 04清晰易读的测试报告
  5. 05Page Object Model 指南
  6. 06测试组织模式

适用场景

  1. 01搭建新的自动化测试套件
  2. 02扩展现有测试套件
  3. 03统一团队测试规范
  4. 04减少重复的测试配置

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill test-automation-framework

安装后在 Claude Code 中输入/test-automation-framework确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
configuration-management.md
custom-reporter.md
custom-test-utilities.md
page-object-model-playwrighttypescript.md
pytest-framework-python.md
test-fixtures-and-factories.md
test-organization.md
scripts/
scaffold-tests.sh
templates/
test-template.js

详细介绍

测试自动化框架

目录

概述

测试自动化框架为自动化测试提供结构、可复用性和可维护性。它定义了组织测试、管理测试数据、处理依赖项和生成报告的模式。设计良好的框架可以减少重复、提高可靠性并加快测试开发。

适用场景

  • 搭建新的测试自动化
  • 扩展现有测试套件
  • 在团队间统一测试实践
  • 减轻测试维护负担
  • 提高测试的可靠性和速度
  • 组织大型测试代码库
  • 实现可复用的测试实用工具
  • 生成一致的报告

快速开始

最小可运行示例:

// framework/pages/BasePage.ts
import { Page, Locator } from "@playwright/test";

export abstract class BasePage {
  constructor(protected page: Page) {}

  async goto(path: string) {
    await this.page.goto(path);
  }

  async waitForPageLoad() {
    await this.page.waitForLoadState("networkidle");
  }

  async takeScreenshot(name: string) {
    await this.page.screenshot({ path: `screenshots/${name}.png` });
  }

  protected async clickAndWait(locator: Locator) {
    await Promise.all([
      this.page.waitForResponse((resp) => resp.status() === 200),
      locator.click(),
    ]);
  }
}
// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
页面对象模型(Playwright/TypeScript)页面对象模型(Playwright/TypeScript)
测试夹具和工厂测试夹具和工厂
自定义测试实用工具自定义测试实用工具
配置管理配置管理
自定义报告器自定义报告器
pytest 框架(Python)pytest 框架(Python)
测试组织测试组织

最佳实践

✅ 应该做
  • 对 UI 测试使用页面对象模型
  • 创建可复用的测试实用工具
  • 实施恰当的等待策略
  • 使用夹具管理测试数据
  • 配置多个环境
  • 生成易读的测试报告
  • 按功能/类型组织测试
  • 对测试框架进行版本控制
❌ 不应该做
  • 将测试逻辑放入页面对象
  • 使用硬编码等待(sleep)
  • 重复测试设置代码
  • 混合测试数据与测试逻辑
  • 跳过错误处理
  • 忽略测试的不稳定性
  • 创建过于复杂的抽象
  • 硬编码环境 URL

评论

支持 Markdown