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

Cypress

Basics and architecture

how the framework works

What is Cypress and how does it differ from Selenium?

Cypress runs the test inside the browser, in the same run loop as the application, while Selenium drives the browser from outside through WebDriver. So Cypress sees the DOM directly, waits for elements itself through command retries and needs no sleep. The price: only JavaScript or TypeScript, a single browser tab, and what the browser cannot do is handled by a separate Node process.

Cypress · Architecture

A Selenium test fails with a stale element and Cypress does not. Why?

A team migrates a suite from Selenium to Cypress and notices something odd: the sleep(2000) calls between steps are gone and the flakiness dropped. There is no magic, there is a different architecture. This lesson explains where a Cypress test runs, how that differs from Selenium and what follows for writing tests.

How it works and why. Cypress is a framework for e2e and component testing of web apps in JavaScript or TypeScript. According to its documentation it executes in the same run loop as the application, and a Node process runs beside it for what the browser cannot do (files, screenshots, video, part of the network). Selenium, by contrast, drives the browser from outside: the test sends commands to a driver (the WebDriver protocol over HTTP), the driver controls the browser and returns a response.

Where the test runs

Selenium: the test is outsidecommand → HTTP → driver → browserCypress: the test is insidetest and app share one run loop
Figure 1. In Selenium there is a network path between the test and the page, in Cypress the test runs on the page itself.

The decision to "live in the browser" solves concrete problems. The test has direct access to window, document, timers and the DOM, so Cypress sees when the page has loaded, when an element appeared and when a request finished, and can wait by itself. Before an action each command checks the element and retries until the timeout. Time travel follows from the same design: the Test Runner takes a DOM snapshot at every step and lets you go back to it. Under the hood Cypress uses Mocha for describe/it and hooks, Chai for assertions and Sinon for cy.stub, cy.spy and cy.clock.

Example: from sleep to automatic waiting. A typical Selenium test ported one to one, and its weak spot:

Typical

Selenium: sleep between steps

A 2-second pause is slow and on a slow CI still not enough. A found element can go stale if the DOM was redrawn between the lookup and the action.

Better

Cypress: waiting inside the command

The command and the assertion are retried until the condition holds, and the element is queried from the DOM again on every attempt.

The same thing in Cypress has no pause at all:

it('login leads to the dashboard', () => {
  cy.visit('/login');
  cy.get('[data-cy=email]').type('qa@example.com');
  cy.get('[data-cy=password]').type('secret');
  cy.contains('button', 'Sign in').click();
  // retried until it passes or the timeout ends
  cy.url().should('include', '/dashboard');
});

Nothing waits explicitly: cy.get looks for the element until it appears, .click() waits until the element is clickable and should retries the check of the URL. The network calls the front end makes for data can also be watched with the built-in cy.intercept. That is why flakiness drops: the test does not guess the time, it describes the expected state.

Limits and alternatives. The same architecture brings limits. Tests are written only in JavaScript/TypeScript. The test lives inside one browser tab, so many tabs or windows at once are not available, and several origins in one test need cy.origin. Among supported browsers the documentation names the Chrome family (Chrome, Chromium, Edge) and Firefox; Safari itself is not supported (an experimental WebKit exists). Electron, still the default browser of cypress run, is deprecated as a test browser in Cypress 16 and will be removed in a future major version. If you need several users in different tabs, another language or real Safari, choose Playwright or Selenium.

In Playwright:

Playwright also avoids WebDriver but works the opposite way to Cypress: it drives the browser from outside over one persistent connection and the browser's native protocol (CDP for Chromium, patched protocols for Firefox and WebKit). Tests can be written not only in JS/TS but in Python, Java and .NET.

Common mistakes.

  • Adding cy.wait(2000) "just in case", as a habitual sleep: the test gets slower and the flakiness stays.
  • Writing await cy.get(...) or storing a command result in a variable as in ordinary async code: Cypress commands are queued and do not return a value right away.
  • Expecting several tabs or Safari from Cypress: that is a limit of its architecture, not a configuration mistake.
  • Treating Cypress as "just Selenium with a better API": a different execution model means different approaches to waiting, network and data.

Check yourself

A colleague ports a Selenium test and leaves cy.wait(3000) after every click. The test is green. What is the problem and what should replace it?

Answer

