34.2 C
Delhi
Monday, July 28, 2025
Home > Interview Questions​50+ Cypress Interview Questions for

50+ Cypress Interview Questions for 2025 [ with Sample Answers ]

Cypress is widely used for testing modern web applications. It’s fast, reliable, and built for JavaScript-based front-end development.

This article includes 50+ Cypress interview questions with sample answers. You'll find basics, advanced use cases, CI/CD topics, and tricky edge cases.

The questions cover common areas like cy.get(), cy.intercept(), API testing, mocking, and Cypress vs Selenium comparisons.

If you're preparing for a role that involves Cypress automation, these examples will help you revise concepts clearly and quickly.

Cypress Interview Questions for Freshers

1. What is Cypress, and why is it popular for web testing?

Cypress is a modern front-end testing framework built on JavaScript. It’s designed specifically for testing web applications and runs directly in the browser. Unlike Selenium, Cypress has a fast execution cycle, built-in waits, and provides real-time reloading with detailed error logs.

What makes Cypress popular is its developer-friendly setup — no need for additional drivers or complex configurations. It’s ideal for end-to-end testing, integration testing, and even unit tests within modern JavaScript frameworks like React or Angular.

2. How is Cypress different from Selenium?

The biggest difference is in how they run. Selenium runs outside the browser and controls it remotely, while Cypress runs inside the browser — alongside your app. This means Cypress has access to everything happening in the browser and gives you better control and visibility.

Cypress also doesn’t require explicit waits like Selenium does. It automatically waits for elements to appear or actions to complete, which simplifies test writing and reduces flakiness.

3. What types of tests can you write using Cypress?

Cypress supports multiple types of testing, including:
End-to-End (E2E) Testing: Simulates real user behaviour on the application.
Integration Testing: Tests how components or modules work together.
Unit Testing: While not its core strength, Cypress can also handle unit tests, especially for frontend code using frameworks like React.

That said, its strongest use case is E2E testing of modern web applications.

4. What browsers are supported by Cypress?

Cypress supports major browsers like Chrome, Edge, and Firefox (both stable and developer editions). While support for Safari is limited, you can run tests in WebKit using the experimental features or plugins.

Tests run fastest and with the best debugging support in Chromium-based browsers like Chrome and Edge.

5. How do you install Cypress?

You can install Cypress using npm, which is the most common method:

npm install cypress --save-dev

Once installed, you can launch it with:
npx cypress open

This opens the Cypress Test Runner where you can run or create test specs.

6. What is the Cypress Test Runner?

The Cypress Test Runner is the UI that launches when you run npx cypress open. It lists all your test specs and allows you to run them in different browsers.

As tests run, you can watch commands execute in real-time, inspect DOM snapshots, and debug failures directly inside the runner — which makes Cypress highly visual and easy to use.

7. How does Cypress handle asynchronous code?

Cypress commands are asynchronous but follow a **chained command queue** model. Each command waits for the previous one to finish before executing — no need for callbacks or await keywords.

This design keeps your test scripts clean and linear. Cypress also automatically retries commands until they pass or timeout, reducing race conditions.

8. What are fixtures in Cypress?

Fixtures are static test data files used to stub or mock responses during tests. They’re typically stored in the cypress/fixtures folder and are written in JSON, JS, or even text format.

You can load a fixture using:
cy.fixture('user').then((user) => )

This is useful when testing login flows, API mocks, or form data scenarios.

9. How do you target elements in Cypress?

You can target DOM elements using the cy.get() command and standard CSS selectors:
cy.get('.btn-primary')

For better maintainability, it’s recommended to use custom data attributes like:
cy.get('[data-cy=submit-button]')

This reduces test flakiness if class names or IDs change.

10. What is the role of commands.js in Cypress?

The commands.js file lets you define **custom Cypress commands** to reuse across multiple tests. It’s located under cypress/support.

For example, you can define a reusable login function:
Cypress.Commands.add('login', (email, password) => )

This keeps your test code DRY (Don’t Repeat Yourself) and improves readability.

Read Also: JavaScript ES6+ Features You Must Know for Interviews in 2025

Advanced Cypress Interview Questions

11. What are some best practices for writing stable Cypress tests?

Advanced Cypress users often follow a few key best practices to improve test reliability:

