πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Cypress Interview Questions
Cypress Mastery 2026

Top 25 Cypress
Interview Questions

Deep-dive answers with code snippets, explanations, and real-world examples. Used by QA engineers to crack front-end automation interviews.

25 QuestionsCode SnippetsBeginner β†’ AdvancedFree
Progress0/25
0%
πŸ”¬

Preparing for Playwright instead?

Explore our comprehensive Top 100 Playwright Scenario-Based Interview Questions with TypeScript snippets.

Try Playwright Guide
01

1. What is Cypress? How is it different from Selenium?

BeginnerArchitecture
Direct Answer

Cypress is a next-generation front-end testing tool built for the modern web. Unlike Selenium, which operates outside the browser and communicates through the WebDriver protocol, Cypress runs directly inside the browser alongside the application code.

Deep Dive Explanation

This architectural difference means Cypress has native access to the DOM, local storage, network requests, and window objects. This results in faster execution, built-in automatic waiting, and consistent test results without the flakiness often associated with Selenium's asynchronous network calls.

02

2. Can you explain Cypress architecture?

IntermediateArchitecture
Direct Answer

Cypress executes its tests within the same run-loop as your application. It runs a Node.js server in the background, while the tests execute inside the browser. The Node server and browser communicate using WebSockets.

Deep Dive Explanation

Because Cypress runs inside the browser, it can intercept network requests, stub responses, and modify application state synchronously. The Node server handles tasks that require higher privileges, like reading from the file system, taking screenshots, or connecting to databases.

03

3. What are Cypress commands? Why are they asynchronous?

IntermediateCore Concepts
Direct Answer

Cypress commands (like cy.get, cy.click) are the building blocks of tests. They don't execute immediately; instead, they are enqueued to be run sequentially later. Behind the scenes, Cypress commands are essentially asynchronous promises.

Deep Dive Explanation

By queuing commands, Cypress manages the execution order perfectly and can automatically retry assertions until they pass or time out. This design eliminates the need for explicit waits or thread sleeps, solving the synchronization issues common in other tools.

cypress.spec.js
// Commands are queued, not executed sequentially right away
cy.get('.btn').click()
// Even though it looks synchronous, Cypress orchestrates the execution
04

4. How does Cypress handle waiting for elements?

BeginnerCore Concepts
Direct Answer

Cypress has built-in 'Auto-Waiting'. It automatically waits for elements to exist in the DOM, become visible, become actionable (not disabled, not covered), and finish animating before it executes a command like clicking or typing.

Deep Dive Explanation

You almost never need to use explicit waits like `cy.wait(5000)` or thread sleeps. Cypress will continuously retry querying the DOM until the element reaches the actionable state or until the default command timeout (usually 4 seconds) is reached.

05

5. What are fixtures in Cypress? How do you use them?

BeginnerTest Data
Direct Answer

Fixtures are external files (usually JSON) that store static mock data. They are used to stub network responses, provide test data for form inputs, or mock application state, keeping your test files clean and data-driven.

Deep Dive Explanation

Using fixtures ensures your tests are not dependent on live backend data, making them faster and more reliable. You load them using `cy.fixture('filename.json')`.

cypress.spec.js
// 1. Store user.json in the cypress/fixtures folder
// 2. Use it in your test:
cy.fixture('user.json').then((userData) => {
  cy.get('#username').type(userData.username);
});

// Or use it in an intercept:
cy.intercept('GET', '/api/users', { fixture: 'user.json' });
06

6. Explain the purpose of the cypress configuration file.

BeginnerConfiguration
Direct Answer

The Cypress configuration file (cypress.config.js or ts in v10+, previously cypress.json) stores global project settings. It defines parameters like baseUrl, default command timeouts, viewport dimensions, environment variables, and folder structures.

Deep Dive Explanation

This file acts as the single source of truth for the project's execution environment. Setting a `baseUrl` here is a critical best practice because it speeds up the initial `cy.visit()` and simplifies test URLs.

cypress.spec.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000',
    defaultCommandTimeout: 5000,
    viewportWidth: 1280,
    viewportHeight: 720,
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
})
07