The test passes but is slow and can still fail on a slow environment, because a fixed pause does not depend on the state of the app. Cypress already waits by itself: lookup commands and assertions are retried until the timeout. Replace the pause with an assertion on the expected state, for example cy.url().should(...) or cy.get(...).should('be.visible'), or wait for a request through an alias from cy.intercept.

Why does Cypress have direct DOM access and Selenium does not, and what is the price?

Answer

Cypress runs in the same run loop as the app, so it sees window and the DOM with no protocol between. The price: the test is tied to one browser tab and to JS/TS, several origins need cy.origin, and what the browser cannot do (files, a database) is done by a separate Node process through cy.task.

In an interview. Junior: Cypress is a framework for e2e and component testing in JavaScript. The main difference from Selenium is that Selenium drives the browser from outside through WebDriver, while Cypress runs tests right in the browser next to the app. So it waits for elements itself, gives time travel for debugging and can intercept the network. Inside it runs on Mocha, Chai and Sinon. Middle/Senior: The architecture choice defines both the strengths and the limits. A test in the browser gives direct DOM access, built-in retries and fast feedback, but ties you to one tab, JS/TS and the browsers Cypress supports. So for scenarios with several tabs, another language or Safari I pick Playwright, and for UI tests that favour development and debugging, Cypress.

How is the Cypress architecture built under the hood?

Cypress consists of a Node process and a browser in which the test and the application live in one tab, in two iframes. The Node process launches the browser and does what the browser cannot: files, cy.task, screenshots, video, and a WebSocket connects the two. Test code is browser code with no Node modules, and cy commands are queued and run later with retries. A different origin needs cy.origin.

Cypress · Architecture

Reading a file in a Cypress test fails with fs is not defined. Where does this code actually run?

A tester adds import fs from 'fs' to a test to read a data file and gets an error, because the browser has no such module. The same code would work in Playwright. The reason is that a Cypress test runs in the browser, not in Node. This lesson covers what Cypress consists of, how its parts communicate and what that means in practice.

How it works and why. Cypress consists of two parts that constantly talk to each other. The first is the Node process: it launches the browser, does what the browser cannot (the file system, cy.task, screenshots, video) and takes part in the network. The second is the browser. In the Test Runner the Cypress page contains two iframes: the spec iframe with the test code and the command queue and the app iframe with the application. They sit in one tab, so the test sees the DOM of the app with no protocol in between. A WebSocket connects the Node process and the browser.

The two parts of Cypress

Browser, one tabspec iframetest + cy queueapp iframethe applicationthe test sees the app DOM directlyWebSocketCypress Node processcy.task · files · screenshots · video
Figure 1. The test and the app are neighbours in the browser, and everything that needs more privileges is done by the Node process.

This layout explains two things. First, cy.* commands are only queued while the test runs and are executed later, one by one, with retries. So they do not return a value and await is not needed. The section on asynchrony explains why. Second, the test runs in the same origin and under the same browser security rules as the app. For several origins in one test there is cy.origin: it runs its block of code in the context of the second origin. Since Cypress 14 another subdomain (app.example.com and auth.example.com) is also another origin, so it needs cy.origin too. Everything the browser cannot do (read files, reach a database) is done in Node through cy.task.

Example: from fs to cy.task. An attempt to read a file in a test:

import { readFileSync } from 'node:fs'; // not in the browser
const seed = readFileSync('seeds/orders.json', 'utf8');

A Node module does not work in browser code, and the test bundle fails to build or fails at runtime. The right way: move the action into the Node process and call it from the test. The task is described in the config in setupNodeEvents and the test reaches it through cy.task:

// cypress.config.ts
import { defineConfig } from 'cypress';
import { readFileSync } from 'node:fs';

export default defineConfig({
  e2e: {
    setupNodeEvents(on) {
      on('task', {
        // runs in Node, not in the browser
        readSeed: (name: string) =>
          JSON.parse(readFileSync('seeds/' + name + '.json', 'utf8')),
      });
    },
  },
});

// in the test
cy.task('readSeed', 'orders').then((orders) => {
  cy.log('orders: ' + (orders as unknown[]).length);
});

Data between the browser and Node travels as serialised values, so functions or complex objects will not pass. Other actions outside the browser work the same way: a screenshot on failure, video, writing to a file or a database query.

