Cypress
A runner that loads inside the page it tests: commands queue and re-run themselves, and every step leaves a DOM snapshot you can step back to. Interviewers probe how that placement shapes every test.
on this pageshowhide
explore
- Test Runner and Commands44 questions
- Chain Construction15 questions
- Retry-Ability9 questions
- Setup and Cleanup10 questions
- Driving the Page10 questions
- Selectors and Assertions29 questions
- Finding Elements20 questions
- Expectation Styles9 questions
- Network Stubbing and Intercept25 questions
- Request Matching15 questions
- Reply Shaping10 questions
- Fixtures and Custom Commands25 questions
- Canned Inputs10 questions
- Shared Helpers15 questions
- Component Harness20 questions
- Mount and Teardown5 questions
- Passing Props and Spying5 questions
- Styles and Assets5 questions
- Real Browser Cost5 questions
- Pipeline Orchestration25 questions
- Unattended Execution10 questions
- Scaling a Run15 questions
- In-Browser Runtime30 questions
- Paired Processes14 questions
- Hard Ceilings16 questions
- Config and Node Events20 questions
- Settings File Layout5 questions
- Exposed Values and Secrets5 questions
- Task Round-Trips5 questions
- Sandbox Reach Limits5 questions
- Debugging and Diagnostics21 questions
- Command Log Time Travel4 questions
- Stepping Through a Run6 questions
- Saved Failure Media6 questions
- Snapshot Fidelity Limits5 questions
- Choosing and Moving17 questions
- Running Inside the Page4 questions
- One Language Only4 questions
- Porting Specs Across Runners5 questions
- Fit and Misfit Cases4 questions
questions
256 · 10 sectionsIn Cypress, what does `.click()` check about an element before it fires the click?
basics
~20 sCypress re-runs a fixed readiness list before every action: it scrolls the element into view, then requires it to be attached, visible, enabled, not readonly, not animating and not covered at the point the event will land.
In Cypress, what does `.type()` do with text wrapped in curly braces?
basics
~20 sCypress reads curly braces in .type() as special key sequences rather than literal characters, so {enter} presses Enter and {selectall} selects the field. An unrecognised sequence throws. Type a literal brace with {{}, or pass the option parseSpecialCharSequences: false.
In Cypress, what does `const rows = cy.get('[data-cy=book-row]')` put into `rows`?
basics
~20 sA Cypress chainer object: a handle you use to append more commands to that chain. It holds no element and no jQuery data, because at the moment the assignment runs cy.get() has only been queued, not executed.
In a Cypress test, when do the cy commands in the test body actually run?
basics
~20 sCypress commands do not run when you call them. Each cy call only appends a step to an internal command queue and returns immediately; Cypress drains that queue, one step at a time, after the test body function has returned.
In Cypress, what does cy.wrap() do, and when do you need it?
basics
~20 scy.wrap() starts a Cypress chain whose subject is the value you hand it - a plain object, a number, a jQuery element or a promise - so queries, .should() assertions, .its() and .invoke() can run against it.
In Cypress, how do you write an `expect()` assertion inside a `.then()` callback?
basics
~10 sCypress makes Chai's expect and assert global in every spec, so inside .then(($rooms) => ...) you call expect($rooms).to.have.length(4) straight on the yielded subject. A throw from that expect fails the test at that command.
In Cypress, what does .should('have.text', 'Deluxe King') do when chained onto cy.get()?
basics
~10 sIt attaches a Chai-jQuery assertion to the preceding cy.get(), and Cypress keeps re-evaluating the query and the check until the element's text matches or the four-second default command timeout expires, then fails the test.
In Cypress, how do you find an element by its `data-cy` test attribute?
basics
~20 sPass a CSS attribute selector to cy.get(), as in cy.get('[data-cy="room-card"]'). Cypress ships no dedicated test-id command: the attribute is ordinary markup and the selector is ordinary CSS, matched the way jQuery's $() matches, with data-cy carrying no special status.
In Cypress, why does a re-render detach the element your chain already holds?
basics
~20 sA Cypress chain carries a concrete DOM node, not the selector that found it. A re-render throws that node away and mounts a fresh one, so the node your chain still holds is no longer in the document.
In Cypress, what does `cy.get('.room-card')` yield when the page renders 12 room cards?
basics
~20 sOne jQuery-wrapped collection holding all 12 room-card elements, not a single DOM node and not an array. Its length is 12, and the whole set becomes the subject the next command in the chain receives.
In Cypress, what does `cy.wait('@getForecast')` yield to the next command?
basics
~20 scy.wait on an intercept alias yields one interception object for that request-response cycle: request and response, plus id, routeId, and an error property when the request failed. Chain .its() or .then() to assert on it.
What are the three ways to call Cypress's `cy.intercept()`, and what does each match?
basics
~10 sCypress accepts cy.intercept(url), cy.intercept(method, url) and cy.intercept(routeMatcher). A bare url matches every HTTP method; the method form narrows it to one; the routeMatcher object matches fields such as pathname, query and headers together.
In Cypress, what turns a `cy.intercept()` route from a spy into a stub?
basics
~20 sThe response argument. A Cypress cy.intercept('GET', '/api/forecast') with no second argument only spies, and the request still reaches the real server. Supply a StaticResponse, a plain body, or a handler that calls req.reply() and Cypress answers it instead.
In Cypress, how does a `cy.intercept()` 500 stub differ from `forceNetworkError`?
basics
~20 sA 500 stub sends a real HTTP response the application can read, so its status and error body are available. forceNetworkError destroys the browser connection instead: no status, no headers, no body, and the app's fetch rejects.
In Cypress 16, why is `req.httpVersion` undefined inside a `cy.intercept()` handler in Chrome?
basics
~20 sBecause Chrome, Chromium and Edge now intercept on the native browser network. The browser negotiates the protocol with your server directly, and that is not known when the request is paused, so Cypress reports no value rather than a wrong one.
Cypress 16 removed cy.exec() - how do you run a setup command now?
basics
~20 scy.exec() was removed in Cypress 16 and now throws; use cy.task() instead, calling a handler registered under the task event in setupNodeEvents. The execTimeout option was removed with it, and taskTimeout, default 60000 ms, replaces it.
In Cypress, how does cy.fixture('receipts') resolve a file with no extension?
basics
~20 sCypress joins the path onto fixturesFolder, which defaults to cypress/fixtures. If that exact file exists it is read; otherwise Cypress tries a fixed extension list, .json first, and yields the first match, parsed according to that extension.
Cypress has no built-in cy.mount(): how do you make it available to every component spec?
basics
~10 sCypress ships no cy.mount command. You import mount from a framework adapter - cypress/react, cypress/vue, cypress/angular or cypress/svelte - and register it once with Cypress.Commands.add('mount', mount) in cypress/support/component.js, which loads before every spec.
In a Cypress component test, how do you assert that a component invoked its `onRate` callback prop?
basics
~20 sCreate a Cypress spy with cy.spy(), name it with .as(), and pass it into cy.mount() as the prop. Drive the component, then assert through the alias: cy.get('@onRate').should('have.been.calledWith', 4). The alias is what makes the assertion retry until the callback fires.
Why does a component mounted by Cypress's cy.mount() render unstyled?
basics
~20 sCypress renders components into cypress/support/component-index.html, not your application's page, so nothing the app's entry file does at startup has run. Import your global stylesheets in cypress/support/component.js, or add the same link tags to that index file.
In a Cypress component test, why does an aliased spy assertion retry when `expect(spy)` does not?
basics
~20 scy.get('@alias') is a Cypress query, so the chained assertion is re-run against the spy until it passes or defaultCommandTimeout expires. A bare expect(spy) inside .then() is plain Chai: it runs once, at that instant, and loses the race whenever the callback is late.
Why does a Cypress component mount cost more than a simulated-DOM render?
basics
~20 sCypress mounts the component in a real browser, so every test pays for a compiled dev-server bundle, a loaded page, real layout and paint, and a snapshot per command. That buys a real box model, real visibility and real CSS.
What do the Cypress Docker images cypress/base, cypress/browsers and cypress/included contain?
basics
~20 scypress/base carries Debian, Node.js and the OS packages Cypress needs, but no browser. cypress/browsers adds Chrome, Firefox and Edge. cypress/included adds a tag-pinned Cypress installed globally. cypress/factory generates a custom image when no published combination fits.
In Cypress, what is the difference between `cypress open` and `cypress run`?
basics
~20 scypress open launches the interactive Cypress app: you pick a spec, watch it run in a visible browser, and it reruns every time you save. cypress run executes matching specs once, headlessly, then exits with a status code a pipeline reads.
In Cypress Cloud, what does it mean when a recorded run is flagged flaky?
basics
~20 sAt least one test in that run failed an attempt and then passed on a later attempt of the same code. Cypress Cloud counts those tests and badges the run, so a run can finish green and still be flaky.
What does a project need before `cypress run --record` uploads to Cypress Cloud?
basics
~10 sTwo things: a projectId in the Cypress config (or CYPRESS_PROJECT_ID) naming the Cloud project, and a record key passed as --key or exported as CYPRESS_RECORD_KEY. The projectId says where; the key authorises writing there.
What exit code does `cypress run` return, and what does `--posix-exit-codes` change?
basics
~20 sBy default cypress run exits with the number of failed tests, Mocha-style: three failures give status 3, and 0 means everything passed. Passing --posix-exit-codes makes any test failure exit 1 instead, and adds 112 for a Cypress Cloud network failure.
Which browsers can Cypress 16 launch, and how do you pick one for a run?
basics
~20 sCypress 16 launches Chrome-family browsers - Chrome, Chrome for Testing, Chromium and Edge - plus Firefox, experimental WebKit, and the deprecated bundled Electron. Choose one per run with the --browser flag, or set defaultBrowser in the Cypress config.
In Cypress, how do you test a link that opens in a new browser tab?
basics
~20 sCypress drives a single tab and has no tab-switching command, so assert the link rather than follow it: check its href and target attributes, request the URL directly with cy.request, or strip the target attribute so the click navigates the current tab.
Why does a console.log() in a Cypress spec never reach the terminal running cypress run?
basics
~20 sSpec code is evaluated inside the browser, so console.log() writes to that browser's DevTools console. The terminal belongs to Cypress's separate Node process, which only prints what code in cypress.config.js and its Node handlers log.
In Cypress, what happens to a request whose host matches a `blockHosts` pattern?
basics
~10 sCypress ends the request itself and answers 503, adding an x-cypress-matched-blocked-host header naming the pattern that matched. The request is never sent, so it resolves immediately instead of waiting on a third party.
Why did Cypress 16 remove `Cypress.env()`, and what replaced it?
basics
~20 sCypress.env() hydrated every configured environment variable into the browser, so reading one value exposed them all. Cypress 16 removed it and split the job: cy.env() reads secrets asynchronously and keeps them in Node, while Cypress.expose() serves public values synchronously.
In a Cypress `cypress.config.js`, which options must sit inside the `e2e` block, not the root?
basics
~20 sThe testing-type-only keys: baseUrl, specPattern, supportFile, excludeSpecPattern, slowTestThreshold and testIsolation. Cypress refuses to start and names the offending key if one of them appears at the root of the exported object, telling you to move it into e2e or component.
Which Cypress commands let a spec running in the browser reach the file system?
basics
~10 sOnly four: cy.fixture(), cy.readFile(), cy.writeFile() and cy.task(). Spec code is browser JavaScript with no fs module, so each of those hands the work to the Node process that loaded the Cypress config.
In Cypress, what must an `on('task')` handler in `setupNodeEvents` return?
basics
~20 sIt must return a value, null, or a promise that resolves to one of those. Returning undefined fails the calling command with a message naming the task, because Cypress reads undefined as "no handler answered this event".
Cypress's `cy.env()` never logs a value, so how do secrets still reach the Command Log?
basics
~20 scy.env() logs only the key names you asked for, and that protection ends when it yields. The object you receive is an ordinary JavaScript object that Cypress does not mask or track, so assertions, .its(), .invoke() and failing commands all print what they touch.
In Cypress, what does a failing `cypress run` leave on disk by default?
basics
~20 sOne PNG per failed test, written under cypress/screenshots, because screenshotOnRunFailure defaults to true. No video: the video option defaults to false, so cypress/videos stays empty until you enable it. Neither of those happens in cypress open mode.
In Cypress open mode, what does cy.pause() let you do to a running spec?
basics
~20 scy.pause() stops the spec before the next queued command and hands control to the Command Log, where Resume finishes the run and Next advances exactly one command. While stopped you can click through the application, inspect the DOM, and read network traffic and storage.
In the Cypress Command Log, what do hovering and clicking a command do?
basics
~20 sHovering a Cypress Command Log entry restores the app under test to the DOM snapshot taken when that command ran. Clicking pins that snapshot so it stays put, and prints the entry's console properties to the browser console.
In Cypress's `cy.screenshot()`, what do capture 'viewport', 'fullPage' and 'runner' capture?
basics
~20 sviewport captures the application as it fits the current viewport, fullPage scrolls and stitches the whole application top to bottom, and runner captures the entire browser viewport including the Cypress Command Log. The default is fullPage.
In a Cypress test, why does .debug() pause where a bare debugger line does not?
basics
~20 sA bare debugger in the test body runs immediately, before any queued cy command has executed, so it stops on an untouched page. .debug() is itself queued, so it fires in order, with the previous command's subject in hand — the same effect as a debugger inside .then().
Which projects is Cypress a strong fit for, and which are the classic misfits?
basics
~20 sCypress fits an application your own team owns: JavaScript or TypeScript, one superdomain per test, Chrome-family or Firefox. The classic misfits are third-party sites, two-browser or second-tab flows, a real Safari or mobile-device sign-off, and spidering or performance work.
What does it mean that Cypress runs your test code inside the browser?
basics
~20 sCypress loads your spec into the browser alongside the application, so both run in the same run loop. Nothing is serialized between a command and an element: the test holds the real window, document and DOM nodes directly.
In Cypress, which languages can specs be written in, and why is that permanent?
basics
~20 sJavaScript and TypeScript, and nothing else. Cypress evaluates spec code inside the browser alongside the application, so the only language it can ever run is the language of the web; the docs list this as a permanent trade-off.
Which of a ported suite's waits vanish into Cypress retry-ability, and which do not?
basics
~20 sWaits for an element to appear, become visible or change text vanish: cy.get() and .should() retry inside defaultCommandTimeout. Network waits become cy.intercept() plus cy.wait('@alias'). Waits on state outside the browser do not vanish at all.
Porting a suite to Cypress, what replaces its XPath locators?
basics
~10 sCypress has no first-class XPath support: cy.get() takes a CSS selector. Text-based XPath becomes cy.contains(), structural XPath becomes a CSS selector, and XPath axes become traversal commands such as .find(), .parent(), .next() and .eq().