自然语言测试自动化框架

一个面向银行应用的企业级自然语言测试自动化框架,支持API和Web UI测试,并能在步骤间无缝共享变量。

  • by ravikaanthe
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 ravikaanthe/MCP-AutomationFramework-Syn

使用说明

自然语言测试自动化框架

剧作家MCP+GitHub Copilot+TypeScript用于银行应用程序

这是一个 基于企业级自然语言的测试自动化框架 专为银行应用而设计。它支持两者 API和Web UI测试 在步骤之间无缝共享变量。


🎯 快速链接


🚀 是什么让这个框架与众不同?

1. 自然语言提示

用简单的英语编写测试-不需要编程!

### Step 1: Login via API
- Endpoint: https://api.bank.com/login/user/pass
- Store customerId → **customerId**

### Step 2: Create Account via API
- Endpoint: https://api.bank.com/accounts?id={{customerId}}
- Store accountId → **newAccountId**

### Step 3: Verify in UI
- Navigate to: https://bank.com
- Check if **newAccountId** is displayed

2. API+UI混合测试

API和具有共享变量的Web自动化的单一测试框架。

3. 企业就绪

  • TypeScript用于类型安全
  • 实现强大自动化的剧作家
  • 带屏幕截图的HTML报告
  • 模块化架构

📁 项目结构

Framework/
├── src/                          ← Framework core
│   ├── core/
│   │   ├── TestContext.ts       ← Global variable storage
│   │   └── PromptExecutor.ts    ← Natural language parser
│   ├── helpers/
│   │   ├── ApiHelper.ts         ← API automation
│   │   └── UiHelper.ts          ← UI automation
│   └── fixtures/
│       └── test-fixtures.ts     ← Playwright fixtures
│
├── prompts/                      ← Natural language test prompts
│   ├── AccountManagement/
│   ├── TransactionManagement/
│   ├── CustomerManagement/
│   ├── LoanManagement/
│   ├── PaymentManagement/
│   └── SecurityAndAuth/
│
├── tests/                        ← Generated test scripts
│   ├── account-management/
│   ├── transaction-management/
│   └── parabank-e2e-generated.spec.ts
│
├── config/                       ← Environment configurations
├── test-data/                    ← Test data files
└── playwright-report/            ← HTML reports

Documentation Files:
├── FRAMEWORK-README.md           ← Complete framework guide
├── ARCHITECTURE.md               ← Technical architecture
├── QUICK-START.md                ← 5-minute setup
├── PROMPT-STORAGE-STRUCTURE.md   ← Prompt organization
├── LEADERSHIP-SUMMARY.md         ← Executive summary
└── README.md                     ← This file

⚡ 快速入门(5分钟)

步骤1:安装依赖项

npm install

步骤2:运行示例测试

npm run test:parabank

步骤3:查看报告

npm run report

就是这样! 您刚刚运行了一个端到端的银行测试,该测试:

  • 通过API登录
  • 通过API创建帐户
  • 已在web UI中验证帐户

📝 创建您的第一个测试

1.编写自然语言提示

创建: prompts/AccountManagement/my-test.prompt

# Title: My First Banking Test

### Step 1: Login via API
- HTTP Method: GET
- Endpoint: https://parabank.parasoft.com/parabank/services/bank/login/FicusRoot/katalon
- Store customerId → **customerId**

### Step 2: Verify in UI
- Open URL: https://parabank.parasoft.com/parabank/index.htm
- Username: FicusRoot
- Password: katalon
- Check if "Account Overview" is displayed

2.创建测试文件

创建: tests/account-management/my-test.spec.ts

import { test } from '../../src/fixtures/test-fixtures';
import { PromptExecutor } from '../../src/core/PromptExecutor';

test('My first test', async ({ page, apiHelper }) => {
  const executor = new PromptExecutor(apiHelper, page);
  await executor.loadPrompt('prompts/AccountManagement/my-test.prompt');
  await executor.execute();
});

3.运行测试

npx playwright test tests/account-management/my-test.spec.ts --headed

完整的文件:参见 快速启动.md


📊 框架功能

✅ 核心能力

  • ✅ 自然语言测试创建
  • ✅ API自动化(REST、SOAP、XML、JSON)
  • ✅ Web UI自动化
  • ✅ API和UI之间的变量共享
  • ✅ 全局状态管理(TestContext)
  • ✅ 带屏幕截图的HTML报告
  • ✅ TypeScript用于类型安全
  • ✅ 模块化架构

✅ 支持的银行模块

  • ✅ 账户管理
  • ✅ 事务管理
  • ✅ 客户管理
  • ✅ 贷款管理
  • ✅ 支付管理
  • ✅ 安全和身份验证

✅ 包括示例测试场景

  • ✅ 通过API创建帐户→ 在UI中验证
  • ✅ API资金转账→ 在UI中验证
  • ✅ 客户资料更新
  • ✅ 贷款申请
  • ✅ 账单支付
  • ✅ 登录认证

🎯 用例