– Use data-* attributes for selectors instead of dynamic classes.
– Avoid using cy.wait() with hardcoded delays — prefer cy.intercept() with cy.wait('@alias').
– Reuse custom commands via commands.js to avoid duplication.
– Always reset app state before each test (e.g., clear cookies, localStorage).
– Keep tests atomic — test one behaviour per spec.

These Cypress automation testing tips help reduce flakiness and ensure long-term test stability.

12. How does Cypress handle API testing?

Cypress makes API testing simple through its cy.request() command. It allows you to send HTTP requests and validate responses without needing to visit the UI.

Example:
cy.request('POST', '/api/login', )

You can use this for pre-authentication, health checks, or mocking server interactions before executing UI tests — making Cypress powerful for full-stack validation.

13. What is the use of cy.intercept() in Cypress?

cy.intercept() is used to spy on or stub network requests in Cypress. It’s commonly used in advanced Cypress interview questions because it replaces the now-deprecated cy.route().

You can intercept API calls and:
– Verify request/response
– Add assertions
– Mock the response data

Example:
cy.intercept('GET', '/api/user', ).as('getUser')
Then wait using: cy.wait('@getUser')

This is critical for controlling test environments and avoiding backend dependency.

14. Can Cypress test iframes?

Cypress doesn’t support iframe testing natively out of the box, which is a known limitation. However, it can be done using workarounds and third-party plugins like cypress-iframe.

With the plugin, you can write:
cy.frameLoaded('#my-frame')
cy.iframe().find('button').click()

Testing embedded content is trickier with Cypress, but still manageable with proper configuration — a common advanced Cypress automation topic.

15. What is Cypress.env and how is it used?

Cypress.env is used to store and retrieve environment-specific variables like usernames, passwords, or API tokens. These can be defined in the cypress.json file or passed via CLI.

Usage:
Cypress.env('admin_user')

You can securely manage sensitive data this way without hardcoding it in your test files — aligning with Cypress testing best practices.

16. How do you run Cypress tests in headless mode?

Running Cypress in headless mode is useful for CI pipelines and local automation. Use the following CLI command:

npx cypress run

To specify a browser (e.g., Chrome):
npx cypress run --browser chrome

Headless mode doesn’t launch the test runner UI but still executes and logs all tests — a must-know for automation engineers.

17. What is Cypress retry-ability and why does it matter?

Retry-ability is a built-in Cypress feature that automatically retries failed commands until they succeed or timeout. For example, if an element is not yet visible, cy.get() keeps checking until it appears.

This removes the need for manual waits and ensures that tests remain resilient even with slower network or UI loads. It’s one of the core reasons why Cypress tests are more stable than Selenium in real-world conditions.

18. How do you handle authentication in Cypress tests?

There are two main ways to handle login in Cypress automation testing:

1. **UI-based login:** Use cy.visit() and fill the login form.
2. **Programmatic login:** Use cy.request() to hit the login API and set auth tokens/cookies manually.

The second method is faster and avoids redundant UI steps. It also keeps your tests focused on the functionality being tested rather than login flows.

19. Can Cypress be integrated with CI/CD tools?

Yes, Cypress integrates smoothly with CI/CD tools like Jenkins, GitHub Actions, GitLab CI, and CircleCI. You can install Cypress as a dev dependency and use the CLI in your pipeline script.

Example (GitHub Actions):
npx cypress run --record

You can also use Cypress Dashboard for storing test results, screenshots, and video recordings — helpful for test reporting in teams.

20. How do you debug failed Cypress tests?

Cypress makes debugging easier through time-travel snapshots, browser dev tools, and video recordings. You can inspect the exact state of the DOM at any step using the Test Runner.

Tips:
– Use cy.log() to print checkpoints
– Use debugger or console.log() within your tests
– Leverage cypress run --headed to watch the test in real-time

This visual feedback loop is one of Cypress’s biggest advantages in debugging UI test failures.

Read Also:  React JS Interview Questions and Answers

Scenario-Based and Tricky Cypress Interview Questions

21. A button is visible but not clickable. How would you handle this in Cypress?

This is a common Cypress interview scenario. The element may be covered by another DOM layer (e.g., loader or animation). Use Cypress commands like:

