Skip to main content
Glama
lucad87

MCP Server - Test Migration (WDIO to Playwright)

by lucad87

refactor_to_pom

Converts migrated Playwright tests to Page Object Model pattern by extracting selectors and creating reusable page object classes with methods.

Instructions

Refactors a migrated Playwright test to use Page Object Model pattern. Extracts actual selectors and creates proper page object classes with methods.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
testContentYesThe migrated Playwright test content to refactor
filePathNoFile path for generating appropriate page object names
existingPageObjectsNoOptional JSON string of existing page objects to extend or reuse

Implementation Reference

  • The handler function that orchestrates the "refactor_to_pom" tool execution. It calls the transformer function and formats the result for the MCP client.
    export async function handleRefactorToPom(args) {
      const { testContent, filePath = 'test.spec.js' } = args;
    
      const result = refactorToPom(testContent, filePath);
    
      return {
        content: [{
          type: 'text',
          text: `# Page Object Model Refactoring
    
    ## Generated Page Object: ${result.pageObject.className}
    
    ### File: ${result.pageObject.fileName}
    
    \`\`\`javascript
    ${result.pageObject.content}
    \`\`\`
    
    ### Extracted Information:
    - URLs: ${result.pageInfo.urls.length}
    - Locators: ${result.pageInfo.locators.length}
    - Actions: ${result.pageInfo.actions.length}
    
    ### Next Steps:
    1. Create file: \`pages/${result.pageObject.fileName}\`
    2. Import the page object in your test
    3. Replace direct page interactions with page object methods
    4. Add additional methods as needed for your test scenarios
    `,
        }],
      };
    }
  • The tool registration and schema definition for "refactor_to_pom".
      name: 'refactor_to_pom',
      description: 'Refactors a migrated Playwright test to use Page Object Model pattern. Extracts actual selectors and creates proper page object classes with methods.',
      inputSchema: {
        type: 'object',
        properties: {
          testContent: {
            type: 'string',
            description: 'The migrated Playwright test content to refactor',
          },
          filePath: {
            type: 'string',
            description: 'File path for generating appropriate page object names',
          },
          existingPageObjects: {
            type: 'string',
            description: 'Optional JSON string of existing page objects to extend or reuse',
          },
        },
        required: ['testContent'],
      },
    },
  • The core implementation function "refactorToPom" which uses AST extraction to generate Page Object Model code.
    export function refactorToPom(testContent, filePath = 'test.spec.js') {
      const pageInfo = extractPageInfo(testContent);
      const pageName = generatePageName(filePath);
      const pageObjectClass = generatePageObjectClass(pageName, pageInfo);
      
      return {
        pageObject: {
          className: pageName,
          fileName: `${pageName}.js`,
          content: pageObjectClass,
        },
        pageInfo,
      };
    }
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses behavioral mechanics ('Extracts actual selectors', 'creates proper page object classes') but omits critical operational details: whether it writes files or returns content, if it's destructive to existing code, or what the return format looks like.

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?

Two tightly constructed sentences with zero waste. Front-loaded with the primary action (refactoring to POM), followed by specific implementation details (extracting selectors, creating classes). Every word earns its place.

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

Completeness3/5

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

For a code-generation tool with 3 parameters and no annotations/output schema, the description adequately covers the transformation logic but leaves gaps regarding I/O behavior (returns code vs. writes files) and side effects. Complete enough for basic selection but missing operational safety details.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds minimal parameter-specific semantics beyond implying 'testContent' contains selectors to extract, meeting the baseline for high-coverage schemas.

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?

Description uses specific verb 'Refactors' with clear resource 'migrated Playwright test' and specifies the pattern 'Page Object Model'. It clearly distinguishes from sibling 'migrate_to_playwright' (which handles migration) by targeting already-migrated tests for structural refactoring.

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

Usage Guidelines3/5

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

The phrase 'migrated Playwright test' implies this is for post-migration scenarios, providing implicit context. However, it lacks explicit guidance on when to use versus siblings like 'analyze_wdio_test' or prerequisites like requiring a successful migration first.

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/lucad87/mcp-server-tests-migration'

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