Cypress interview questions on architecture, commands and chaining, retry-ability, cy.intercept, fixtures, custom commands, component testing and CI.
50 questions17 Beginner20 Intermediate13 Advanced
Interview Questions
Showing 15 of 50 questions
Answer
Cypress is a JavaScript end-to-end and component testing framework that runs inside the browser alongside the app, with a Node server process handling tasks like file access and network proxying. Selenium drives the browser from outside via the WebDriver protocol.
Key points
Direct access to the DOM, window and network layer
Automatic waiting and retries built into commands
Time-travel debugging in the interactive runner
Supports Chrome-family, Firefox and experimental WebKit
Interview tip: Know the trade-offs: JS/TS only, limited multi-tab support, and cross-origin needs cy.origin().
Cypress is a JavaScript end-to-end and component testing framework that runs inside the browser alongside the app, with a Node server process handling tasks like file access and network proxying. Selenium drives the browser from outside via the WebDriver protocol.
Answer
Cypress commands are enqueued and executed later in order; they return chainables, not Promises. To use a yielded value you chain .then() or use aliases, rather than assigning the result to a variable.
Key points
const el = cy.get(...) does not give you the element
Mixing async/await causes confusing ordering bugs
Cypress.Promise exists but is rarely needed
javascript
// Wrong: text is a chainable, not a string
// const text = cy.get("[data-cy=total]").invoke("text");
cy.get("[data-cy=total]")
.invoke("text")
.then((text) => {
expect(Number(text.replace("$", ""))).to.be.greaterThan(0);
});
Interview tip: This is one of the most asked Cypress questions; interviewers check you understand the command queue.
Cypress commands are enqueued and executed later in order; they return chainables, not Promises. To use a yielded value you chain .then() or use aliases, rather than assigning the result to a variable.
Answer
Cypress recommends dedicated data-* attributes like data-cy or data-testid, because they're isolated from styling and structure changes. cy.contains() is good when the visible text is part of what you're testing.
Key points
Avoid brittle selectors like .btn.btn-primary or nth-child
cy.get() supports CSS selectors only, no XPath by default
Cypress recommends dedicated data-* attributes like data-cy or data-testid, because they're isolated from styling and structure changes. cy.contains() is good when the visible text is part of what you're testing.
Answer
Queries like cy.get, .find and .contains, along with their attached assertions, automatically retry until the assertion passes or the timeout (default 4 seconds) expires. Action commands like .click() are not retried, but they wait for the element to be actionable.
Key points
Only the last query plus assertions retry together
Put assertions right after the query that should retry
Override per command: cy.get(sel, { timeout: 10000 })
Interview tip: Common mistake: using cy.wait(5000). Hard waits make tests slow and still flaky.
Queries like cy.get, .find and .contains, along with their attached assertions, automatically retry until the assertion passes or the timeout (default 4 seconds) expires. Action commands like .click() are not retried, but they wait for the element to be actionable.
Answer
Cypress bundles Chai, Chai-jQuery and Sinon-Chai. I mostly use .should() with chainers like 'be.visible' or 'have.text', which retry, and expect() inside .then() for complex checks.
Cypress bundles Chai, Chai-jQuery and Sinon-Chai. I mostly use .should() with chainers like 'be.visible' or 'have.text', which retry, and expect() inside .then() for complex checks.
Answer
Static data goes in cypress/fixtures as JSON and is loaded with cy.fixture() or used directly in cy.intercept with the fixture option. Dynamic data is usually created via API calls with cy.request() in beforeEach.
Key points
Fixtures pair well with stubbed responses
Use unique data per test to allow parallel runs
Environment values via Cypress.env() or config env
Static data goes in cypress/fixtures as JSON and is loaded with cy.fixture() or used directly in cy.intercept with the fixture option. Dynamic data is usually created via API calls with cy.request() in beforeEach.
Answer
It defines e2e and component settings like baseUrl, specPattern, viewport, timeouts, retries, video/screenshot options, and setupNodeEvents for registering tasks and plugins.
Key points
cypress.json was removed in Cypress 10
retries: { runMode: 2, openMode: 0 } is a common setup
Environment overrides via --config or --env on the CLI
It defines e2e and component settings like baseUrl, specPattern, viewport, timeouts, retries, video/screenshot options, and setupNodeEvents for registering tasks and plugins.
Answer
I use cy.intercept() to spy on or stub requests, give it an alias with .as(), and then cy.wait('@alias') to synchronize on the actual call. Stubbing with a fixture or statusCode lets me test error and empty states.
Key points
Register the intercept before the action that triggers it
cy.wait('@alias') yields the interception for assertions
I use cy.intercept() to spy on or stub requests, give it an alias with .as(), and then cy.wait('@alias') to synchronize on the actual call. Stubbing with a fixture or statusCode lets me test error and empty states.
Answer
I add them with Cypress.Commands.add() in cypress/support/commands.js for repeated actions like programmatic login. I keep them small and avoid wrapping every single click, since that hides what the test does.
Key points
Add TypeScript declarations for autocomplete
Cypress.Commands.overwrite() can extend built-ins
Prefer plain functions for logic that doesn't need the chain
I add them with Cypress.Commands.add() in cypress/support/commands.js for repeated actions like programmatic login. I keep them small and avoid wrapping every single click, since that hides what the test does.
Answer
I wrap the login steps in cy.session(), which caches and restores cookies, localStorage and sessionStorage between tests. Combined with API login, tests skip the UI login entirely after the first run.
Key points
The id argument (e.g. user email) separates sessions
validate callback checks the session is still valid
cacheAcrossSpecs: true reuses it between spec files
I wrap the login steps in cy.session(), which caches and restores cookies, localStorage and sessionStorage between tests. Combined with API login, tests skip the UI login entirely after the first run.
Answer
Page objects work fine in Cypress for organizing selectors and flows, but many teams prefer custom commands, helper modules and app actions that set state directly. I use lightweight page or component objects for selectors and API helpers for setup.
Key points
Methods should return cy chains, not values
App actions: call app functions via window to set state quickly
Keep assertions visible in the spec
Page objects work fine in Cypress for organizing selectors and flows, but many teams prefer custom commands, helper modules and app actions that set state directly. I use lightweight page or component objects for selectors and API helpers for setup.
Answer
Since Cypress 12, cy.origin() runs commands against a different origin, such as an SSO login page. Variables must be passed in through the args option since the callback runs in a separate context.
Key points
Prefer programmatic SSO login with cy.request where possible
chromeWebSecurity: false is a last-resort workaround in Chrome only
Multi-tab flows: remove target=_blank or assert on href
javascript
cy.visit("/");
cy.contains("Sign in with SSO").click();
cy.origin(
"https://login.example-idp.com",
{ args: { user: Cypress.env("SSO_USER") } },
({ user }) => {
cy.get("#username").type(user);
cy.get("#password").type(Cypress.env("SSO_PASSWORD"), { log: false });
cy.get("button[type=submit]").click();
}
);
cy.url().should("include", "/dashboard");
Interview tip: Cypress.env is accessible inside cy.origin, but outer closure variables are not.
Since Cypress 12, cy.origin() runs commands against a different origin, such as an SSO login page. Variables must be passed in through the args option since the callback runs in a separate context.
Answer
Component testing mounts a single React, Vue, Angular or Svelte component in a real browser using cy.mount(), so you can test it in isolation without running the whole app. It's faster than E2E and gives visual feedback.
Key points
Configured under the component key with a dev server (Vite/Webpack)
Stub props and callbacks with cy.spy/cy.stub
Complements, not replaces, unit and E2E tests
Component testing mounts a single React, Vue, Angular or Svelte component in a real browser using cy.mount(), so you can test it in isolation without running the whole app. It's faster than E2E and gives visual feedback.
Answer
I review the screenshots and video from CI artifacts, or Cypress Cloud test replay, and compare environments: headless browser, viewport, baseUrl, env variables and data. Most often it's a missing wait on a network call or a test depending on state from another spec.
Key points
Run cypress run --browser chrome locally with CI settings
Use the cypress/included Docker image to match CI
Replace cy.wait(ms) with cy.wait('@alias') or assertions
Make each test set up its own state
Interview tip: Mention that test isolation (default since Cypress 12) clears state between tests, so hidden dependencies surface.
I review the screenshots and video from CI artifacts, or Cypress Cloud test replay, and compare environments: headless browser, viewport, baseUrl, env variables and data. Most often it's a missing wait on a network call or a test depending on state from another spec.
Answer
The app re-rendered the element between Cypress finding it and acting on it. Since Cypress 12, queries re-run automatically in many cases, but I still fix it by waiting for the request or state that causes the re-render before interacting.
Key points
Wait on the aliased request that triggers re-render
Assert on a stable state first, e.g. loading spinner gone
Avoid storing elements in variables across actions
The app re-rendered the element between Cypress finding it and acting on it. Since Cypress 12, queries re-run automatically in many cases, but I still fix it by waiting for the request or state that causes the re-render before interacting.