该框架非常适合:

  1. 端到端银行工作流程

    • 帐户创建→ 交易→ 验证
  2. API-带有UI验证的首次测试

    • 通过API创建→ 在UI中验证
  3. 回归测试

    • 用于CI/CD的自动化测试套件
  4. 冒烟测试

    • 快速验证关键流量
  5. 集成测试

    • API+数据库+UI在一个测试中

🎓 文档

文档 目的 受众
快速启动.md 5分钟后开始 每个人
框架评审.md 完整的框架指南 QA工程师
建筑.md 技术细节 开发者
PROMPT-STORAGE-STRUCTURE.md 快速组织 测试创建者
PROMPT-ORGANIZATION-GUIDE.md 如何撰写提示 业务分析师
领导力-SUMMARY.md 执行概述 管理

🛠️ 框架组件

TestContext(全局变量)

import { testContext } from './src/core/TestContext';

testContext.set('customerId', '12345');
const id = testContext.get('customerId');

ApiHelper(API操作)

import { ApiHelper } from './src/helpers/ApiHelper';

const api = new ApiHelper();
await api.init('https://api.bank.com');
const result = await api.get('/accounts');

UiHelper(Web自动化)

import { UiHelper } from './src/helpers/UiHelper';

const ui = new UiHelper(page);
await ui.navigateTo('https://bank.com');
await ui.fill('input[name="username"]', 'user');
await ui.clickButton('Submit');

🎬 运行测试

运行特定测试

# Parabank E2E test
npm run test:parabank

# Prompt-driven test
npm run test:parabank-prompt

# All E2E tests
npm run test:e2e

# All API tests
npm run test:api

# Specific test file
npm test -- tests/parabank-e2e-generated.spec.ts --headed

使用选项运行

# Headed mode (see browser)
npx playwright test --headed

# Debug mode
npx playwright test --debug

# UI mode (interactive)
npx playwright test --ui

# Specific browser
npx playwright test --project=chromium

查看报告

# Open HTML report
npm run report

# Or directly
npx playwright show-report

📦 安装和设置

先决条件

  • Node.js 16+
  • npm或纱线

安装

npm install

安装Playwright浏览器

npx playwright install

🎓 示例:完成E2E测试

场景:通过API创建帐户,在UI中验证

提示文件: prompts/AccountManagement/create-checking-account-e2e.prompt

测试文件: tests/account-management/create-checking-account-e2e.spec.ts

跑:

npx playwright test tests/account-management/create-checking-account-e2e.spec.ts --headed

结果:显示所有步骤和证据的HTML报告


📈 益处

领导力

  • ✅ 测试创建速度提高70%
  • ✅ 降低质量保证成本
  • ✅ 早期错误检测
  • ✅ 自动化的投资回报率更高

QA团队

  • ✅ 无需编程
  • ✅ 易于测试维护
  • ✅ 全面覆盖
  • ✅ 更好的协作

对于开发者

  • ✅ API测试自动化
  • ✅ 清晰的测试场景
  • ✅ 早期反馈
  • ✅ 减少生产错误

🔐 提示文件存储

位置: C:\Playwright Automation Projects\Playwright MCP_Script & API\prompts\

按银行模块组织:

  • AccountManagement/ -账户操作
  • TransactionManagement/ -交易记录
  • CustomerManagement/ -客户运营
  • LoanManagement/ -贷款业务
  • PaymentManagement/ -付款
  • SecurityAndAuth/ -身份验证

看: PROMPT-STORAGE-STRUCTURE.md 有关完整详细信息


🎯 后续步骤

  1. ✅ 审查 快速启动.md
  2. ✅ 运行示例测试: npm run test:parabank
  3. ✅ 查看中的示例提示 prompts/ 文件夹
  4. ✅ 创建自己的提示文件
  5. ✅ 执行并迭代!

👥 团队协作

  • 业务分析师:在中编写测试场景 prompts/ 文件夹
  • QA工程师:执行测试,审查报告
  • 开发者:增强框架,添加功能
  • 开发运维:集成到CI/CD管道中

🏆 为什么是这个框架?

功能 传统 此框架
测试创建 4-8小时 30-60分钟
所需技能 编程 自然语言
API+UI 独立工具 单一框架
维护 高 低
协作 有限 高

📞 支持和文档

需要帮助?

  1. 检查 快速启动.md 用于设置
  2. 阅读 框架评审.md 详情
  3. 查看中的示例提示 prompts/ 文件夹
  4. 检查 建筑.md 获取技术信息

领导力:


📄 许可证

此项目是贵组织的专有项目。


✨ 框架状态

版本: 1.0.0
状态: ✅ 生产就绪
最后更新:2025年11月
测试覆盖率:银行业E2E工作流程


准备彻底改变您的银行测试自动化! 🚀


附加文档(以前的功能)

该项目为运行Playwright测试提供了一个全面的解决方案,正确处理包含空格和特殊字符的工作区文件夹名称。

快速开始

运行测试

使用NPM脚本

在模块中运行所有测试:

npm run test:account-management         # All account tests (headed)
npm run test:transaction-management     # All transaction tests (headed)
npm run test:customer-management        # All customer tests (headed)
npm run test:loan-management            # All loan tests (headed)
npm run test:payment-management         # All payment tests (headed)
npm run test:security-and-auth          # All auth tests (headed)
npm run test:all-modules                # All tests (headed)

