migrate_to_playwright
Convert WebDriverIO tests to Playwright syntax using AST transformation. Supports partial migrations, preserves existing code, and generates TypeScript or JavaScript output.
Instructions
Migrates a WebDriverIO test to Playwright syntax using AST transformation. Supports partial migrations and preserves already-migrated code. Uses modern Playwright locators (getByRole, getByLabel, getByTestId with data-test-id). Supports TypeScript output.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| testContent | Yes | The WDIO test content to migrate | |
| analysisResult | No | Optional JSON string of previous analysis result to use as context | |
| filePath | No | Original file path for naming reference | |
| outputFormat | No | Output format: javascript (default) or typescript |
Implementation Reference
- src/handlers/toolHandlers.js:59-110 (handler)The `handleMigrateToPlaywright` function performs the migration of WDIO test content to Playwright using AST transformations.
export async function handleMigrateToPlaywright(args) { const { testContent, analysisResult, filePath = 'test.spec.js', outputFormat = 'javascript' } = args; let analysis = null; if (analysisResult) { try { analysis = JSON.parse(analysisResult); } catch (e) { // Continue without analysis } } const isTypeScript = outputFormat === 'typescript' || filePath.endsWith('.ts'); const migration = performAstMigration(testContent, analysis, isTypeScript); let targetFile = filePath; if (isTypeScript) { targetFile = filePath.replace(/\.(js|ts)$/, '.spec.ts'); } else { targetFile = filePath.replace(/\.(js|ts)$/, '.spec.js'); } const codeLanguage = isTypeScript ? 'typescript' : 'javascript'; return { content: [{ type: 'text', text: `# Migrated Playwright Test ## Original File: ${filePath} ## Target: ${targetFile} ## Format: ${isTypeScript ? 'TypeScript' : 'JavaScript'} ### Migration Summary: ${migration.notes.join('\n')} ### Migrated Code: \`\`\`${codeLanguage} ${migration.code} \`\`\` ### Next Steps: 1. Review the migrated test for any manual adjustments needed 2. Run \`npx playwright test ${targetFile}\` to verify functionality 3. Use 'refactor_to_pom' tool to apply Page Object Model pattern 4. Consider replacing CSS selectors with data-test-id attributes ${isTypeScript ? '5. Ensure tsconfig.json is properly configured for Playwright' : ''} `, }], }; }