Automation Script Generator MCP Server

Automation Script Generator MCP Server

Processes test scenarios from user prompts to generate complete WDIO test suites with intelligent file management that analyzes existing files to determine whether to update them or create new ones.

Category
访问服务器

README

Automation Script Generator MCP Server

An MCP (Model Context Protocol) server for automated test script generation using the WDIO framework. This server processes test scenarios directly from user prompts and generates complete WDIO test suites with intelligent file management that analyzes existing files to determine whether to update them or create new ones.

Features

  • 🧠 Smart File Analysis: Intelligently analyzes existing test files to prevent duplicates and maintain organized structure
  • Direct User Input: Process test scenarios from user prompts (no external dependencies)
  • Repository Analysis: Analyze existing patterns and conventions
  • WDIO Code Generation: Generate complete test suites with:
    • Feature files (Gherkin syntax)
    • Step definition files (WDIO functions)
    • Page Object Model files (selectors and methods)
    • Component files (test data collections)
  • Schema Validation: Comprehensive input validation using JSON Schema
  • Code Review & Enhancement: Automated code review with improvements
  • Intelligent Decision Making:
    • Updates existing features when similarity > 60%
    • Reuses page objects with matching selectors
    • Extends step definitions when steps are similar
    • Creates new files only when necessary
  • Pattern Recognition: Reuse existing functions and maintain consistency

Schema Validation

The MCP server includes robust input validation using AJV (Another JSON Schema Validator). All tool inputs are validated against their defined schemas before execution.

Validation Features

  • Type Checking: Ensures correct data types (string, object, array, etc.)
  • Required Fields: Validates that all required parameters are provided
  • String Constraints: Enforces minimum length requirements for important fields
  • Additional Properties: Prevents extra/unknown properties in requests
  • Enum Validation: Validates against predefined allowed values
  • Detailed Error Messages: Provides clear feedback on validation failures

🧠 Smart File Analysis

The server now includes intelligent file management that analyzes your existing test structure before generating new files. This prevents duplication and maintains an organized test suite.

How It Works

  1. Feature Similarity Analysis: Compares new scenarios with existing features using keyword matching
  2. Selector Overlap Detection: Identifies when new tests share page elements with existing page objects
  3. Step Definition Reuse: Finds existing step definitions that can be extended rather than duplicated
  4. Strategic Decision Making: Determines whether to update existing files or create new ones

Decision Logic

  • Feature Similarity > 60%: Updates existing feature file with new scenarios
  • Matching Selectors Found: Extends existing page object with new elements
  • Step Similarity > 80%: Reuses and extends existing step definitions
  • No Matches Found: Creates new test files

Smart Analysis Examples

// Scenario: "User Login with 2FA"
// Decision: Update existing login.feature (85% similarity)
// Action: Add new scenario to existing file
// Reason: Keywords match: "user", "login", "credentials"

// Scenario: "Product Catalog Search"
// Decision: Create new product-catalog.feature
// Action: Generate new test suite
// Reason: No similar features found (<30% similarity)

// Scenario: "Login Page Validation"
// Decision: Update existing login.page.js
// Action: Add validation selectors to page object
// Reason: Selectors overlap: usernameInput, passwordInput

Benefits

  • Maintains Organized Structure: Keeps related tests together
  • Prevents Duplicate Code: Avoids redundant test scenarios and step definitions
  • Reduces Maintenance: Fewer files to maintain and update
  • Improves Reusability: Maximizes reuse of existing test components

Example Validation

// ✅ Valid request
{
  "database_id": "test-db-123",
  "filter": {
    "tags": ["LOGIN"],
    "status": "ready"
  }
}

// ❌ Invalid request - missing required field
{
  "filter": { "tags": ["LOGIN"] }
  // Error: must have required property 'database_id'
}

// ❌ Invalid request - extra properties
{
  "database_id": "test-db-123",
  "invalid_property": "not allowed"
  // Error: must NOT have additional properties
}

Testing Validation

Run the validation demo to see schema validation in action:

npm run test:validation
# or
node validation-demo.js

Process Flow

  1. Input from Notion: Fetch scenario_title, tags (test_id), gherkin syntax, selectors, and data items
  2. Repository Analysis: Read existing patterns and validate formats
  3. Code Generation: Create feature, steps, page, and component files
  4. Code Review: Improve, add docs, enhance, validate POM, check for reusable functions

