testrail
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTestRail Integration
TestRail 集成
Bidirectional sync between Playwright tests and TestRail test management.
Playwright测试与TestRail测试管理之间的双向同步。
Prerequisites
前提条件
Environment variables must be set:
- — e.g.,
TESTRAIL_URLhttps://your-instance.testrail.io - — your email
TESTRAIL_USER - — API key from TestRail
TESTRAIL_API_KEY
If not set, inform the user how to configure them and stop.
必须设置以下环境变量:
- — 例如:
TESTRAIL_URLhttps://your-instance.testrail.io - — 你的邮箱
TESTRAIL_USER - — 来自TestRail的API密钥
TESTRAIL_API_KEY
如果未设置,请告知用户如何配置并停止操作。
Capabilities
功能
1. Import Test Cases → Generate Playwright Tests
1. 导入测试用例 → 生成Playwright测试
/pw:testrail import --project <id> --suite <id>Steps:
- Call MCP tool to fetch test cases
testrail_get_cases - For each test case:
- Read title, preconditions, steps, expected results
- Map to a Playwright test using appropriate template
- Include TestRail case ID as test annotation:
test.info().annotations.push({ type: 'testrail', description: 'C12345' })
- Generate test files grouped by section
- Report: X cases imported, Y tests generated
/pw:testrail import --project <id> --suite <id>步骤:
- 调用MCP工具获取测试用例
testrail_get_cases - 针对每个测试用例:
- 读取标题、前置条件、步骤、预期结果
- 使用合适的模板映射为Playwright测试
- 将TestRail用例ID作为测试注解包含在内:
test.info().annotations.push({ type: 'testrail', description: 'C12345' })
- 按章节分组生成测试文件
- 报告:已导入X个用例,生成Y个测试
2. Push Test Results → TestRail
2. 推送测试结果 → TestRail
/pw:testrail push --run <id>Steps:
- Run Playwright tests with JSON reporter:
bash
npx playwright test --reporter=json > test-results.json - Parse results: map each test to its TestRail case ID (from annotations)
- Call MCP tool for each test:
testrail_add_result- Pass → status_id: 1
- Fail → status_id: 5, include error message
- Skip → status_id: 2
- Report: X results pushed, Y passed, Z failed
/pw:testrail push --run <id>步骤:
- 使用JSON报告器运行Playwright测试:
bash
npx playwright test --reporter=json > test-results.json - 解析结果:将每个测试映射到其TestRail用例ID(来自注解)
- 为每个测试调用MCP工具:
testrail_add_result- 通过 → status_id: 1
- 失败 → status_id: 5,包含错误信息
- 跳过 → status_id: 2
- 报告:已推送X个结果,Y个通过,Z个失败
3. Create Test Run
3. 创建测试运行
/pw:testrail run --project <id> --name "Sprint 42 Regression"Steps:
- Call MCP tool
testrail_add_run - Include all test case IDs found in Playwright test annotations
- Return run ID for result pushing
/pw:testrail run --project <id> --name "Sprint 42 Regression"步骤:
- 调用MCP工具
testrail_add_run - 包含在Playwright测试注解中找到的所有测试用例ID
- 返回运行ID用于结果推送
4. Sync Status
4. 同步状态
/pw:testrail status --project <id>Steps:
- Fetch test cases from TestRail
- Scan local Playwright tests for TestRail annotations
- Report coverage:
TestRail cases: 150 Playwright tests with TestRail IDs: 120 Unlinked TestRail cases: 30 Playwright tests without TestRail IDs: 15
/pw:testrail status --project <id>步骤:
- 从TestRail获取测试用例
- 扫描本地Playwright测试中的TestRail注解
- 报告覆盖率:
TestRail cases: 150 Playwright tests with TestRail IDs: 120 Unlinked TestRail cases: 30 Playwright tests without TestRail IDs: 15
5. Update Test Cases in TestRail
5. 在TestRail中更新测试用例
/pw:testrail update --case <id>Steps:
- Read the Playwright test for this case ID
- Extract steps and expected results from test code
- Call MCP tool to update steps
testrail_update_case
/pw:testrail update --case <id>步骤:
- 读取此用例ID对应的Playwright测试
- 从测试代码中提取步骤和预期结果
- 调用MCP工具更新步骤
testrail_update_case
MCP Tools Used
使用的MCP工具
| Tool | When |
|---|---|
| List available projects |
| List suites in project |
| Read test cases |
| Create new test case |
| Update existing case |
| Create test run |
| Push individual result |
| Read historical results |
| 工具 | 使用场景 |
|---|---|
| 列出可用项目 |
| 列出项目中的套件 |
| 读取测试用例 |
| 创建新测试用例 |
| 更新现有用例 |
| 创建测试运行 |
| 推送单个结果 |
| 读取历史结果 |
Test Annotation Format
测试注解格式
All Playwright tests linked to TestRail include:
typescript
test('should login successfully', async ({ page }) => {
test.info().annotations.push({
type: 'testrail',
description: 'C12345',
});
// ... test code
});This annotation is the bridge between Playwright and TestRail.
所有链接到TestRail的Playwright测试都包含:
typescript
test('should login successfully', async ({ page }) => {
test.info().annotations.push({
type: 'testrail',
description: 'C12345',
});
// ... test code
});此注解是Playwright与TestRail之间的桥梁。
Output
输出
- Operation summary with counts
- Any errors or unmatched cases
- Link to TestRail run/results
- 包含统计的操作摘要
- 任何错误或不匹配的用例
- 指向TestRail运行/结果的链接