Where network interception happens. cy.intercept sees and replaces the app's requests, but the path depends on the browser. According to the Cypress 16 changelog, in Chrome, Chromium and Edge traffic is intercepted on the browser's native network, while Firefox, WebKit and Electron keep the old path through a proxy in Node.

Where test traffic goes

Chrome family

Chrome, Chromium, Edge

Since Cypress 16 test traffic is intercepted on the browser’s own native network.

Others

Firefox, WebKit, Electron

As before: traffic goes through a proxy in the Node process. The forceHttp1 option (deprecated from the start, a temporary workaround) turns this path on for every browser.

Figure 2. Consequence for QA: interception behaviour can differ between browsers, so check key scenarios in the browser CI uses.
In Playwright:

Playwright has no iframe with the test next to the app. The test lives in Node and the Playwright server sends commands to the browser through a protocol. So the test has no direct DOM access (only through page.evaluate), but works freely with several tabs, domains and contexts.

Limits and alternatives. A test in the browser does not see what is outside the page: a second tab, the browser window, system dialogs. Cypress works in one tab, and several origins require cy.origin with its rules (data between contexts is passed explicitly). For files, a database, email and services outside the browser you need the Node process with cy.task. If "two users at the same time" is the main scenario, the Playwright architecture fits better.

Common mistakes.

  • Importing Node modules (fs, path with file calls, a database driver) into a test: it is browser code. Use cy.task.
  • Passing functions or classes to cy.task: arguments and results are serialised, so return plain data.
  • Expecting cy.get to return the element at once: the command is only queued.
  • Assuming cy.intercept behaves the same in every browser: Chrome-family browsers and Firefox use different interception paths.

Check yourself

A test calls fs.readFileSync and fails. Why would this work in Playwright but not in Cypress, and what should you do?

Answer

A Playwright test runs in Node, so fs is available. A Cypress test runs in the browser, which has no Node modules. Move the action into the Node process: describe a task in setupNodeEvents through on('task', ...) and call it from the test as cy.task('name', argument). Data is passed serialised.

What does it mean that the spec iframe and the app iframe live in one tab, and what follows for the DOM?

Answer

The test and the app share one browser context, so the test code can read the app DOM directly with no protocol in between. A side effect: this also explains why there is one tab and why another origin needs cy.origin.

In an interview. Junior: Cypress works as two processes. The Node process launches the browser and does what the browser cannot, such as working with files or a database through cy.task. In the browser itself two iframes live in one tab: the test and the app, so the test sees the DOM directly. A WebSocket connects Node and the browser. Middle/Senior: It follows that the test code is browser code with no Node modules, cy commands are queued and run with retries, and everything privileged goes through cy.task. Network interception depends on the browser: in Cypress 16 it goes through the browser's native network for Chrome-family browsers and through a Node proxy for Firefox, WebKit and Electron. So I check cy.intercept behaviour in the browser CI uses.

How does cypress open differ from cypress run?

cypress open opens an interactive Test Runner for writing and debugging, while cypress run executes tests without a UI for CI. The modes differ in browser, window size, machine resources and retries: retries.runMode and retries.openMode. Run prints results to the console and takes a screenshot on failure. When a test is green locally and red in CI, reproduce the CI mode with cypress run in the same browser.

Cypress · Architecture

A test is green in cypress open but fails in CI. What changed between the two runs?

A developer writes a test in the interactive window, sees green steps and pushes. In CI the same test goes red. Often the cause is not the test code but the run mode: open and run differ in browser, retries, UI and what is available after a failure. This lesson explains what each mode is for and what to check when the results diverge.

How it works and why. cypress open opens the interactive Test Runner: you pick a spec, see every command in the Command Log, can go back to any step (time travel) and the test reruns when you save the file. This is the mode for writing and debugging. cypress run runs tests with no UI, prints the result to the console and takes a screenshot on failure. This is the mode for CI. The difference is deliberate: a person needs feedback, a machine needs a fast and repeatable run.

Two run modes

cypress open

For writing and debugging

Interactive Test Runner, time travel through steps, a rerun after you save a file. Retries are 0 by default.

cypress run

For CI and batch runs

No UI, console output, screenshots on failure. retries.runMode applies here if set.

Figure 1. The modes differ not only in UI: the defaults for retries and the browser can be different.