使用特定模式运行测试:

npm run test:selfhealing               # All self-healing tests (headed)
npm test -- --headed --grep "login"    # Tests matching "login" pattern
npm test -- --headed --grep "api"      # Tests matching "api" pattern

运行所有测试:

npm run test                           # Run all tests (headless)
npm run test:headed                    # Run all tests (headed mode)
npm run test:ui                        # Run in UI mode (interactive)
npm run test:debug                     # Run in debug mode

运行单独测试(工作区特定限制):

⚠️ 重要: 由于工作空间文件夹名称包含空格和特殊字符, 直接文件路径模式不能可靠地工作。

❌ 这些将失败:

npm test tests/account-management/my-test.spec.ts
npm test -- tests/account-management/my-test.spec.ts --headed
npx playwright test tests/account-management/my-test.spec.ts

✅ 运行单个测试的推荐方法:

选项1:VS代码测试浏览器(最简单)

  • 打开测试面板(侧边栏中的烧杯图标)
  • 在树上找到你的测试
  • 点击播放按钮▶️ 在旁边

选项2:使用 .only 修饰符 添加 .only 到文件中的测试:

test.only('My specific test', async ({ ... }) => {
  // Only this test will run
});

然后运行该模块:

npm run test:account-management

选项3:使用具有唯一名称的Grep

npm test -- --headed --grep "unique-test-name-here"

选项4:与Workers一起运行=1 使用一个worker在文件夹中运行所有测试:

node node_modules/@playwright/test/cli.js test tests/account-management --headed --workers=1

查看报告:

npm run report                         # Show the HTML report

使用批处理文件(Windows)

# Run all tests in a module
./playwright-test.bat tests/account-management --headed

# Run with one worker
./playwright-test.bat tests/account-management --headed --workers=1

# Run self-healing tests
./playwright-test.bat --grep selfhealing --headed

# Show HTML report
./playwright-report.bat

测试示例

运行特定测试

运行生成的API-to-UI测试:

# Normal mode
npm run test:file tests/create-contact-api-to-ui-generated.spec.ts

# Headed mode (visible browser)
npm run test:file:headed tests/create-contact-api-to-ui-generated.spec.ts

# With HTML report
npm run test:file:reporter tests/create-contact-api-to-ui-generated.spec.ts

# Using batch file (alternative)
./playwright-test.bat tests/create-contact-api-to-ui-generated.spec.ts --headed

运行任何其他测试:

# Run login test
npm run test:file:headed tests/login-datadriven-generated.spec.ts

# Run admin module test
npm run test:file tests/admin-module-access.spec.ts

# Run buzz post verification
npm run test:file:reporter tests/buzz-post-verification.spec.ts

运行多个测试

# Run all API tests
./playwright-test.bat tests/api*.spec.ts

# Run all login tests
./playwright-test.bat tests/login*.spec.ts --headed

# Run all tests with HTML report
npm run test:reporter

查看报告

HTML报告

# Generate and view HTML report
npm run test:reporter && npm run report

# Or using batch files
./playwright-test.bat --reporter=html
./playwright-report.bat

HTML报告将在默认浏览器中自动打开,并显示:

  • 测试执行总结
  • 每个测试的通过/失败状态
  • 故障截图和视频
  • 测试执行时间表
  • 详细的错误消息

控制台输出

所有npm脚本和批处理文件都提供了详细的控制台输出,显示:

  • 测试执行进度
  • API调用结果
  • UI交互步骤
  • 通过/失败状态
  • 执行时间

故障排除

NPX命令问题

如果您遇到以下错误:

'API\node_modules\.bin\' is not recognized as an internal or external command

这是由于文件夹路径中有空格。使用提供的解决方案:

  1. NPM脚本:使用 npm run test 而不是 npx playwright test
  2. 批处理文件:使用 ./playwright-test.bat 而不是 npx playwright test
  3. 直接节点:使用 node node_modules/@playwright/test/cli.js test

常用命令

# If npx fails, use these alternatives:
npm run test                    # instead of: npx playwright test
npm run test:headed            # instead of: npx playwright test --headed  
npm run report                 # instead of: npx playwright show-report
./playwright-test.bat          # batch file alternative

项目结构

├── tests/                     # Test files
│   ├── *.spec.ts             # Generated and manual test files
├── prompts/                   # Prompt files for test generation
├── playwright-report/         # HTML reports (auto-generated)
├── test-results/             # Screenshots, videos, traces
├── playwright-test.bat       # Generic test runner script
├── playwright-report.bat     # Report viewer script
├── package.json              # NPM scripts and dependencies
└── playwright.config.ts      # Playwright configuration

提示

  • 始终使用 npm run test:reporter 当您想要生成HTML报告时
  • 使用 --headed 标记以直观地查看浏览器交互
  • 使用 --debug 标记以交互方式逐步执行测试
  • 检查 playwright-report/index.html 查看详细的测试结果
  • 批处理文件处理所有命令行参数,因此您可以传递任何Playwright CLI选项