cy.get('button').click( )

You can also use cy.scrollIntoView() or add waits for animations to complete. But use carefully — only when you’re sure the button is intended to be clickable at that moment.

22. What would you do if tests pass locally but fail in CI?

This is one of the most tricky Cypress interview questions. CI failures often stem from environment mismatches, slow loading elements, or resolution differences.

Tips:
– Check base URLs and environment variables.
– Add logging with cy.log() to debug.
– Use cy.wait('@api-call') instead of cy.wait(1000).
– Add viewport configuration in your tests to match the CI resolution.

Run cypress run --headed locally in CI-like mode to simulate the issue.

23. How would you test a file upload in Cypress?

Cypress doesn’t natively support file upload, but you can use the cypress-file-upload plugin.

Steps:
1. Install the plugin
2. Add it to commands.js
3. Use:
cy.get('input[type=file]').attachFile('example.jpg')

This helps simulate real user behaviour when automating forms or profile update flows — a key Cypress real-world testing use case.

24. How do you test a dynamic dropdown list in Cypress?

For dynamic dropdowns, start by triggering the input event:
cy.get('input[role=combobox]').type('Banana')
cy.get('.dropdown-list').contains('Banana').click()

Make sure to assert the list appears before clicking. Use cy.should('be.visible') before interacting — this reduces test flakiness in auto-suggest or async dropdowns.

25. How do you handle timeouts in Cypress?

Cypress commands have default timeouts (e.g., 4s for cy.get()). You can increase timeouts for slower apps:

cy.get('.element', )

For global control, use defaultCommandTimeout in cypress.config.js. But keep test feedback quick — increasing timeouts shouldn’t be your first option.

26. How would you simulate slow network conditions?

You can simulate network delay using cy.intercept() with a delay property.

Example:
cy.intercept('GET', '/api/products', ).as('slowApi')

Then:
cy.wait('@slowApi')

This is useful for testing loaders, skeleton screens, and retry logic under real-world conditions.

27. How do you test localStorage and sessionStorage in Cypress?

To validate localStorage:
cy.window().then((win) => )

You can also use cy.clearLocalStorage() or cy.clearCookies() to reset session data before tests — which is a key Cypress testing practice in login-based workflows.

28. What would you do if Cypress cannot find an element?

Check for these common issues:
– Element is not yet in the DOM → Add a wait or assert visibility
– Selector is incorrect → Use browser dev tools to validate
– Shadow DOM → Cypress doesn’t support it natively; use plugins

Use cy.wait() wisely or cy.intercept() to sync UI with network readiness.

29. How would you test multi-tab or multi-window flows?

Cypress doesn’t support multiple tabs or windows directly because it runs in a single browser context.

Workaround:
– Intercept or stub external redirects
– Test content in isolation by visiting the redirected URL manually

This is a known Cypress limitation, and you may need Puppeteer or Playwright for deep multi-tab automation.

30. How can you group related tests in Cypress?

Use describe() blocks to group related tests in a spec file. Each group can have beforeEach() or afterEach() hooks to manage setup/teardown.

Example:
describe('Login flow', () => )
})


This helps keep your Cypress test suites clean and modular — especially in large projects.

Read Also: Front End Developer Interview Questions and Answers

Cypress vs Other Tools: Comparison Questions

31. How does Cypress differ from Selenium?

Cypress and Selenium are both widely used test automation tools, but they differ significantly in architecture and developer experience.

FeatureCypressSelenium
Execution ContextRuns inside browserRuns outside browser via WebDriver
Language SupportJavaScript onlySupports Java, Python, C#, etc.
SpeedFast, auto-waits built-inSlower, manual waits often needed
UI DebuggingTime-travel, snapshotsLimited debugging support
Browser SupportModern Chromium/FirefoxWider (incl. IE, Safari)

Use Cypress for fast, stable frontend testing. Use Selenium for broad cross-browser or legacy support.

32. Cypress vs Playwright — which one should you choose?

Both are modern JavaScript-based automation frameworks. Your choice depends on project needs and test complexity.

FeatureCypressPlaywright
Test RunnerBuilt-in GUI runnerCLI-based runner
Multi-tab SupportNot supportedFully supported
Mobile EmulationLimitedYes, built-in
Cross-browser TestingChromium/FirefoxChromium, Firefox, WebKit
Ease of SetupVery easyModerate

