MCP Test Case Generator
Generates structured, comprehensive test cases from user stories, API specs, or raw text, with automatic Excel export and Playwright automation code generation.
README
MCP Test Case Generator
MCP Server for generating structured, comprehensive test cases that QA teams can use immediately in TestRail, Jira, Xray, or other test management tools.
🎯 Mục tiêu
Tạo test case chuẩn, có cấu trúc, copy-paste là dùng được cho tester, không phải dạng mô tả chung chung.
✨ Đặc điểm nổi bật
🔧 Input chuẩn hóa
Chấp nhận 3 loại input và tự động chuẩn hóa:
-
User Story
"As a user I want to login so that I can access dashboard" -
API Spec
{ "endpoint": "/login", "method": "POST", "request": {"username": "string", "password": "string"} } -
Raw Text
"Login functionality with username and password validation"
📁 File Reading Capabilities (NEW!)
MCP server giờ có thể đọc trực tiếp từ local filesystem:
6 Tools Available:
generate_test_cases- Generate từ input text/objectread_requirement_file- Đọc file requirement từ localscan_requirement_directory- Quét thư mục tìm requirement filesgenerate_test_cases_from_file- Đọc file và generate test casesexport_to_excel- Export test cases sang file Excel (.xlsx)generate_automation_tests- Generate automation test code (Playwright) (NEW!)
Supported File Formats:
- Markdown (.md, .markdown)
- Text (.txt, .text)
- JSON (.json) - API specs, configurations
- YAML (.yml, .yaml) - Config files
- Word (.doc, .docx) - Requirement documents
- PDF (.pdf) - Requirement specifications
📋 Output JSON cố định
Mỗi test case có đủ các field bắt buộc:
{
"id": "TC_LOGIN_001",
"title": "Login with valid credentials",
"type": "positive",
"precondition": "User has valid account",
"steps": [
"Open login page",
"Enter valid username",
"Enter valid password",
"Click Login"
],
"expected_result": "User is redirected to dashboard",
"test_data": {"username": "valid_user", "password": "valid_pass"},
"priority": "High"
}
🎯 4 nhóm test bắt buộc
- Positive: Test happy path (tối thiểu 3 test cases)
- Negative: Test error handling (tối thiểu 3 test cases)
- Boundary: Test giới hạn (tối thiểu 3 test cases)
- Edge: Test trường hợp đặc biệt (tối thiểu 3 test cases)
🚀 Cài đặt
# Clone hoặc download project
cd mcp-test-case-generator
# Install dependencies
npm install
# Start server
npm start
📖 Cách sử dụng
1. Cấu hình MCP Client
Thêm vào MCP client config:
{
"mcpServers": {
"test-case-generator": {
"command": "node",
"args": ["path/to/mcp-test-case-generator/index.js"]
}
}
}
2. Sử dụng Tools
Method 1: Direct Input (Auto Excel Export - NEW DEFAULT!)
{
"input": "As a user I want to login so that I can access dashboard",
"auto_export_excel": true,
"excel_path": "./test-cases-auto.xlsx"
}
🎉 NEW DEFAULT: Auto Excel Export enabled! Test cases sẽ tự động được export sang Excel file.
Method 2: Read from File (NEW!)
{
"file_path": "requirements/login-user-story.md"
}
Method 3: Scan Directory (NEW!)
{
"directory_path": "./requirements",
"extensions": [".md", ".json", ".txt"]
}
Method 4: Generate from File (NEW!)
{
"file_path": "api-specs/login-api.json"
}
Method 5: Export to Excel (NEW!)
{
"test_cases": {
"positive": [...],
"negative": [...],
"boundary": [...],
"edge": [...]
},
"output_path": "./test-cases.xlsx"
}
Method 6: Generate Automation Tests (NEW!)
{
"test_cases": {
"positive": [...],
"negative": [...],
"boundary": [...],
"edge": [...]
},
"framework": "playwright",
"language": "javascript",
"base_url": "https://example.com"
}
3. Example Usage in Claude Desktop
"Read the login requirements file and generate test cases"
→ MCP sẽ tự động: scan → read → generate
"Scan my requirements directory and list all files"
→ MCP sẽ hiển thị danh sách file có thể xử lý
"Generate test cases from this API spec file: ./api/login.json"
→ MCP sẽ đọc file và generate test cases
"Export the generated test cases to Excel file"
→ MCP sẽ tạo file Excel với format chuẩn
"Generate test cases from requirements and export to Excel"
→ MCP sẽ generate và export trong 1 bước
"Generate test cases from this requirement"
→ MCP sẽ generate test cases VÀ tự động export Excel
"Generate test cases but disable Excel export"
→ MCP chỉ generate test cases, không export Excel
"Generate test cases and save to custom Excel path"
→ MCP sẽ generate và export đến file chỉ định
"Generate automation tests from the test cases"
→ MCP sẽ tạo Playwright test code sẵn sàng chạy
4. Output structure
{
"success": true,
"file_info": {
"path": "/path/to/file.md",
"type": "markdown",
"extension": ".md",
"size": 500
},
"input_type": "user_story",
"validation": {
"isValid": true,
"errors": []
},
"test_cases": {
"positive": [...],
"negative": [...],
"boundary": [...],
"edge": [...]
},
"summary": {
"total_cases": 12,
"by_section": {
"positive": 3,
"negative": 3,
"boundary": 3,
"edge": 3
}
}
}
🧠 QA Assumptions
Khi requirement không rõ ràng, server tự động áp dụng quy tắc QA chuẩn:
String fields
- Max length: 255 characters
- Min length: 1 character
- Invalid formats:
<script>, SQL injection, etc.
Number fields
- Min: 0
- Max: 999999
- Invalid: -1, 999999999
Required fields
- Test với null values
- Test với empty strings
- Test với missing fields
✅ Validation
Server tự động validate output:
- Đủ 4 nhóm test
- Mỗi nhóm có tối thiểu 3 test cases
- Đủ các field bắt buộc
- Steps không được trống
Nếu validation fail → server báo lỗi chi tiết.
🎯 Best Practices
Steps writing
- 1 step = 1 action cụ thể
- Dùng verb bắt đầu: "Enter", "Click", "Verify", "Navigate"
- Tránh từ mơ hồ: "successfully", "correctly", "as expected"
Expected Results
- 1 expected = 1 kết quả quan sát được
- Dùng measurable language: "User is redirected to", "Error message displays", "Status code is 200"
Test Data
- Cung cấp data cụ thể cho từng test case
- Boundary tests: min/max values
- Negative tests: invalid data types
🔄 Integration
TestRail
Copy-paste test case vào TestRail với format:
- Title:
test_case.title - Type:
test_case.type - Priority:
test_case.priority - Precondition:
test_case.precondition - Steps:
test_case.steps(mỗi step = 1 row) - Expected Result:
test_case.expected_result - Test Data:
test_case.test_data
Jira/Xray
Tương tự TestRail, có thể import qua CSV format.
📊 Excel Export (NEW!)
Export test cases sang file Excel với format chuẩn:
Excel Columns:
- Test Case ID: Unique identifier (TC_LOGIN_001)
- Title: Test case description
- Type: positive/negative/boundary/edge
- Priority: High/Medium/Low
- Precondition: Conditions before test
- Steps: Test steps (newline separated)
- Expected Result: Expected outcome
- Test Data: Test data in JSON format
- Section: Test case category
Features:
- Auto column widths cho readability
- Structured format ready for import
- All 4 test sections trong 1 sheet
- JSON test data preserved
- Professional formatting
🚀 Auto Excel Export (NEW DEFAULT!)
Tính năng mới: Tự động export Excel khi generate test cases!
Default Behavior
- Auto Export: ENABLED theo mặc định
- File Path:
./test-cases-auto.xlsx - Format: 9 columns với professional formatting
Usage Options
1. Auto Export (Default)
{
"input": "As a user I want to login",
// auto_export_excel: true (mặc định)
// excel_path: "./test-cases-auto.xlsx" (mặc định)
}
2. Disable Auto Export
{
"input": "As a user I want to login",
"auto_export_excel": false
}
3. Custom Excel Path
{
"input": "As a user I want to login",
"excel_path": "./custom-test-cases.xlsx"
}
Output Structure (Updated)
{
"success": true,
"input_type": "user_story",
"validation": { "isValid": true, "errors": [] },
"test_cases": { ... },
"excel_export": {
"success": true,
"path": "./test-cases-auto.xlsx",
"total_cases": 12,
"file_size": 20480
},
"auto_export_enabled": true,
"summary": { ... }
}
Benefits
- Zero configuration - Auto export sẵn có
- One-step workflow - Generate + Export trong 1 call
- Customizable - Có thể disable hoặc thay đổi path
- Error handling - Excel export không ảnh hưởng đến test case generation
🤖 Automation Test Generation (NEW!)
Generate automation test code từ test cases với Playwright:
Supported Frameworks
- Playwright + JavaScript (hiện tại)
- Sắp tới: Cypress, Selenium WebDriver
Generated Code Features
- Smart step conversion - Tự động chuyển test steps thành Playwright commands
- Test data substitution - Tự động sử dụng test data từ test cases
- Custom helpers - Login, toast verification, dashboard waiting
- Data-testid selectors - Best practice cho stable selectors
- Comprehensive assertions - Mọi expected result được convert thành assertions
Sample Generated Test
test('Login with valid credentials', async ({ page }) => {
// Step 1: Open login page
await page.goto('/login');
// Step 2: Enter valid username
await page.fill('[data-testid="username"]', 'valid_user');
// Step 3: Enter valid password
await page.fill('[data-testid="password"]', 'valid_pass');
// Step 4: Click Login
await page.click('[data-testid="login-button"]');
// Expected Result: User is redirected to dashboard
await helpers.waitForDashboard(page);
});
Usage
- Generate test cases từ requirements
- Generate automation tests từ test cases
- Install dependencies:
npm install @playwright/test - Run tests:
npx playwright test
Output Structure
{
"framework": "playwright",
"language": "javascript",
"base_url": "https://example.com",
"dependencies": ["@playwright/test"],
"setup": "// Playwright configuration...",
"tests": {
"positive": [...],
"negative": [...],
"boundary": [...],
"edge": [...]
}
}
🐛 Troubleshooting
Common Issues
- "Missing required fields" → Kiểm tra input có đủ thông tin
- "Invalid input type" → Input không phải string/object hợp lệ
- "Validation failed" → Output không đủ yêu cầu QA
- "File not found" → Kiểm tra path và permissions
- "Unsupported file type" → Check supported formats
- "Excel export failed" → Kiểm tra write permissions và disk space
- "Automation generation failed" → Kiểm tra test case structure và steps format
Debug Mode
Server logs errors to stderr, check console output.
📈 Performance
- Processing time: < 1s cho input thông thường
- Memory usage: < 50MB
- Output size: ~10-50KB JSON
- File reading: < 100ms cho files < 1MB
- Excel export: < 500ms cho 50 test cases
- Automation generation: < 200ms cho 20 test cases
🤝 Contributing
- Fork project
- Create feature branch
- Add test cases cho new feature
- Submit PR
📄 License
MIT License
Made with ❤️ for QA Teams
🔗 Links
- GitHub Repository: https://github.com/anhpdhe171578/mcp-test-case-generator
- Issues & Feature Requests: https://github.com/anhpdhe171578/mcp-test-case-generator/issues
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。