Building an AI-Powered Selenium to Playwright Migration Tool With n8n and OpenAI
Your team has 500 Selenium Java tests. Leadership wants Playwright. Manual migration takes months. What if you could use AI to convert 80% of it automatically?
Contents
The Architecture
- Input: Paste Selenium Java test code into an n8n chat interface
- Processing: n8n sends the code to OpenAI with a conversion prompt
- Output: Playwright TypeScript code saved to Google Drive or GitHub
- Validation: Run the generated Playwright code and report results
Common Selenium to Playwright Mappings
| Selenium (Java) | Playwright (TypeScript) |
|---|---|
driver.findElement(By.id("x")) | page.locator('#x') |
driver.findElement(By.xpath("//btn")) | page.getByRole('button') |
WebDriverWait(...).until(visible) | await expect(locator).toBeVisible() |
driver.get("url") | await page.goto('url') |
element.sendKeys("text") | await locator.fill('text') |
element.click() | await locator.click() |
Thread.sleep(3000) | // Remove — Playwright auto-waits |
The Conversion Prompt
Convert this Selenium Java test to Playwright TypeScript.
Rules:
1. Replace all explicit waits with Playwright auto-waiting assertions
2. Use semantic locators (getByRole, getByLabel) instead of XPath/CSS
3. Remove Thread.sleep() calls entirely
4. Convert Page Object to Playwright Page Object pattern
5. Use expect() assertions instead of JUnit/TestNG assertions
6. Add proper TypeScript types
7. Keep the same test logic and coverage
Selenium code:
{input_code}
What AI Cannot Convert (Human Review Needed)
- Custom Selenium Grid configurations — need Playwright parallelization setup
- TestNG data providers — convert to Playwright test.describe with parameterization
- Complex implicit wait patterns — need case-by-case analysis
- Selenium Actions class chains — map to Playwright mouse/keyboard APIs
- Custom WebDriver extensions — rewrite as Playwright fixtures
