Lesson 2 / 25

Playwright Versus Cypress Architecture

Outside the browser versus inside it.

Two different designs

Playwright (from Microsoft) runs your tests in a Node.js process and drives the browser from outside over automation protocols. It ships its own builds of Chromium, Firefox and WebKit, so one suite can cover the three major engines, and it can control several pages, tabs, browser contexts and origins in one test. Cypress runs your test code inside the browser, in the same run loop as the application, with a Node.js process alongside for file system and network work. That gives it direct access to the app, a rich interactive runner with time-travel snapshots, and simple synchronous-looking commands, but historically means one browser tab per test and extra steps (such as cy.origin) for multiple origins. Cypress supports Chrome-family browsers, Firefox and Electron, with WebKit support marked experimental (check the docs for your version).

The same check in both tools

Playwright uses async/await; Cypress enqueues commands.

// Playwright: tests/home.spec.ts
import { test, expect } from '@playwright/test';

test('home page shows the product name', async ({ page }) => {
  await page.goto('/');
  await expect(page.getByRole('heading', { name: 'Acme Tasks' })).toBeVisible();
});

// Cypress: cypress/e2e/home.cy.ts
describe('home page', () => {
  it('shows the product name', () => {
    cy.visit('/');
    cy.contains('h1', 'Acme Tasks').should('be.visible');
  });
});

Pick by constraints, not hype

Need WebKit/Safari coverage, multiple tabs or several origins in one test? Playwright fits naturally. Want an in-browser runner your front-end team already knows, plus component testing in the same tool? Cypress is strong there. Both are mature and well documented.

A remote control versus a passenger

Playwright holds a remote control and operates the browser from the sofa; Cypress sits in the passenger seat inside the car, seeing everything the app sees but sharing its seat belt.

Quick check: Where does Cypress execute your test code?

  • Inside the browser, alongside the application under test
  • Only in a separate Node.js process over a remote protocol
  • On a cloud service that must be paid for
  • Inside the web server that hosts the app
Answer

Inside the browser, alongside the application under test — This in-browser design is the main architectural difference from Playwright.