Setup

Prerequisites

  • Node.js 18+
  • Notion integration token
  • Notion database with test scenarios

Installation

  1. Clone or create the project:
git clone <repository-url>
cd automation-script-generator
  1. Install dependencies:
npm install
  1. Configure environment:
cp .env.example .env
# Edit .env with your Notion token and database ID

Environment Configuration

Create a .env file with the following variables (optional):

DEFAULT_REPO_PATH=./test-repository
OUTPUT_BASE_PATH=./generated
WDIO_CONFIG_PATH=./wdio.conf.js

Usage

Starting the MCP Server

npm start

The server will run on stdio and expose the following tool:

Main Tool: process_test_scenario

Process a complete test scenario from user input and generate all necessary WDIO files.

Parameters:

  • scenario_title (required): Title of the test scenario
  • gherkin_syntax (required): Complete Gherkin syntax with Given/When/Then steps
  • selectors (required): UI element selectors as key-value pairs
  • output_directory (required): Base directory for generated files
  • tags (optional): Test ID tags (e.g., ["@login", "@smoke", "@TEST-001"])
  • data_items (optional): Test data items and configurations
  • repo_path (optional): Path to existing repository for pattern analysis

Additional Tools

The following individual tools are also available for granular control:

analyze_repository_patterns

Analyze repository for existing patterns and conventions.

generate_feature_file

Generate WDIO feature file with Gherkin syntax.

generate_steps_file

Generate step definitions file.

generate_page_file

Generate page object file.

generate_component_file

Generate component file with test data.

review_and_enhance_code

Review and enhance generated code.

Example Workflow

Here's how to use the MCP server to generate a complete test suite from a user prompt:

// Single call to process complete scenario
await process_test_scenario({
  scenario_title: "User Login Functionality",
  tags: ["@login", "@smoke", "@TEST-001"],
  gherkin_syntax: `Feature: User Login
  
  Scenario: Successful login with valid credentials
    Given I am on the login page
    When I enter valid username "user@example.com"
    And I enter valid password "password123"
    And I click the login button
    Then I should be redirected to the dashboard
    And I should see the welcome message`,
  selectors: {
    usernameInput: '[data-testid="username-input"]',
    passwordInput: '[data-testid="password-input"]',
    loginButton: '[data-testid="login-button"]',
    welcomeMessage: ".welcome-message",
  },
  data_items: {
    validUser: {
      username: "user@example.com",
      password: "password123",
    },
    invalidUser: {
      username: "invalid@example.com",
      password: "wrongpassword",
    },
  },
  output_directory: "./generated-tests",
  repo_path: "./existing-tests", // Optional: for pattern analysis
});

This single call will:

  1. Analyze existing repository patterns (if repo_path provided)
  2. Generate feature file with Gherkin syntax
  3. Generate step definitions with WDIO functions
  4. Generate page object with selectors and methods
  5. Generate test data component (if data_items provided)
  6. Review and enhance all generated code
  7. Return summary of all generated files

Generated File Structure

The server generates files following WDIO best practices:

test/
├── features/
│   └── *.feature          # Gherkin scenarios
├── step-definitions/
│   └── *.steps.js         # Step implementations
├── pageobjects/
│   └── *.page.js          # Page Object Models
└── data/
    └── *.data.js          # Test data components

Code Quality Features

  • Documentation: Automatic JSDoc comments
  • POM Patterns: Page Object Model best practices
  • Function Reuse: Detection of existing step functions
  • Naming Conventions: Consistent naming across files
  • Error Handling: Proper error handling in generated code
  • WDIO Integration: Full compatibility with WebDriverIO framework

Testing Validation

Run the validation demo to see schema validation in action:

npm run test:validation

User Prompt Format

See USER-PROMPT-EXAMPLES.md for detailed examples of how to format user prompts for the MCP server.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes following the coding standards
  4. Add tests for new functionality
  5. Submit a pull request

License

ISC License

Support

For issues and questions:

  1. Check the examples in the /examples directory
  2. Review the user prompt examples in USER-PROMPT-EXAMPLES.md
  3. Review the MCP documentation at https://modelcontextprotocol.io
  4. Open an issue in the repository

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选