In run with no flags tests run headless in Electron, but since Cypress 16 Electron is deprecated as a test browser and will be removed in a future major version. So in CI it is better to name the browser explicitly: --browser chrome or defaultBrowser in the config. Retries are set separately per mode: retries.runMode and retries.openMode. Video is turned on with the video option, and run takes screenshots on failure.

Example: a gap between open and run. The main commands:

npx cypress open                      # interactive
npx cypress run                       # headless, all specs
npx cypress run --browser chrome      # a specific browser
npx cypress run --spec "cypress/e2e/login.cy.ts"
npx cypress run --headed              # with the browser window

The test passes in open, in Chrome, on a laptop with a wide screen and a fast network, while CI runs it in a different browser with a different window size on a slower machine. Diagnosis starts with equalising conditions, not with editing the test:

  • run the same cypress run --browser <the CI browser> locally to reproduce the CI mode;
  • check the viewport and window size in the config, because responsive layout changes elements;
  • look at the screenshot and the failure log that run produces;
  • remember retries: in run the test may have failed several times and passed, so it is flaky, not green.

A config that tells the modes apart:

export default defineConfig({
  e2e: {
    // no retries in open, up to two in run
    retries: { runMode: 2, openMode: 0 },
  },
});

Different values for open and run make sense: in development retries mask a problem, in CI they reduce noise. But a test that passes only on a retry must be fixed, not ignored.

In Playwright:

The analogue is npx playwright test, headless by default. Instead of a Test Runner there is --ui (UI mode with a timeline and DOM snapshots), --debug with the inspector and --headed. Browsers are chosen with --project, not --browser.

Limits and alternatives. Interactive mode does not replace CI: it does not guarantee the same conditions (browser, window size, machine resources). run gives screenshots and a log but no interactive debugging: for that, reproduce the failure in open with the same data. For quick review in CI, video and artifacts are useful, stored as build artifacts.

Common mistakes.

  • Checking a test only in open and not running run locally before a push.
  • Relying on the default browser in CI: after version changes it may become a different one.
  • Treating a test as green when it passed in run only with a retry.
  • Setting the same retries for open and run: in development they hide flakiness.

Check yourself

A test passes in cypress open but fails in CI on a button click. Which three differences between the runs do you check first?

Answer

The browser (CI may use another), the window size/viewport (responsive layout can hide the button) and the speed and resources of the machine (slower loading). Then the failure screenshot from run, and a local reproduction through cypress run with the same browser.

In CI a test is marked passed, but the log shows it failed twice. What does that mean?

Answer

retries.runMode kicked in: the test was rerun and passed. It is formally green but unstable, because the result depends on a retry. It must be investigated as flaky, not trusted as reliable.

In an interview. Junior: Open is the interactive mode for development: I see every command, can go back to any step and the test reruns on save. Run is the headless mode for CI: no UI, console output and screenshots on failure. In run you can choose the browser, a specific spec or headed mode. Middle/Senior: The modes differ not only in UI but in conditions: the browser, retries.runMode versus openMode, the window size. So when a test is green locally and red in CI I reproduce the CI mode with cypress run in the same browser. Electron as a test browser is deprecated in Cypress 16, so in CI I set the browser explicitly.

What do the project structure and the Cypress config look like?

Since version 10 the Cypress config lives in code, in cypress.config.js or .ts, and cypress.json is no longer used. It has separate blocks for e2e and component, plus baseUrl, specPattern, defaultCommandTimeout, retries and setupNodeEvents, which runs in Node. Tests live in cypress/e2e, data in cypress/fixtures, shared code in cypress/support. A mistake in specPattern produces the symptom «no specs found».

Cypress · Architecture

The project holds a cypress.json that the docs you read never mention. Why?

A newcomer clones an old tutorial project, sees cypress.json and integration instead of e2e, and the new Cypress version finds no tests at all. The structure changed: since version 10 the config moved into code. This lesson explains what lives where now, what the main settings mean and how to tell a modern answer from an outdated one.

How it works and why. Since version 10 the config lives in a cypress.config.js or .ts file, and the old cypress.json is no longer used. The config is code that Node executes before the run, so imports, conditions and reading environment variables work there. It has separate blocks for e2e and component: different test types have different specs, dependencies and settings. The rest of the project is simple: cypress/e2e for tests, cypress/fixtures for data, cypress/support for shared code loaded before every spec.

What lives where in the project