7. How do you write a test to check if a button is disabled?

BeginnerAssertions
Direct Answer

You use the `should` assertion with the Chail-jQuery matcher `be.disabled`.

Deep Dive Explanation

Cypress bundles Chai and jQuery, giving you a rich syntax for assertions. You can chain `.should('be.disabled')` directly to the `cy.get()` command.

cypress.spec.js
// Asserting the button is disabled
cy.get('#submit-btn').should('be.disabled');

// Asserting the button is NOT disabled
cy.get('#submit-btn').should('not.be.disabled');
08

8. How do you handle API calls in Cypress tests?

IntermediateNetwork
Direct Answer

Cypress handles API calls using `cy.request()` to make direct HTTP requests, and `cy.intercept()` to spy on or stub network traffic initiated by the browser application.

Deep Dive Explanation

`cy.request()` is ideal for fast data setup (like creating a user before a test) or API testing because it bypasses the UI completely. `cy.intercept()` is used during UI tests to mock backend responses, simulating different application states (like a 500 server error).

09

9. What is the use of cy.intercept()? Explain with an example.

IntermediateNetwork
Direct Answer

`cy.intercept()` is used to spy on, stub, or modify network requests and responses made by the browser. It allows you to simulate backend behavior without needing a real server.

Deep Dive Explanation

You can use it to force a server error to test UI error handling, delay a response to test loading spinners, or return mock data via a fixture to ensure consistent test conditions.

cypress.spec.js
// Intercept a GET request and return mock data from a fixture
cy.intercept('GET', '/api/users', { fixture: 'users.json' }).as('getUsers');

cy.visit('/dashboard');

// Wait for the specific intercepted call to finish before asserting UI
cy.wait('@getUsers');
cy.get('.user-list').should('have.length', 5);
10

10. What is the difference between cy.get() and cy.contains()?

BeginnerCore Concepts
Direct Answer

`cy.get()` selects elements based on CSS selectors (like ID, class, or data attributes). `cy.contains()` selects elements based on the text content visible inside them.

Deep Dive Explanation

While `cy.get` is faster and more precise when using dedicated test IDs (e.g., `data-cy`), `cy.contains` is incredibly useful for testing from the user's perspective, as users interact with text labels (like 'Submit' or 'Login'), not CSS classes.

cypress.spec.js
// Using cy.get with a CSS selector
cy.get('.btn-primary').click();

// Using cy.contains to find a button by its text content
cy.contains('Submit Order').click();

// Combining them to find text within a specific element
cy.get('.modal').contains('Confirm').click();
11

11. Explain what custom commands are in Cypress and how to create them.

IntermediateFramework Design
Direct Answer

Custom commands allow you to extend the Cypress `cy` object with your own reusable functions. They are used to abstract repetitive logic, like logging into an application or setting up specific state.

Deep Dive Explanation