Choose Cypress for ease and debugging. Choose Playwright for advanced test coverage and cross-context workflows.

33. Can Cypress replace Selenium in large enterprise projects?

Cypress can replace Selenium in modern frontend-heavy projects, especially those using React, Angular, or Vue. But it may not fully replace Selenium in legacy apps or test suites needing:

  • Multi-tab navigation
  • Support for older browsers (like IE)
  • Non-JavaScript tech stacks
That said, Cypress is often used in parallel with Selenium — handling fast UI tests while Selenium manages older test flows.

34. Cypress vs Puppeteer — what’s the difference?

Puppeteer is great for headless browser scripting and data scraping. Cypress is built specifically for testing web apps.

FeatureCypressPuppeteer
PurposeWeb app testingBrowser automation
Built-in AssertionsYesNo
Test RunnerYes (with UI)No
Use CaseUI testingScraping, automation scripts
Learning CurveBeginner-friendlyCode-heavy

Use Cypress when you need structured E2E testing with detailed feedback. Use Puppeteer for browser control and automation outside the testing domain.

35. Can Cypress and Selenium be used together in the same project?

Yes, it’s possible to run Cypress and Selenium side-by-side — though it requires proper segregation. Example setup:

  • Cypress: Component and UI regression tests
  • Selenium: Cross-browser testing and legacy app flows
Each test suite should have its own CI/CD job, environment, and reporting mechanism to avoid conflicts. It’s not common, but large teams may adopt this hybrid approach during test migration.

Related Read: Full Stack Developer Skills You Can Add to Your Resume

Cypress Best Practices & Troubleshooting

36. What are some Cypress best practices for writing maintainable test cases?

Top Cypress testing best practices include:

  • Use data-cy or data-testid attributes for selectors
  • Keep tests atomic – one assertion per test
  • Write reusable Cypress.Commands to avoid repetition
  • Clean app state with beforeEach() using cy.clearCookies(), cy.visit()
  • Avoid hard-coded waits like cy.wait(5000)
These principles reduce test flakiness and improve readability for long-term automation maintenance.

37. How do you handle flaky tests in Cypress?

Flaky Cypress tests usually stem from:

  • Unstable network/API responses
  • Dynamic DOM content with transitions or loaders
  • Improper element selectors
To fix them: – Use cy.intercept() to wait for network stability
– Add assertions like .should('be.visible') before interacting
– Replace cy.wait() with event-driven cy.wait('@alias')
– Use retries and add where needed

38. How can you validate UI and API responses together in Cypress?

You can combine UI actions with API interceptions using cy.intercept() and then perform assertions: cy.intercept('GET', '/api/user').as('getUser')
cy.visit('/dashboard')
cy.wait('@getUser').its('response.statusCode').should('eq', 200)
cy.get('.username').should('contain', 'John Doe')
This is a powerful way to connect frontend validations with backend contract testing — a practice many teams use in real-world Cypress frameworks.

39. How to debug a failing test in Cypress?

To debug Cypress tests:

  • Use the Test Runner to see real-time command logs
  • Add cy.log() at key steps
  • Use browser’s DevTools console and debugger keyword
  • Check screenshots and videos in headless mode
Cypress also provides automatic snapshots for every command, making it easier to trace the point of failure visually.

40. How do you mock APIs using fixtures in Cypress?

You can use fixtures to mock data for network requests: cy.intercept('GET', '/api/profile', ).as('getProfile')
cy.visit('/profile')
cy.wait('@getProfile')
Fixtures help stabilise tests when backend APIs are unstable or unavailable — a key part of Cypress mocking strategy.

41. Why does Cypress auto-reload test files?

Cypress watches the filesystem and automatically reloads tests when it detects changes. This improves developer feedback speed. If needed, you can disable auto-reload in cypress.config.js by setting watchForFileChanges: false.

42. How do you handle browser permissions or pop-ups in Cypress?

Cypress doesn’t support browser permission prompts (e.g. location, camera) directly. As a workaround:

  • Stub browser APIs like navigator.geolocation
  • Override window methods using cy.visit() with onBeforeLoad
For example: cy.visit('/map',
})

