Lesson 24 / 25

Choosing a Tool and Migrating

Trade-offs and translation tips.

Making the call

Choose Playwright when you need Chromium, Firefox and WebKit from one suite, multiple tabs, windows or origins in a test, free built-in parallelism and sharding, or tests in languages besides JavaScript (it also has Python, Java and .NET bindings). Choose Cypress when your team values its interactive in-browser runner, wants E2E and component tests in one familiar tool, or already has a large Cypress suite. When migrating from Cypress to Playwright, translate concepts rather than lines: cy.visit becomes page.goto, cy.get(...).should(...) becomes await expect(locator)..., cy.intercept becomes page.route, cy.session becomes storageState, custom commands become fixtures or helpers, and cy.task becomes plain Node code in the test.

A translation table

Common equivalents (approximate, not one-to-one).

# Cypress                                  -> Playwright
# cy.visit('/x')                           -> await page.goto('/x')
# cy.get('[data-cy=a]')                    -> page.getByTestId('a')   (with testIdAttribute: 'data-cy')
# cy.contains('button', 'Save')            -> page.getByRole('button', { name: 'Save' })
# .should('have.text', 'Hi')               -> await expect(loc).toHaveText('Hi')
# cy.intercept(...).as('x'); cy.wait('@x') -> page.route(...) / page.waitForResponse(...)
# cy.session(...)                          -> storageState + setup project
# Cypress.Commands.add(...)                -> test.extend fixtures or helper functions
# cy.task('db:reset')                      -> call Node code directly in a fixture
# cy.request(...)                          -> request fixture

Migrate gradually

Run both suites side by side, write new tests in the target tool, and port the most valuable or flakiest old tests first. Delete the old tests once the new ones are trusted.

Quick check: Which requirement points most clearly towards Playwright?

  • Writing tests with Mocha-style describe and it
  • Wanting a test runner that lives inside the browser
  • Testing WebKit, Firefox and Chromium with several tabs in one test
  • Needing assertions on DOM elements
Answer

Testing WebKit, Firefox and Chromium with several tabs in one test — Both tools assert on the DOM; architecture drives the other differences.