testrail

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TestRail Integration

TestRail 集成

Bidirectional sync between Playwright tests and TestRail test management.
Playwright测试与TestRail测试管理之间的双向同步。

Prerequisites

前提条件

Environment variables must be set:
  • TESTRAIL_URL
    — e.g.,
    https://your-instance.testrail.io
  • TESTRAIL_USER
    — your email
  • TESTRAIL_API_KEY
    — API key from TestRail
If not set, inform the user how to configure them and stop.
必须设置以下环境变量:
  • TESTRAIL_URL
    — 例如:
    https://your-instance.testrail.io
  • TESTRAIL_USER
    — 你的邮箱
  • TESTRAIL_API_KEY
    — 来自TestRail的API密钥
如果未设置,请告知用户如何配置并停止操作。

Capabilities

功能

1. Import Test Cases → Generate Playwright Tests

1. 导入测试用例 → 生成Playwright测试

/pw:testrail import --project <id> --suite <id>
Steps:
  1. Call
    testrail_get_cases
    MCP tool to fetch test cases
  2. 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' })
  3. Generate test files grouped by section
  4. Report: X cases imported, Y tests generated
/pw:testrail import --project <id> --suite <id>
步骤:
  1. 调用
    testrail_get_cases
    MCP工具获取测试用例
  2. 针对每个测试用例:
    • 读取标题、前置条件、步骤、预期结果
    • 使用合适的模板映射为Playwright测试
    • 将TestRail用例ID作为测试注解包含在内:
      test.info().annotations.push({ type: 'testrail', description: 'C12345' })
  3. 按章节分组生成测试文件
  4. 报告:已导入X个用例,生成Y个测试

2. Push Test Results → TestRail

2. 推送测试结果 → TestRail

/pw:testrail push --run <id>
Steps:
  1. Run Playwright tests with JSON reporter:
    bash
    npx playwright test --reporter=json > test-results.json
  2. Parse results: map each test to its TestRail case ID (from annotations)
  3. Call
    testrail_add_result
    MCP tool for each test:
    • Pass → status_id: 1
    • Fail → status_id: 5, include error message
    • Skip → status_id: 2
  4. Report: X results pushed, Y passed, Z failed
/pw:testrail push --run <id>
步骤:
  1. 使用JSON报告器运行Playwright测试:
    bash
    npx playwright test --reporter=json > test-results.json
  2. 解析结果:将每个测试映射到其TestRail用例ID(来自注解)
  3. 为每个测试调用
    testrail_add_result
    MCP工具:
    • 通过 → status_id: 1
    • 失败 → status_id: 5,包含错误信息
    • 跳过 → status_id: 2
  4. 报告:已推送X个结果,Y个通过,Z个失败

3. Create Test Run

3. 创建测试运行

/pw:testrail run --project <id> --name "Sprint 42 Regression"
Steps:
  1. Call
    testrail_add_run
    MCP tool
  2. Include all test case IDs found in Playwright test annotations
  3. Return run ID for result pushing
/pw:testrail run --project <id> --name "Sprint 42 Regression"
步骤:
  1. 调用
    testrail_add_run
    MCP工具
  2. 包含在Playwright测试注解中找到的所有测试用例ID
  3. 返回运行ID用于结果推送

4. Sync Status

4. 同步状态

/pw:testrail status --project <id>
Steps:
  1. Fetch test cases from TestRail
  2. Scan local Playwright tests for TestRail annotations
  3. 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>
步骤:
  1. 从TestRail获取测试用例
  2. 扫描本地Playwright测试中的TestRail注解
  3. 报告覆盖率:
    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:
  1. Read the Playwright test for this case ID
  2. Extract steps and expected results from test code
  3. Call
    testrail_update_case
    MCP tool to update steps
/pw:testrail update --case <id>
步骤:
  1. 读取此用例ID对应的Playwright测试
  2. 从测试代码中提取步骤和预期结果
  3. 调用
    testrail_update_case
    MCP工具更新步骤

MCP Tools Used

使用的MCP工具

ToolWhen
testrail_get_projects
List available projects
testrail_get_suites
List suites in project
testrail_get_cases
Read test cases
testrail_add_case
Create new test case
testrail_update_case
Update existing case
testrail_add_run
Create test run
testrail_add_result
Push individual result
testrail_get_results
Read historical results
工具使用场景
testrail_get_projects
列出可用项目
testrail_get_suites
列出项目中的套件
testrail_get_cases
读取测试用例
testrail_add_case
创建新测试用例
testrail_update_case
更新现有用例
testrail_add_run
创建测试运行
testrail_add_result
推送单个结果
testrail_get_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运行/结果的链接