cypress.config.tsdefineConfig, e2e and component, Node logiccypress/e2etests *.cy.tscypress/fixturesJSON with test datacypress/supporte2e.ts, commands.ts: shared by specs
Figure 1. The config in the root drives everything, and the cypress subfolders separate tests, data and shared code.

The support/e2e.ts file runs before every spec, so custom commands and global hooks are registered there. In the config, setupNodeEvents runs in Node, not in the browser: this is where cy.task and event subscriptions are described. The baseUrl setting makes cy.visit('/') short and lets you change the environment in one place.

Example: from cypress.json to a modern config. The old file had flat keys and an integration folder. The modern equivalent:

// cypress.config.ts
import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    baseUrl: 'https://staging.example.com',
    specPattern: 'cypress/e2e/**/*.cy.ts',
    defaultCommandTimeout: 6000,
    retries: { runMode: 2, openMode: 0 },
    setupNodeEvents(on, config) {
      // cy.task, plugins, reports: this is Node
      return config;
    },
  },
});

Now each line is visible. baseUrl lets you write cy.visit('/login'). specPattern says which files count as tests: if it is wrong, Cypress "does not see" specs. defaultCommandTimeout sets how long a lookup command is retried. retries configures rerunning failed tests separately for run and open. Shared logic lives in support, and the test just calls it:

// cypress/support/commands.ts
Cypress.Commands.add('login', (email: string, password: string) => {
  cy.request('POST', '/api/login', { email, password });
});

// cypress/e2e/profile.cy.ts
it('opens the profile', () => {
  cy.login('qa@example.com', 'secret'); // baseUrl from the config
  cy.visit('/profile');
});

This structure keeps a test short and readable: login, data and settings are moved out, and the test itself describes behaviour.

In Playwright:

The config is playwright.config.ts. Instead of separate e2e and component blocks there are projects: different browsers, devices, a setup project for login. There is no support folder: shared logic lives in fixtures through test.extend.

Limits and alternatives. A config in code is flexible but easy to make tangled: sensitive values should not be hard-coded, pass them from environment variables (with the CYPRESS_ prefix or through --env) or CI. Settings that depend on the environment are better returned from the config by a function than by copying files. The folder layout can be changed through specPattern and supportFile, but the default layout eases onboarding, so deviate with a reason.

Common mistakes.

  • Looking for or creating cypress.json in a modern project: in 10+ it is ignored.
  • A wrong specPattern: the tests sit in a folder the pattern does not cover and Cypress says there are no specs.
  • Putting secrets and passwords in a config that lands in the repository.
  • Mixing Node logic (reading files) into test code instead of setupNodeEvents and cy.task.
  • Raising defaultCommandTimeout instead of fixing the wait: it masks the real cause.

Check yourself

After an upgrade Cypress says it found no specs although *.cy.ts files exist. Where do you look for the cause?

Answer

In the config: specPattern should cover the folder with the tests (by default cypress/e2e/**/*.cy.{js,jsx,ts,tsx}), and the old cypress.json is ignored in version 10+. I check that the settings are in cypress.config.ts in the e2e block and that the pattern matches the real location of the files.

Where does code in the config run: in the browser or in Node, and what follows for cy.task?

Answer

Everything in cypress.config.ts, setupNodeEvents included, runs in Node. That is why the tasks for cy.task are described there: they can reach files and a database, and the test in the browser calls them by name.

In an interview. Junior: Since version 10 the config is written in cypress.config.ts through defineConfig, with separate blocks for e2e and component testing. It sets baseUrl, the spec search pattern, timeouts, retries and setupNodeEvents for Node logic. Tests live in the e2e folder, test data in fixtures, and custom commands and global setup in support. Middle/Senior: The config is code that runs in Node, so I take secrets from environment variables and handle environment differences with a function rather than file copies. A cypress.json in a modern project signals outdated knowledge or an unfinished migration. A wrong specPattern shows up as "no specs found", so I check it first.

How do e2e tests differ from component testing in Cypress?

An e2e test walks a scenario through the whole application, while component testing mounts a single component with cy.mount in isolation. Component tests are fast, isolated and good for trying states and props, but do not catch integration problems with the backend and routing. So component states are checked with component tests, and the main end-to-end paths stay with e2e.

Cypress · Architecture

To check a discount on a price, a test logs in, opens the catalog and the cart. Isn’t that too long?

