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);
        }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this is a read-only operation, what happens to existing files, error handling, performance characteristics, or what 'complete WDIO test files' entails. For a tool with 7 parameters and file generation, this is inadequate behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently communicates the core functionality without any wasted words. It's front-loaded with the main action and outcome, making it immediately understandable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 7 parameters, nested objects, file generation, and no output schema or annotations, the description is insufficient. It doesn't explain what 'complete WDIO test files' means, what format they're in, whether this overwrites existing files, or what the expected output looks like. The agent would need to guess about the tool's behavior and results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema itself. The description doesn't add any additional meaning about parameter usage, relationships, or constraints beyond what's already in the schema. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('process a test scenario') and the output ('generate complete WDIO test files'), distinguishing it from sibling tools that focus on individual file generation or analysis. It explicitly mentions the resource being processed (test scenario) and the transformation performed.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings like generate_feature_file or generate_steps_file. It doesn't mention prerequisites, alternatives, or exclusions, leaving the agent to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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