Skip to content
TargetQA

Automation Tools

Cypress Interview Questions & Answers

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. It defines e2e and component settings like baseUrl, specPattern, viewport, timeouts, retries, video/screenshot options, and setupNodeEvents for registering tasks and plugins.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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.