cy2pwconvert v1.0.13
cy2pwconvert
A command-line tool to migrate Cypress tests to Playwright, preserving directory structure and converting .js
& .ts
test files automatically.
š Features
ā
Converts Cypress .js
and .ts
test files to Playwright
ā
Preserves the original folder structure
ā
Supports custom source and target directories
ā
CLI-based, install once and use anywhere
ā
Error handling for missing directories
š„ Installation
1ļøā£ Global Installation (Recommended)
npm install -g cy2pwconvert
2ļøā£ Local Installation (Project-based)
npm install --save-dev cy2pwconvert
š Usage
š Convert Cypress Tests (Default Paths)
cy2pwconvert
(Default: ./cypress/integration
ā ./playwright/tests
)
š Convert with Custom Source & Target Directories
cy2pwconvert ./my-cypress-tests ./my-playwright-tests
š Help
cy2pwconvert --help
Options
Usage: npx cy2pwconvert .cypress/ tests/
Arguments:
src Source file or folder
dst Target file or folder
Options:
-V, --version output the version number
-ft, --filetype <filetype> File types to convert default: .js, example: .js,.ts, current support: .js,.ts,.jsx (default: ".js,.ts")
-idp, --installDependency <installDependency> Installs Dependency after project clone (default: false)
-sC, --skipConfig <skipConfig> Skips the config conversion from cypress to playwright (default: true)
-ep, --enablePlugins <enablePlugins> If enabled, this packages takes plugins from babel config file or package file, which comes under plugins key. (default:
false)
-ep, --preserveBDD <preserveBDD> This option will help you to preserve bdd being converted to tdd (default: true)
-h, --help display help for command
š§ How It Works
- Replaces Cypress commands (
cy.visit()
,cy.get()
, etc.) with Playwright equivalents. - Ensures
async/await
syntax for Playwright compatibility. - Converts all
.js
and.ts
test files while maintaining directory structure. - Converts you Cypress config to Playwright config
š Example
Before (Cypress Test)
describe('Login', () => {
it('should log in successfully', () => {
cy.visit('/login');
cy.get('#username').type('admin');
cy.get('#password').type('password');
cy.contains('Submit').click();
cy.get('.dashboard').should('be.visible');
});
});
After (Playwright Test)
test.describe('Login', async ({ page }) => {
test('should log in successfully', async ({ page }) => {
await page.goto('/login');
await page.locator('#username').fill('admin');
await page.locator('#password').fill('password');
await page.getByText('Submit').click();
await expect(page.locator('.dashboard')).toBeVisible();
});
});
š Supported Cypress ā Playwright Config Mappings
ā Supports all Cypress config formats:
- cypress.config.js
- cypress.config.json
- cypress.config.ts (via ts-node)
ā Merges into existing playwright.config.ts
- If the Playwright config already has settings, it preserves them while adding the new ones.
ā Creates a new Playwright config if missing
ā Supports both Playwright JS & TS configs:
- Detects if playwright.config.ts or playwright.config.js exists.
- Merges Cypress settings into the correct file.
ā Handles missing Playwright config:
- If no playwright.config.ts/js exists, it creates a new one based on the detected Cypress format.
ā Automatically formats with Prettier
š Development & Contributions
š§ Local Development
Clone the repo:
git clone git@github.com:arunchaitanyajami/cy2pwconvert.git
cd cy2pwconvert
npm install
š Link for Local Testing
npm link
cy2pwconvert ./cypress/integration ./playwright/tests
Foundation
I took the inspiration from cy2pw
package.
Copied the code and added additional features on top of this code.
Open Source Packages : https://www.npmjs.com/package/cy2pw
š License
MIT License. Feel free to contribute! š
Version Update
v1.0.13
- Support Cypress custom commands.
- Cucumber: Move away from Regx to Babel plugin.