43. Why does Cypress not support multiple tabs or windows?

Cypress runs inside a single browser tab with a controlled JavaScript execution environment. Supporting multi-tab interactions would break this model.

Workarounds: – Test the new tab URL directly via cy.visit()
– Use target="_blank" link stubbing to stay in the same tab

For complex multi-tab flows, tools like Playwright may be better suited.

44. What is the Cypress Dashboard and how is it used?

The Cypress Dashboard is a cloud service that records test runs, screenshots, and videos. It helps teams:

  • Track test flakiness over time
  • Debug failed runs with full logs
  • Compare runs across branches or commits
You can enable it via CLI: npx cypress run --record --key <your-project-key>

45. How do you conditionally skip or run tests in Cypress?

To skip a test, use: it.skip('should not run', () => )

To run only one test: it.only('should run only this test', () => )

You can also use custom logic inside the test block: if (Cypress.env('runSlowTests')) )
}

Cypress Advanced Scenarios & Edge Case Questions

46. How do you run Cypress tests in parallel?

To speed up CI pipelines, Cypress supports parallelisation using the Dashboard. Add the --record and --parallel flags in your CI script: npx cypress run --record --parallel --key <project-id>

Tests are split across multiple CI machines to reduce run time — ideal for large test suites in agile projects.

47. How do you isolate flaky tests in Cypress?

Use it.only() to run the failing test alone. Then:

  • Inspect DOM stability (delays, loaders)
  • Check selectors for uniqueness
  • Use cy.wait('@alias') instead of hard waits
  • Review video or time-travel snapshots
Once isolated, rewrite or refactor the test using better waiting strategies or intercepts.

48. Can you use third-party plugins with Cypress?

Yes. The Cypress ecosystem has official and community plugins like:

  • cypress-file-upload – File input automation
  • cypress-axe – Accessibility testing
  • cypress-real-events – Native mouse/keyboard events
Install with npm install and register in cypress/support/e2e.js. Always read the plugin docs for compatibility with Cypress versions.

49. How do you simulate delayed API responses?

Use cy.intercept() with a delay option: cy.intercept('GET', '/api/data', ).as('slowApi')

This is useful for testing skeleton loaders or retry mechanisms when APIs are slow or unreliable.

50. How can Cypress test multi-language/localised apps?

Pass locale info via query strings, headers, or cookies. Example: cy.visit('/dashboard?lang=fr')

Use fixtures for different languages and assert against visible text. You can also stub i18n API responses using cy.intercept().

51. How do you retry a failed Cypress test in CI automatically?

Use the retries option in cypress.config.js: retries:

This will retry failed tests up to 2 times in CI mode. Useful for rare network flakiness or async UI delays.

52. How do you test if an email was triggered without a real inbox?

Intercept the backend API that triggers the email: cy.intercept('POST', '/send-email', (req) => ).as('emailApi')

Assert the request body, response status, or even simulate success/failure flows. This avoids relying on inbox testing tools like Mailhog.

53. How do you handle test data management in Cypress?

Strategies include:

  • Use cy.request() to set up or clean data via backend APIs
  • Load predefined fixtures for mocking responses
  • Run DB scripts via CI before test execution
Avoid creating test data via the UI — it adds redundancy and time.

54. How can you stub window or global JS functions?

Use the onBeforeLoad hook in cy.visit(): cy.visit('/page', }) You can use this to stub alerts, confirm dialogs, or analytics methods during Cypress tests.

55. What are common causes of false positives in Cypress tests?

– Skipping critical assertions
– Using without validation
– Not validating final app state (e.g., backend confirmation)
– Missing network wait logic before assertions

Always assert both UI and API outcomes to avoid false confidence.

56. Can Cypress run visual regression tests?

Yes, with third-party plugins like cypress-image-snapshot: cy.get('button').matchImageSnapshot()

It compares UI elements pixel-by-pixel and flags layout shifts or broken UI. Very useful for design-focused workflows.

57. How to run only smoke tests in a large Cypress suite?

Tag your smoke specs or group them into a folder like /cypress/e2e/smoke/.

Then run: npx cypress run --spec "cypress/e2e/smoke/*"

Alternatively, use plugins like cypress-grep to filter tests via CLI tags.

58. What are some signs that your Cypress tests need refactoring?