A team has an e2e test for one button that walks half the app: login, catalog, cart. It is slow, breaks from unrelated changes and checks a small thing. Cypress offers a second kind of test in which such a component state is checked on its own. This lesson explains the difference between e2e and component testing and how to choose the kind of test.

How it works and why. E2E opens the whole application through cy.visit and walks a scenario like a user, with a real backend or network mocks. Component testing mounts one React, Vue or Angular component through cy.mount in a real browser, without the rest of the app. The browser and commands are the same, but the test subject differs: a page versus a component. So component testing is fast and isolated: handy for checking states of a button, form or table with different props without starting the whole front end.

Two kinds of tests in Cypress

E2E

The whole application

cy.visit opens the page and the test walks a scenario like a user, with a real backend or network mocks. Slower, closer to reality.

Component

One component

cy.mount mounts a React, Vue or Angular component in a real browser without the rest of the app. Fast and isolated.

Figure 1. They are not rivals: e2e confirms the app works together, component tests check the details.

They are configured separately: the config has an e2e block and a component block, and for components you also say how to build them (framework and bundler) and register mount in the support/component.ts file.

Example: moving a check from e2e to a component test. Before:

// E2E: to see a discount we walk half the app
it('shows the discount in the cart', () => {
  cy.login('qa@example.com', 'secret');
  cy.visit('/catalog');
  cy.get('[data-cy=product-42]').click();
  cy.get('[data-cy=add-to-cart]').click();
  cy.visit('/cart');
  cy.get('[data-cy=final-price]').should('have.text', '80');
});

The test checks one thing, the final price calculation, but depends on login, the catalog, the cart and the data on the environment. If any step fails, the test is red although the component itself is fine. After: the same calculation is checked on the component with the needed props.

// a component test
import { PriceTag } from './PriceTag';

it('shows the discount', () => {
  cy.mount(<PriceTag price={100} discount={20} />);
  cy.get('[data-cy=final-price]').should('have.text', '80');
});

The test runs in seconds, does not depend on the backend and easily covers edge cases: zero discount, a fractional price, very large numbers. The config for components:

export default defineConfig({
  component: {
    // how components are built: framework and bundler
    devServer: { framework: 'react', bundler: 'vite' },
  },
});

E2E keeps what a component cannot prove: that login, the catalog and the cart work together. Such a split forms a practical pyramid: many fast component tests and a few end-to-end ones for the main paths.

In Playwright:

In Playwright component testing is now built in: component tests are regular @playwright/test tests with the mount fixture, and the experimental @playwright/experimental-ct-* packages were removed and are no longer published. In Cypress CT has long been stable, with official adapters for React, Next.js, Vue and Angular (Svelte is still in alpha).

Limits and alternatives. A component test does not check integration with a real backend, routing and the page as a whole: that is e2e's job. It needs a configured build (a bundler) and may need mocks for contexts or services the component expects. If a component is hard to mount alone, that signals heavy dependencies. For pure logic with no DOM, plain unit tests are faster.

Common mistakes.

  • Checking every small UI detail with an e2e test: slow and brittle.
  • Expecting a component test to catch integration problems with the backend or routes.
  • Forgetting to register mount in support or to configure devServer: the test will not build.
  • Using component tests as a replacement for e2e: the main user paths still need an end-to-end check.

Check yourself

Which kind of test do you choose to check that a button is disabled when a form is empty, and why?

Answer

A component one: the button state depends only on the component props and internal state, and cy.mount lets you mount it without login and a backend and quickly go through variants. E2E here is slower and depends on unrelated steps.

A component test of a payment form is green, but in production payment fails because of a wrong request URL. Why did the test not catch it?

Answer

The component is mounted apart from the real app and backend: integration with routes and the API was not checked. That is e2e territory (or a test with network interception) for the main payment path.

In an interview. Junior: An e2e test opens the whole app and walks a scenario like a user. Component testing mounts a separate component through cy.mount in a real browser, without the rest of the app and without a backend. It is much faster and handy for checking different component states, while e2e stays for key end-to-end scenarios. Middle/Senior: I split by what the test must prove: states and edge cases of one component go to component tests, integration and end-to-end paths to e2e. CT needs a component build (devServer with a framework and a bundler) and mount in support, and its drawback is that without a real backend and routes it does not catch integration problems.

Cypress architecture and a comparison

