QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › Cypress vs Playwright

How would you migrate a project from Cypress to Playwright?

A migration from Cypress to Playwright is done in stages while both stacks live side by side, not as one big rewrite. The stages are an inventory, a pilot, coexistence, and switching Cypress off once coverage has not dropped. Custom commands become fixtures, cy.session becomes storageState, an intercept with an alias becomes waitForResponse created before the action. Risks are two stacks in CI and hidden dependencies between tests.

Cypress · Comparison

You are asked to move 600 tests from Cypress to Playwright without breaking CI. Where do you start?

A migration question checks whether you think in risks, not in a find-and-replace. Rewriting everything in one sprint rarely works, and a half-migrated project without a plan is worse than both options. This lesson gives an order of work and a map of equivalents.

How it works and why. A migration is not a translation of syntax but a transfer of test architecture, so it is done in stages while both stacks live side by side. First an inventory: what the suite covers, which tests are critical, which are flaky, which depend on each other. Then a pilot on 3-5 tests: this is where a shared base appears (config, fixtures, authentication). Then coexistence: new tests are written in Playwright, old ones are moved in batches, starting with the most critical and the flakiest. Only when coverage has not dropped is Cypress switched off.

Migration stages

1. Inventorywhat exists, what is critical, what is flaky2. Pilot3-5 tests and a shared base (config, fixtures)3. Coexistencenew tests in Playwright, old ones move over4. Switch Cypress offonce coverage has not dropped
Figure 1. The idea is not one big rewritten pool but a controlled transition where both test sets run in CI.

You move the architecture, not the lines. A Page Object moves almost directly, but its methods become async. Custom commands turn into fixtures or helpers. cy.session is replaced by storageState with a setup project. Existing data-cy selectors stay if you set testIdAttribute:

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: 'e2e-pw',                 // next to the Cypress folder
  use: {
    baseURL: 'http://localhost:3000',
    testIdAttribute: 'data-cy',      // keep the existing selectors
  },
});

A map of equivalents worth showing the team at the start:

CypressPlaywright
cy.get(sel)page.locator(sel) / getByTestId
cy.contains(text)getByText / getByRole
.should('be.visible')await expect(...).toBeVisible()
cy.intercept + aliaspage.route / waitForResponse
cy.sessionstorageState + setup-project
Custom commandsFixtures, helpers
cy.taskA direct call in the test (Node)
cy.clockpage.clock

Example: the network. Moving the wait for a request breaks most often. In Cypress an alias is created before the action and cy.wait('@stats') waits for it. In Playwright the counterpart is waitForResponse, which must also be created before the action, otherwise the response can be missed:

// Cypress
cy.intercept('GET', '/api/stats').as('stats');
cy.get('[data-cy=period]').select('30d');
cy.wait('@stats');
cy.get('[data-cy=chart]').should('be.visible');

// Playwright
const stats = page.waitForResponse('**/api/stats'); // before the action
await page.getByTestId('period').selectOption('30d'); // data-cy via testIdAttribute
await stats;
await expect(page.getByTestId('chart')).toBeVisible();

Limits and alternatives. Migration risks: two stacks in CI for a while (time and money), team training, implicit dependencies between tests that Cypress hid by serial runs and Playwright will expose in a parallel one. Timeouts and state cleanup also differ, so "the same" test on the new tool may behave differently: that is not a transfer mistake but different models. Automatic converters help with routine work, but the result must be re-read. The alternative is not to migrate at all: if no problem is in the way, keeping Cypress is cheaper.

Typical mistakes.

  • Trying a "big bang": rewriting everything and switching Cypress off in one day.
  • Moving line by line while keeping Cypress habits (chains, cy.wait with a time) instead of idiomatic Playwright.
  • Not defining a success criterion in advance and not knowing when to switch the old suite off.
  • Ignoring dependencies between tests that will surface in a parallel run.

Check yourself

Why is waitForResponse in Playwright created before the action, not after?

Answer

Because if the response arrives before the wait begins, it is missed and the test waits until the timeout. First create the wait, then perform the action, then await it.

What criterion do you measure the migration success by?

Answer

Fewer flaky tests, a faster run thanks to workers, and coverage that has not dropped: every critical scenario from Cypress has a counterpart in the new suite before the old one is switched off.

In the interview. Junior: I would not rewrite everything at once. New tests are written in Playwright, old ones live beside them in CI and are moved gradually. I move the architecture, not the lines: Page Object almost directly but with async, custom commands become fixtures, cy.session becomes storageState, intercept with an alias becomes waitForResponse. Middle/Senior: I start with an inventory and a pilot, then coexistence, and switch Cypress off once coverage has not dropped. The main risks are two stacks at once and hidden dependencies between tests that will surface in a parallel run. I measure success by stability, run speed and coverage, and I also honestly ask whether the migration is needed at all.

More articles in this chapter