Skip to main content
Glama
raymondsambur

Automation Script Generator MCP Server

process_test_scenario

Generate complete WDIO test files from Gherkin scenarios and UI selectors for automated testing workflows.

Instructions

Process a test scenario provided directly by the user and generate complete WDIO test files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scenario_titleYesTitle of the test scenario
tagsNoTest ID tags for the scenario (e.g., ["@login", "@smoke", "@TEST-001"])
gherkin_syntaxYesComplete Gherkin syntax with Given/When/Then steps
selectorsYesUI element selectors as key-value pairs (e.g., {"usernameInput": "#username", "loginButton": "[data-testid=login-btn]"})
data_itemsNoTest data items and configurations (optional)
output_directoryYesBase directory where all generated files should be saved
repo_pathNoPath to existing repository for pattern analysis (optional)

Implementation Reference

  • index.js:330-335 (registration)
    Registers all tools including process_test_scenario by returning the toolConfigs array in ListTools handler
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolConfigs, }; });
  • index.js:336-374 (registration)
    Registers the call handler for tools with switch case dispatching to processTestScenario for 'process_test_scenario'
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { // Validate arguments against schema this.validateArgs(name, args || {}); switch (name) { case 'process_test_scenario': return await this.processTestScenario(args); case 'analyze_repository_patterns': return await this.analyzeRepositoryPatterns(args); case 'generate_feature_file': return await this.generateFeatureFile(args); case 'generate_steps_file': return await this.generateStepsFile(args); case 'generate_page_file': return await this.generatePageFile(args); case 'generate_component_file': return await this.generateComponentFile(args); case 'review_and_enhance_code': return await this.reviewAndEnhanceCode(args); default: throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${name}` ); } } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Error executing tool ${name}: ${error.message}` ); } }); }
  • Input schema definition for process_test_scenario tool
    { name: 'process_test_scenario', description: 'Process a test scenario provided directly by the user and generate complete WDIO test files', inputSchema: { type: 'object', properties: { scenario_title: { type: 'string', description: 'Title of the test scenario', minLength: 1, }, tags: { type: 'array', items: { type: 'string' }, description: 'Test ID tags for the scenario (e.g., ["@login", "@smoke", "@TEST-001"])', }, gherkin_syntax: { type: 'string', description: 'Complete Gherkin syntax with Given/When/Then steps', minLength: 1, }, selectors: { type: 'object', description: 'UI element selectors as key-value pairs (e.g., {"usernameInput": "#username", "loginButton": "[data-testid=login-btn]"})', }, data_items: { type: 'object', description: 'Test data items and configurations (optional)', }, output_directory: { type: 'string', description: 'Base directory where all generated files should be saved', minLength: 1, }, repo_path: { type: 'string', description: 'Path to existing repository for pattern analysis (optional)', }, }, required: ['scenario_title', 'gherkin_syntax', 'selectors', 'output_directory'], additionalProperties: false, }, },
  • Primary handler function for process_test_scenario tool. Validates input, performs repo analysis if provided, determines intelligent create/update strategy for files, generates/updates WDIO test files (feature, steps, page, data), applies code review and enhancements.
    async processTestScenario(args) { const { scenario_title, tags = [], gherkin_syntax, selectors, data_items = null, output_directory, repo_path } = args; try { const results = { scenario_title, tags, files_generated: [], files_updated: [], analysis: null, decisions: [] }; // Step 1: Analyze repository patterns if repo_path provided if (repo_path) { console.error(`Analyzing repository patterns at: ${repo_path}`); const analysisResult = await this.analyzeRepositoryPatterns({ repo_path, pattern_types: ['features', 'steps', 'pages', 'components'] }); results.analysis = analysisResult.content[0].text; } // Step 2: Analyze existing files and determine strategy const fileStrategy = await this.analyzeExistingFiles( output_directory, scenario_title, gherkin_syntax, selectors, repo_path ); results.decisions = fileStrategy.decisions; // Step 3: Process files based on strategy await this.executeFileStrategy(fileStrategy, { scenario_title, tags, gherkin_syntax, selectors, data_items, output_directory, repo_path }); results.files_generated = fileStrategy.filesToCreate; results.files_updated = fileStrategy.filesToUpdate; // Step 4: Review and enhance all processed files console.error('Reviewing and enhancing generated/updated code...'); const allFiles = [...results.files_generated, ...results.files_updated]; if (allFiles.length > 0) { await this.reviewAndEnhanceCode({ file_paths: allFiles, review_criteria: ['docs', 'pom', 'functions', 'utils', 'format', 'existing_steps'], repo_path }); } return { content: [ { type: 'text', text: this.formatProcessingResults(results), }, ], }; } catch (error) { throw new Error(`Failed to process test scenario: ${error.message}`); } }
  • Helper that implements smart analysis to decide create new files or update existing based on content similarity (features >60%, selectors overlap, step reuse >80%)
    async analyzeExistingFiles(output_directory, scenario_title, gherkin_syntax, selectors, repo_path) { const strategy = { decisions: [], filesToCreate: [], filesToUpdate: [], similarFeatures: [], matchingPages: [], existingSteps: [] }; try { // Check if output directory exists const dirExists = await fs.pathExists(output_directory); if (!dirExists) { strategy.decisions.push('Output directory does not exist - will create new files'); return this.createNewFilesStrategy(output_directory, scenario_title); } // Analyze existing feature files const existingFeatures = await this.findSimilarFeatures(output_directory, scenario_title, gherkin_syntax); strategy.similarFeatures = existingFeatures; // Analyze existing page objects const matchingPages = await this.findMatchingPageObjects(output_directory, selectors); strategy.matchingPages = matchingPages; // Analyze existing step definitions const existingSteps = await this.findReusableSteps(output_directory, gherkin_syntax, repo_path); strategy.existingSteps = existingSteps; // Determine strategy based on analysis if (existingFeatures.length > 0) { // Similar feature found - update existing strategy.decisions.push(`Found similar feature: ${existingFeatures[0].file} - will add new scenario`); strategy.filesToUpdate.push(existingFeatures[0].path); // Check if we need to update corresponding steps file const stepsFile = existingFeatures[0].path.replace(/\.feature$/, '.steps.js').replace('/features/', '/step-definitions/'); if (await fs.pathExists(stepsFile)) { strategy.filesToUpdate.push(stepsFile); strategy.decisions.push(`Will update corresponding steps file: ${path.basename(stepsFile)}`); } } else { // No similar feature - create new feature file const featureFileName = this.generateFileName(scenario_title, 'feature'); const featurePath = path.join(output_directory, 'features', featureFileName); strategy.filesToCreate.push(featurePath); strategy.decisions.push('No similar feature found - will create new feature file'); } // Handle page objects if (matchingPages.length > 0) { // Update existing page object with new selectors strategy.filesToUpdate.push(matchingPages[0].path); strategy.decisions.push(`Found matching page object: ${matchingPages[0].file} - will add new selectors`); } else { // Create new page object const pageFileName = this.generateFileName(scenario_title, 'page'); const pagePath = path.join(output_directory, 'pageobjects', pageFileName); strategy.filesToCreate.push(pagePath); strategy.decisions.push('No matching page object found - will create new page file'); } // Handle step definitions if (strategy.filesToUpdate.some(f => f.includes('.steps.js'))) { // Already updating steps file with feature strategy.decisions.push('Step definitions will be updated with feature scenarios'); } else { // Create new steps file const stepsFileName = this.generateFileName(scenario_title, 'steps'); const stepsPath = path.join(output_directory, 'step-definitions', stepsFileName); strategy.filesToCreate.push(stepsPath); strategy.decisions.push('Will create new step definitions file'); } return strategy; } catch (error) { console.warn(`Error analyzing existing files: ${error.message}`); strategy.decisions.push('Analysis failed - defaulting to create new files'); return this.createNewFilesStrategy(output_directory, scenario_title); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/raymondsambur/automation-script-generator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server