migrate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate to Playwright
迁移至Playwright
Interactive migration from Cypress or Selenium to Playwright with file-by-file conversion.
支持从Cypress或Selenium交互式迁移至Playwright,支持逐文件转换。
Input
输入
$ARGUMENTS- — migrate Cypress test suite
"from cypress" - — migrate Selenium/WebDriver tests
"from selenium" - A file path: convert a specific test file
- Empty: auto-detect source framework
$ARGUMENTS- — 迁移Cypress测试套件
"from cypress" - — 迁移Selenium/WebDriver测试
"from selenium" - 文件路径:转换指定的测试文件
- 空值:自动检测源框架
Steps
步骤
1. Detect Source Framework
1. 检测源框架
Use subagent to scan:
Explore- directory or
cypress/→ Cypresscypress.config.ts - ,
seleniuminwebdriverdeps → Seleniumpackage.json - test files with
.pyimports → Selenium (Python)selenium
使用子代理进行扫描:
Explore- 目录或
cypress/→ Cypresscypress.config.ts - 依赖中的
package.json、selenium→ Seleniumwebdriver - 包含导入的
selenium测试文件 → Selenium(Python版本).py
2. Assess Migration Scope
2. 评估迁移范围
Count files and categorize:
Migration Assessment:
- Total test files: X
- Cypress custom commands: Y
- Cypress fixtures: Z
- Estimated effort: [small|medium|large]| Size | Files | Approach |
|---|---|---|
| Small (1-10) | Convert sequentially | Direct conversion |
| Medium (11-30) | Batch in groups of 5 | Use sub-agents |
| Large (31+) | Use | Parallel conversion with |
统计文件数量并分类:
Migration Assessment:
- Total test files: X
- Cypress custom commands: Y
- Cypress fixtures: Z
- Estimated effort: [small|medium|large]| 规模 | 文件数量 | 处理方式 |
|---|---|---|
| 小型(1-10个) | 顺序转换 | 直接转换 |
| 中型(11-30个) | 按5个一组批量处理 | 使用子代理 |
| 大型(31个以上) | 使用 | 通过 |
3. Set Up Playwright (If Not Present)
3. 配置Playwright(若未配置)
Run first if Playwright isn't configured.
/pw:init如果尚未配置Playwright,请先运行。
/pw:init4. Convert Files
4. 转换文件
For each file, apply the appropriate mapping:
针对每个文件,应用对应的映射规则:
Cypress → Playwright
Cypress → Playwright
Load for complete reference.
cypress-mapping.mdKey translations:
cy.visit(url) → page.goto(url)
cy.get(selector) → page.locator(selector) or page.getByRole(...)
cy.contains(text) → page.getByText(text)
cy.find(selector) → locator.locator(selector)
cy.click() → locator.click()
cy.type(text) → locator.fill(text)
cy.should('be.visible') → expect(locator).toBeVisible()
cy.should('have.text') → expect(locator).toHaveText(text)
cy.intercept() → page.route()
cy.wait('@alias') → page.waitForResponse()
cy.fixture() → JSON import or test data fileCypress custom commands → Playwright fixtures or helper functions
Cypress plugins → Playwright config or fixtures
/ → /
beforebeforeEachtest.beforeAll()test.beforeEach()查看获取完整参考。
cypress-mapping.md核心映射关系:
cy.visit(url) → page.goto(url)
cy.get(selector) → page.locator(selector) or page.getByRole(...)
cy.contains(text) → page.getByText(text)
cy.find(selector) → locator.locator(selector)
cy.click() → locator.click()
cy.type(text) → locator.fill(text)
cy.should('be.visible') → expect(locator).toBeVisible()
cy.should('have.text') → expect(locator).toHaveText(text)
cy.intercept() → page.route()
cy.wait('@alias') → page.waitForResponse()
cy.fixture() → JSON import or test data fileCypress自定义命令 → Playwright fixture或辅助函数
Cypress插件 → Playwright配置或fixture
/ → /
beforebeforeEachtest.beforeAll()test.beforeEach()Selenium → Playwright
Selenium → Playwright
Load for complete reference.
selenium-mapping.mdKey translations:
driver.get(url) → page.goto(url)
driver.findElement(By.id('x')) → page.locator('#x') or page.getByTestId('x')
driver.findElement(By.css('.x')) → page.locator('.x') or page.getByRole(...)
element.click() → locator.click()
element.sendKeys(text) → locator.fill(text)
element.getText() → locator.textContent()
WebDriverWait + ExpectedConditions → expect(locator).toBeVisible()
driver.switchTo().frame() → page.frameLocator()
Actions → locator.hover(), locator.dragTo()查看获取完整参考。
selenium-mapping.md核心映射关系:
driver.get(url) → page.goto(url)
driver.findElement(By.id('x')) → page.locator('#x') or page.getByTestId('x')
driver.findElement(By.css('.x')) → page.locator('.x') or page.getByRole(...)
element.click() → locator.click()
element.sendKeys(text) → locator.fill(text)
element.getText() → locator.textContent()
WebDriverWait + ExpectedConditions → expect(locator).toBeVisible()
driver.switchTo().frame() → page.frameLocator()
Actions → locator.hover(), locator.dragTo()5. Upgrade Locators
5. 升级定位器
During conversion, upgrade selectors to Playwright best practices:
- →
#idorgetByTestId()getByRole() - →
.classorgetByRole()getByText() - →
[data-testid]getByTestId() - XPath → role-based locators
转换过程中,将选择器升级为Playwright最佳实践:
- →
#id或getByTestId()getByRole() - →
.class或getByRole()getByText() - →
[data-testid]getByTestId() - XPath → 基于角色的定位器
6. Convert Custom Commands / Utilities
6. 转换自定义命令/工具
- Cypress custom commands → Playwright custom fixtures via
test.extend() - Selenium page objects → Playwright page objects (keep structure, update API)
- Shared helpers → TypeScript utility functions
- Cypress自定义命令 → 通过实现Playwright自定义fixture
test.extend() - Selenium页面对象 → Playwright页面对象(保留结构,更新API)
- 共享辅助函数 → TypeScript工具函数
7. Verify Each Converted File
7. 验证每个转换后的文件
After converting each file:
bash
npx playwright test <converted-file> --reporter=listFix any compilation or runtime errors before moving to the next file.
转换每个文件后:
bash
npx playwright test <converted-file> --reporter=list在处理下一个文件前,修复所有编译或运行时错误。
8. Clean Up
8. 清理工作
After all files are converted:
- Remove Cypress/Selenium dependencies from
package.json - Remove old config files (, etc.)
cypress.config.ts - Update CI workflow to use Playwright
- Update README with new test commands
Ask user before deleting anything.
所有文件转换完成后:
- 从中移除Cypress/Selenium依赖
package.json - 删除旧配置文件(如等)
cypress.config.ts - 更新CI工作流以使用Playwright
- 更新README中的测试命令
删除任何内容前请先询问用户。
Output
输出
- Conversion summary: files converted, total tests migrated
- Any tests that couldn't be auto-converted (manual intervention needed)
- Updated CI config
- Before/after comparison of test run results
- 转换摘要:已转换文件数量、已迁移测试总数
- 无法自动转换的测试(需要手动干预)
- 更新后的CI配置
- 测试运行结果的前后对比