The main difference is where the test runs: Cypress runs in the browser, while Selenium and Playwright drive it from outside. That gives Cypress direct access to the DOM, time-travel, built-in waiting and retries. It also brings limits: only JavaScript or TypeScript, one tab, and cy.origin for several origins. For scenarios with several users or tabs, another language or built-in parallelism, Playwright is the choice.

Cypress · Architecture

You are asked: “Cypress or Playwright?”. Which single difference do you name first?

In an interview the question about choosing a tool almost always comes down to one thing: where the test runs. Everything else, from several tabs to parallelisation, follows from that answer. The closing lesson of the chapter gathers the Cypress architecture in comparison with Selenium and Playwright, so that the answer sounds like a conclusion and not a list.

How it works and why. Cypress runs tests inside the browser, in the same run loop as the application, and a Node process works beside it for tasks outside the browser. Selenium and Playwright drive the browser from outside: Selenium through WebDriver, Playwright through CDP and its own protocols. Because of this architecture Cypress has direct access to the DOM, window and the app's network requests, while the test code runs in the browser, so Node capabilities are reached through cy.task.

Where the test runs in three tools

Seleniumoutside: every command an HTTP requestPlaywrightoutside: one persistent connectionCypressinside the browser + Node beside it
Figure 1. One architectural decision explains most of the differences asked about in interviews.

What this gives and what it takes. Cypress strengths: a convenient interactive runner with time-travel snapshots of every step, built-in retries and waiting, an easy start, cy.intercept for the network, component testing. Limits: only JavaScript/TypeScript, one tab, harder work with iframes and several origins (through cy.origin), no Safari support (only experimental WebKit).

CypressPlaywrightSelenium
Test runsin the browserin Nodein the test process
LanguagesJS/TSJS/TS, Python, Java, .NETmany
Tabsoneseveralseveral
Safari/WebKitexperim. WebKitWebKitvia Safari driver

Example: deriving an answer from the architecture. Task: test a chat where two users write at the same time. In Cypress the test lives in one tab, so the second user has to be emulated through the API or a separate run, which is awkward. In Playwright these are two contexts in one test. On the other hand, when a team writes in JS and values fast interactive feedback while building the UI, Cypress gives time travel and a clear Command Log. The conclusion is derived from the architecture, not from preference.

The same goes for parallelisation. In Playwright it is built in (workers and sharding). Cypress runs specs in parallel through Cypress Cloud (the --parallel option with recording) or by splitting specs manually between CI jobs.

In Playwright:

It supports several tabs, contexts and languages besides JS, and parallelisation is built in with no paid service. In exchange there is no interactive runner that runs inside the application: its role is played by UI mode and the Trace Viewer.

Limits and alternatives. Comparisons age fast: versions change and tools converge (for example, in Cypress 16 the network interception path changed and Electron became deprecated). So build the answer on the principle and check specific features against the documentation. The choice also depends on the team: languages, existing code, the need for other browsers and tabs, the budget for parallelisation.

Common mistakes.

  • Answering with a list of features and no mention of architecture: it sounds memorised.
  • Claiming Cypress "does not support iframes or several origins": it does, with limits and extra commands.
  • Naming outdated facts or missing changes: cypress.json instead of cypress.config, Electron in CI without an explicit --browser although it is deprecated in Cypress 16.
  • Believing one tool is always better: the choice depends on the task.

Check yourself

A test needs two users in different tabs at the same time. Which tool fits better and why?

Answer

Playwright: its test lives in Node and drives several browser contexts. A Cypress test runs in one tab, so the second user can only be emulated through the API or separate runs.

How do you explain in two sentences that Cypress "has direct DOM access"?

Answer

The test runs in the browser in the same run loop as the app, so it sees window and the DOM directly with no protocol between. This gives automatic waiting and time travel but ties the test to one tab and to JS/TS.

In an interview. Junior: Cypress runs tests inside the browser next to the app, while Selenium and Playwright drive it from outside. So Cypress has direct DOM access, a convenient interactive runner and built-in waiting, but only JS/TS, one tab and no Safari. Middle/Senior: I derive all the differences from one decision, where the test lives. For scenarios with several users or tabs, another language or parallelisation with no paid service I pick Playwright, and for UI tests of a JS team with an emphasis on debugging and component testing, Cypress. Version facts, such as the changes in Cypress 16, I check against the documentation.