– Tests fail intermittently with no app change
– Duplicated login or navigation code across specs
– Multiple cy.wait() sprinkled randomly
– Large test files without modularity

Refactor by using commands.js, grouping with describe(), and abstracting setup steps.

59. How do you migrate from older Cypress versions to the latest?

– Read the official changelog on the Cypress Docs
– Upgrade via npm install cypress@latest --save-dev
– Test plugins and custom commands for compatibility
– Validate breaking changes (e.g., config file format, intercept updates)

Always try the upgrade on a feature branch with full regression before merging.

60. Can Cypress be used for performance testing?

Not directly. Cypress is not a load testing tool. But it can validate:

  • API response times using cy.request()
  • Page load time with performance.now() via cy.window()
For full-scale performance/load testing, integrate tools like Lighthouse, JMeter, or k6 alongside Cypress.

Checklist + Comparison Table

Cypress Interview Preparation Checklist

  • ✅ Understand Cypress architecture (browser execution, no WebDriver)
  • ✅ Know the difference between Cypress and Selenium
  • ✅ Be able to write tests using cy.get(), cy.intercept(), cy.request()
  • ✅ Use custom commands via commands.js
  • ✅ Know how to mock APIs with fixtures and intercepts
  • ✅ Explain retry-ability, assertions, and auto-waiting
  • ✅ Handle dynamic elements and flaky tests with proper debugging
  • ✅ Be familiar with CI/CD integration and headless mode
  • ✅ Know limitations: no multi-tab, limited cross-browser, no mobile emulation
  • ✅ Prepare real-world use cases like login tests, dropdowns, API validations

Cypress vs Selenium vs Playwright: Comparison Table

FeatureCypressSeleniumPlaywright
Execution ContextInside browser (real-time)Outside browser via WebDriverBrowser automation APIs
Supported LanguagesJavaScriptJava, Python, JS, C#, RubyJavaScript, Python, Java, C#
Cross-Browser SupportChrome, Firefox, EdgeAll major browsers incl. SafariChromium, Firefox, WebKit
Multi-Tab/Window SupportNot supportedSupportedSupported
Mobile EmulationLimitedYes (via browser tools)Yes (built-in)
Ease of SetupVery EasyModerate to HardModerate
Test Runner UIYes (visual runner)NoCLI + HTML Reports
Flakiness HandlingBuilt-in retry, auto-waitsManual waits, retriesAuto-waits and retries
CI/CD IntegrationSeamless + DashboardManual setup neededGood CLI support
Ideal ForModern web app testingLegacy system + cross-browserAdvanced, cross-context apps

Use this table to compare Cypress with other test frameworks during your interviews or tool evaluation discussions. Highlighting strengths and limitations clearly shows real-world project understanding.

Frequently Asked Questions on Cypress Interviews

🔽 What are the most commonly asked Cypress interview questions?
Most interviews start with basics like “What is Cypress?”, “How is it different from Selenium?”, and “What types of testing does Cypress support?” Then they dive into cy.get(), cy.intercept(), API testing, fixtures, and debugging workflows.
🔽 Is Cypress used only for frontend testing?
While Cypress excels at frontend UI testing, it can also handle API testing, integration scenarios, and backend validation using cy.request() and mocking. It’s a powerful full-stack testing tool for JavaScript-based applications.
🔽 Can I use Cypress with GitHub Actions or Jenkins?
Yes. Cypress is designed for CI/CD. You can integrate it easily with tools like GitHub Actions, CircleCI, GitLab CI, or Jenkins. Use npx cypress run in your pipeline script, and optionally --record with a project key for Dashboard integration.
🔽 How do I prepare for Cypress interviews as a fresher?
Focus on JavaScript basics, DOM selectors, writing simple tests using Cypress commands like cy.get(), cy.visit(), and cy.contains(). Also learn how to use cy.intercept() and fixtures for mocking.
🔽 Is Cypress better than Selenium or Playwright?
It depends. Cypress is great for fast, reliable frontend testing. Selenium supports more languages and legacy browsers. Playwright supports multi-tab and mobile emulation. Many teams choose Cypress for day-to-day frontend tests due to its simplicity and speed.
- Advertisement -spot_img

More articles

spot_img

Latest article