They keep test files clean and adhere to the DRY (Don't Repeat Yourself) principle. Custom commands are typically defined in the `cypress/support/commands.js` file so they are globally available across all specs.

cypress.spec.js
// Definition in cypress/support/commands.js
Cypress.Commands.add('login', (email, password) => {
  cy.visit('/login');
  cy.get('#email').type(email);
  cy.get('#password').type(password);
  cy.get('#submit').click();
});

// Usage in any test file
cy.login('test@user.com', 'password123');
12

12. How can you handle iframes in Cypress?

AdvancedAdvanced Techniques
Direct Answer

Handling iframes in Cypress requires a workaround because Cypress cannot inherently cross the iframe boundary due to browser security restrictions. You have to manually target the iframe's content window.

Deep Dive Explanation

Alternatively, you can use the popular `cypress-iframe` plugin, which provides custom commands like `cy.iframe()` to seamlessly interact with elements inside the iframe.

cypress.spec.js
// Without plugins (Native Workaround)
cy.get('iframe').its('0.contentDocument.body').should('not.be.empty')
  .then(cy.wrap)
  .find('.iframe-button').click();

// With cypress-iframe plugin
cy.frameLoaded('#my-iframe');
cy.iframe().find('.iframe-button').click();
13

13. What is the purpose of before(), beforeEach(), after(), and afterEach() hooks?

BeginnerCore Concepts
Direct Answer

These Mocha hooks manage test setup and teardown operations. `before()` runs once before all tests in a block, `beforeEach()` runs before every single test, `after()` runs once after all tests, and `afterEach()` runs after every single test.

Deep Dive Explanation

Use `beforeEach()` to reset application state (like clearing cookies or logging in) to ensure tests are completely isolated. Avoid `after()` hooks for cleanup, as Cypress recommends cleaning up state *before* tests run, in case a test crashes and the `after` hook is skipped.

14

14. How do you handle file upload in Cypress?

IntermediateInteractions
Direct Answer

Historically, Cypress required a third-party plugin for file uploads. However, since version 9.3.0, Cypress natively supports file uploads using the `selectFile()` command.

Deep Dive Explanation

You can use `selectFile` to upload files stored in your fixtures folder directly to an input element of type `file`, and even simulate drag-and-drop actions.

cypress.spec.js
// Uploading a file from the fixtures directory
cy.get('input[type="file"]').selectFile('cypress/fixtures/profile-pic.png');

// Simulating drag and drop
cy.get('.dropzone').selectFile('cypress/fixtures/profile-pic.png', { action: 'drag-drop' });
15

15. What are Cypress plugins? Can you name a few commonly used ones?

IntermediatePlugins
Direct Answer

Plugins extend Cypress's native functionality by allowing you to tap into the Node.js process running behind the browser. This allows Cypress to do things the browser can't, like read files, query databases, or process configuration.

Deep Dive Explanation

Commonly used plugins/packages include `cypress-iframe` (for iframe support), `cypress-xpath` (to enable XPath selectors), `@badeball/cypress-cucumber-preprocessor` (for BDD/Cucumber integration), and `cypress-file-upload` (for older versions).

16

16. Explain how you would integrate Cypress tests with CI/CD tools like Jenkins or GitLab.

AdvancedCI/CD
Direct Answer

You integrate Cypress into CI/CD by running Cypress via its CLI command `npx cypress run` in the CI pipeline script. The pipeline must have an environment that supports browsers (usually a Docker container provided by Cypress, like `cypress/included`).

Deep Dive Explanation

For large suites, you can parallelize tests across multiple CI machines using Cypress Cloud's `--record --parallel` flags to drastically reduce execution time. The pipeline would spin up the local server, run the tests headlessly, and generate an artifact report on failure.

cypress.spec.js
// Example GitHub Actions snippet
jobs:
  cypress-run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: cypress-io/github-action@v5
        with:
          build: npm run build
          start: npm start
          wait-on: 'http://localhost:3000'
          browser: chrome
17

17. How to run Cypress tests headlessly?

BeginnerExecution
Direct Answer

You run Cypress in headless mode using the command `npx cypress run`. By default, this executes the tests headlessly (without a visible UI) using the Electron browser.

Deep Dive Explanation

Running headlessly consumes fewer system resources and is much faster, which is why it is the standard mode used in CI/CD pipelines.

18

18. Can you run Cypress tests on multiple browsers? Which ones?

BeginnerExecution
Direct Answer

Yes, Cypress supports testing across multiple browsers. It currently supports Chromium-based browsers (Chrome, Edge, Electron) and Firefox.

Deep Dive Explanation

You can specify the browser using the `--browser` flag in the CLI, e.g., `npx cypress run --browser firefox`. Note that Cypress does not support Safari natively; it only supports WebKit (Safari's engine) experimentally.

19

19. What is the difference between .should() and .then() in Cypress?

AdvancedCore Concepts
Direct Answer

`.should()` is an assertion command that automatically retries until the assertion passes or times out. `.then()` is a utility command used to access the yielded subject (like an element or a string) to write custom code or handle asynchronous data.

Deep Dive Explanation

Crucially, `.then()` does *not* retry. Once the previous command yields its value, `.then()` executes immediately. If you need Cypress to wait and retry, you must use `.should()`. You use `.then()` when you need to extract text or interact with jQuery elements directly.

cypress.spec.js
// .should() will retry until the element has the class 'active'
cy.get('.btn').should('have.class', 'active');

// .then() executes immediately to extract text
cy.get('.btn').invoke('text').then((text) => {
  const numericalValue = parseInt(text);
  expect(numericalValue).to.be.greaterThan(5);
});
20

20. Explain test retries in Cypress and how to configure them.

IntermediateConfiguration
Direct Answer

Test retries tell Cypress to re-run a failing test case a specified number of times before ultimately marking it as a failure. This helps mitigate test flakiness caused by network blips or unpredictable DOM rendering.

Deep Dive Explanation

You configure retries in the `cypress.config.js` file. You can set different retry counts for `runMode` (headless/CI) and `openMode` (interactive UI).

cypress.spec.js
// In cypress.config.js
module.exports = defineConfig({
  e2e: {
    retries: {
      runMode: 2, // Retries twice in CI/headless mode
      openMode: 0 // Does not retry during local development
    }
  }
});
21

21. How do you capture screenshots or videos of your tests?

BeginnerExecution
Direct Answer

When running tests in headless mode (`cypress run`), Cypress automatically captures a screenshot whenever a test fails and records a video of the entire test run by default.

Deep Dive Explanation

You can manually capture a screenshot at any specific point during a test using the `cy.screenshot('filename')` command. Video recording can be turned off in the configuration file to save processing time in CI pipelines.

22

22. What are the limitations of Cypress?

IntermediateArchitecture
Direct Answer

Cypress has several distinct architectural limitations: it cannot easily interact with multiple browser tabs or windows, it cannot handle native mobile app testing, and it historically struggles with cross-origin domains within the same test.

Deep Dive Explanation

Because Cypress runs inside a single browser tab, testing workflows that pop open new tabs (like OAuth logins or external payment gateways) require workarounds (like removing the `target='_blank'` attribute or utilizing `cy.origin()` in newer versions).

23

23. What is the role of cy.request() and how is it different from cy.visit()?

BeginnerNetwork
Direct Answer

`cy.visit()` loads an HTML page into the Cypress browser UI and waits for the page to fire its load event. `cy.request()` makes an HTTP request under the hood, completely bypassing the browser UI.

Deep Dive Explanation

Use `cy.request()` for API testing, or to set up test data rapidly (like creating a user via POST) before using `cy.visit()` to test the UI. `cy.request()` is vastly faster than driving the UI to set up data.

24

24. How do you organize test files and structure a real project?

IntermediateFramework Design
Direct Answer

A standard Cypress project is structured logically: `cypress/e2e/` holds the actual test spec files. `cypress/fixtures/` contains mock JSON data. `cypress/support/` holds global configurations, custom commands (`commands.js`), and index file.

Deep Dive Explanation

In real projects, I often adopt the Page Object Model (POM) pattern or use custom commands to abstract UI selectors and actions. I categorize tests into subfolders within `e2e` (e.g., `/auth`, `/checkout`, `/api`).

25

25. Share a challenge you faced while writing Cypress tests and how you resolved it.

AdvancedTroubleshooting
Direct Answer

A common challenge is dealing with elements that detach from the DOM (the 'detached from DOM' error) when a modern React/Vue application aggressively re-renders the UI during a test.

Deep Dive Explanation

I resolved this by ensuring I chained assertions to wait for a stable state before interacting. Instead of querying an element, waiting, and then clicking it (which risks detachment in the middle), I merged the query and action, or waited for loading spinners to disappear completely before attempting interactions.

cypress.spec.js
// BAD: Element might detach between get and click
cy.get('.submit-btn').as('btn');
cy.wait(1000);
cy.get('@btn').click(); // Error: detached from DOM

// GOOD: Cypress automatically retries to find the element right before clicking
cy.get('.loading-spinner').should('not.exist');
cy.get('.submit-btn').should('be.visible').click();

Finished practicing?

Head back to the main lobby to explore more interview prep tracks and dashboard tools.

🏠 Back to Home Dashboard