/**
* Example usage of MCP Zephyr tools
*
* This file demonstrates how to use the various Zephyr tools
* once the MCP server is integrated with Claude.
*/
// Example: Create a test case
const createTestCaseExample = `
// Create a comprehensive test case
await zephyr_create_test_case({
projectKey: "PROJ",
name: "User Registration Flow Test",
objective: "Verify new users can successfully register with valid information",
precondition: "Registration form is accessible and user is not logged in",
status: "Draft",
priority: "High",
component: ["Authentication", "User Management"],
estimatedTime: 10,
labels: ["smoke-test", "registration", "critical-path"],
steps: [
{
action: "Navigate to registration page",
expected: "Registration form is displayed with all required fields",
stepIndex: 1
},
{
action: "Enter valid email, password, and confirm password",
expected: "Fields accept input and validation passes",
stepIndex: 2
},
{
action: "Click 'Register' button",
expected: "User account is created and redirected to dashboard",
stepIndex: 3
},
{
action: "Verify email confirmation is sent",
expected: "Confirmation email arrives in user's inbox",
stepIndex: 4
}
]
});
`;
// Example: Create a test cycle and add test cases
const createTestCycleExample = `
// Create a test cycle for regression testing
const testCycle = await zephyr_create_test_cycle({
projectKey: "PROJ",
name: "Q4 2024 Regression Cycle",
description: "Comprehensive regression testing for Q4 release",
status: "Planned",
environment: "Staging",
startDate: "2024-12-01",
endDate: "2024-12-15"
});
// Add multiple test cases to the cycle
await zephyr_add_test_cases_to_cycle({
testCycleKey: testCycle.key,
testCaseKeys: ["PROJ-T1", "PROJ-T2", "PROJ-T3", "PROJ-T4"]
});
`;
// Example: Execute test cases with detailed results
const executeTestsExample = `
// Execute a test case with step-by-step results
await zephyr_create_test_execution({
testCaseKey: "PROJ-T1",
testCycleKey: "PROJ-C1",
status: "Pass",
executedBy: "qa.automation@company.com",
actualTime: 8,
comment: "All test steps passed successfully. No issues found.",
stepResults: [
{
stepIndex: 0,
status: "Pass",
actual: "Registration page loaded in 2.3 seconds",
comment: "Performance is within acceptable limits"
},
{
stepIndex: 1,
status: "Pass",
actual: "Form validation working correctly",
comment: "Password strength indicator functional"
},
{
stepIndex: 2,
status: "Pass",
actual: "Successfully redirected to dashboard",
comment: "Welcome message displayed correctly"
},
{
stepIndex: 3,
status: "Pass",
actual: "Email received within 30 seconds",
comment: "Email template looks good, all links working"
}
]
});
`;
// Example: Bulk execution creation
const bulkExecutionExample = `
// Create multiple test executions at once
const executions = [
{
testCaseKey: "PROJ-T1",
testCycleKey: "PROJ-C1",
status: "Pass",
actualTime: 8
},
{
testCaseKey: "PROJ-T2",
testCycleKey: "PROJ-C1",
status: "Fail",
actualTime: 15,
comment: "Bug found in payment processing"
},
{
testCaseKey: "PROJ-T3",
testCycleKey: "PROJ-C1",
status: "Block",
actualTime: 5,
comment: "Blocked by API outage"
}
];
await zephyr_bulk_create_test_executions({
executions: executions
});
`;
// Example: Search test cases
const searchExample = `
// Search for high priority test cases in specific components
await zephyr_search_test_cases({
jql: 'project = PROJ AND status = "Ready" AND priority IN (High, Critical) AND component IN ("Authentication", "Security")',
maxResults: 25
});
// Search for recently created test cases
await zephyr_search_test_cases({
jql: 'project = PROJ AND created >= -7d',
maxResults: 50
});
`;
// Example: Get comprehensive test results
const getResultsExample = `
// Get test results for a complete test cycle
const results = await zephyr_get_test_results({
testCycleKey: "PROJ-C1",
maxResults: 100
});
// Calculate test coverage and pass rate
const totalTests = results.size;
const passedTests = results.values.filter(r => r.status === "Pass").length;
const failedTests = results.values.filter(r => r.status === "Fail").length;
const blockedTests = results.values.filter(r => r.status === "Blocked").length;
console.log(\`Test Execution Summary:\`);
console.log(\`Total Tests: \${totalTests}\`);
console.log(\`Passed: \${passedTests} (\${(passedTests/totalTests*100).toFixed(1)}%)\`);
console.log(\`Failed: \${failedTests} (\${(failedTests/totalTests*100).toFixed(1)}%)\`);
console.log(\`Blocked: \${blockedTests} (\${(blockedTests/totalTests*100).toFixed(1)}%)\`);
console.log(\`Pass Rate: \${(passedTests/(totalTests-blockedTests)*100).toFixed(1)}%\`);
`;
// Example: Complete test workflow
const completeWorkflowExample = `
// Complete workflow: Plan -> Create -> Execute -> Report
// 1. Create test plan
const testPlan = await zephyr_create_test_plan({
projectKey: "PROJ",
name: "Q4 2024 Release Testing",
description: "Comprehensive testing plan for Q4 release including new features and regression",
status: "Active",
startDate: "2024-12-01",
endDate: "2024-12-20"
});
// 2. Create test cycle
const testCycle = await zephyr_create_test_cycle({
projectKey: "PROJ",
name: "Q4 2024 Feature Testing",
description: "New features testing for Q4 release",
status: "Active",
environment: "Staging"
});
// 3. Create test cases
const testCases = [];
for (let i = 1; i <= 5; i++) {
const testCase = await zephyr_create_test_case({
projectKey: "PROJ",
name: \`Feature Test Case \${i}\`,
objective: \`Test new feature \${i} functionality\`,
status: "Ready",
priority: i <= 2 ? "High" : "Medium"
});
testCases.push(testCase);
}
// 4. Add test cases to cycle
await zephyr_add_test_cases_to_cycle({
testCycleKey: testCycle.key,
testCaseKeys: testCases.map(tc => tc.key)
});
// 5. Execute all test cases
const executions = testCases.map((testCase, index) => ({
testCaseKey: testCase.key,
testCycleKey: testCycle.key,
status: index % 4 === 0 ? "Fail" : "Pass", // Simulate some failures
actualTime: 5 + Math.floor(Math.random() * 10),
comment: index % 4 === 0 ? "Bug found - needs investigation" : "Test passed successfully"
}));
await zephyr_bulk_create_test_executions({ executions });
// 6. Get final results
const finalResults = await zephyr_get_test_results({
testCycleKey: testCycle.key,
maxResults: 100
});
console.log("Test execution completed!");
`;
export {
createTestCaseExample,
createTestCycleExample,
executeTestsExample,
bulkExecutionExample,
searchExample,
getResultsExample,
completeWorkflowExample
};