create_bdd_test_script
Generate BDD test scripts in Gherkin format for Zephyr Scale Cloud, validating steps and structuring scenarios with Given/When/Then syntax.
Instructions
Create a BDD test script using Gherkin format with helper validation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| testCaseKey | Yes | Test case key (format: [A-Z]+-T[0-9]+) | |
| feature | No | Feature description for the BDD script | |
| scenario | No | Scenario description for the BDD script | |
| steps | No | Array of Gherkin steps (must start with Given/When/Then/And/But) |
Implementation Reference
- src/tools/test-script-tools.js:123-236 (handler)Main handler function that validates inputs (testCaseKey, feature, scenario, steps), builds a Gherkin-formatted BDD test script, calls createTestScript to persist it to Zephyr, and enhances the response with helper info.async function createBddTestScript(args) { try { const { testCaseKey, feature, scenario, steps } = args; if (!testCaseKey) { throw new Error('testCaseKey is required'); } if (!config.testCaseKeyPattern.test(testCaseKey)) { throw new Error('Invalid testCaseKey format. Must match pattern: [A-Z]+-T[0-9]+'); } // Build Gherkin script let gherkinScript = ''; if (feature) { gherkinScript += `Feature: ${feature}\n\n`; } if (scenario) { gherkinScript += `Scenario: ${scenario}\n`; } if (steps && Array.isArray(steps)) { if (steps.length === 0) { throw new Error('At least one step must be provided'); } const validStepKeywords = ['Given', 'When', 'Then', 'And', 'But']; steps.forEach((step, index) => { if (typeof step !== 'string' || step.trim().length === 0) { throw new Error(`Step ${index + 1} must be a non-empty string`); } const stepText = step.trim(); const hasKeyword = validStepKeywords.some(keyword => stepText.toLowerCase().startsWith(keyword.toLowerCase()) ); if (!hasKeyword) { throw new Error(`Step ${index + 1} must start with a Gherkin keyword: Given, When, Then, And, or But`); } gherkinScript += ` ${stepText}\n`; }); } else if (!feature && !scenario) { throw new Error('Either steps array or feature/scenario text must be provided'); } // Create the script using the base function const result = await createTestScript({ testCaseKey, text: gherkinScript, type: 'bdd' }); // Add additional info to the response const originalContent = result.content[0].text; let parsedContent; try { parsedContent = JSON.parse(originalContent); } catch (parseError) { // If JSON parsing fails, return the original result with error info return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to parse createTestScript response', originalResponse: originalContent, parseError: parseError.message, bddHelper: { feature, scenario, stepsCount: steps ? steps.length : 0, generatedScript: gherkinScript } }, null, 2) } ], isError: true }; } return { content: [ { type: 'text', text: JSON.stringify({ ...parsedContent, bddHelper: { feature, scenario, stepsCount: steps ? steps.length : 0, generatedScript: gherkinScript } }, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: formatError(error, `creating BDD test script for ${args.testCaseKey}`) } ], isError: true }; } }
- JSON schema defining the input parameters for the tool: required testCaseKey, optional feature, scenario, and steps array of strings.inputSchema: { type: 'object', properties: { testCaseKey: { type: 'string', description: 'Test case key (format: [A-Z]+-T[0-9]+)', pattern: config.testCaseKeyPattern.source }, feature: { type: 'string', description: 'Feature description for the BDD script' }, scenario: { type: 'string', description: 'Scenario description for the BDD script' }, steps: { type: 'array', description: 'Array of Gherkin steps (must start with Given/When/Then/And/But)', items: { type: 'string', description: 'Gherkin step (e.g., "Given I am logged in" or "When I click the button")' }, minItems: 1 } }, required: ['testCaseKey'] },
- src/tools/test-script-tools.js:282-314 (registration)Tool object registration within the testScriptTools export array, specifying name, description, inputSchema, and handler reference.{ name: 'create_bdd_test_script', description: 'Create a BDD test script using Gherkin format with helper validation', inputSchema: { type: 'object', properties: { testCaseKey: { type: 'string', description: 'Test case key (format: [A-Z]+-T[0-9]+)', pattern: config.testCaseKeyPattern.source }, feature: { type: 'string', description: 'Feature description for the BDD script' }, scenario: { type: 'string', description: 'Scenario description for the BDD script' }, steps: { type: 'array', description: 'Array of Gherkin steps (must start with Given/When/Then/And/But)', items: { type: 'string', description: 'Gherkin step (e.g., "Given I am logged in" or "When I click the button")' }, minItems: 1 } }, required: ['testCaseKey'] }, handler: createBddTestScript }