Cypress Middle interview questions and answers

77 questions for a Cypress (Middle) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.In Cypress 12+, what is the difference between queries and action commands?
  2. 2.In cy.get('.list').find('li').should('have.length', 3), what is retried?
  3. 3.Why can an action in the middle of a chain break retrying?
  4. 4.What does .should(callback) add compared with .then(callback)?
  5. 5.What does .its('length') do?
  6. 6.How do you assert on the response of an intercepted request?
  7. 7.How do you check the body a form sends to the API?
  8. 8.How do you simulate a slow API in Cypress?
  9. 9.How do you simulate a network failure for a request?
  10. 10.How do you change part of a real response with cy.intercept?
  11. 11.Why must cy.intercept be defined before the action that triggers the request?
  12. 12.Are aliases shared between tests?
  13. 13.What does the validate option of cy.session do?
  14. 14.What does cacheAcrossSpecs: true on cy.session do?
  15. 15.What does cy.origin() solve?
  16. 16.How do you handle a link that opens a new tab in Cypress?
  17. 17.How do you interact with content inside an iframe in Cypress?
  18. 18.How do you query elements inside shadow DOM?
  19. 19.How do you add TypeScript types for a custom command cy.login?
  20. 20.When should you use Cypress.Commands.overwrite?
  21. 21.Where are cy.task handlers registered?
  22. 22.Why seed test data with cy.task or API calls instead of the UI?
  23. 23.What are "app actions" in Cypress testing?
  24. 24.What does cy.window() give you?
  25. 25.How do you test that window.open was called with the right URL?
  26. 26.What is the difference between cy.spy and cy.stub?
  27. 27.How do you test that a session expires after 30 minutes of inactivity?
  28. 28.How do you read a downloaded file in a Cypress test?
  29. 29.How can you add accessibility checks to Cypress tests?
  30. 30.What does visual regression testing require in Cypress?
  31. 31.How do you mount a React component that needs a router and store in component tests?
  32. 32.Why does Cypress recommend against the Page Object pattern in some cases?
  33. 33.What is "conditional testing" and why is it discouraged?
  34. 34.Why shouldn't you mix async/await with Cypress commands?
  35. 35.What does cy.wrap() do?
  36. 36.How do you call an API with auth in cy.request?
  37. 37.What does failOnStatusCode: false in cy.request allow?
  38. 38.How do you run Cypress tests against different environments?
  39. 39.What is a risk of turning testIsolation off?
  40. 40.What is the difference between before and beforeEach?
  41. 41.What does retries: { runMode: 2 } mean?
  42. 42.What causes "element is detached from the DOM" style failures?
  43. 43.How can animations cause flaky Cypress tests?
  44. 44.How do you parallelize Cypress tests without Cypress Cloud?
  45. 45.Why use the official cypress/included Docker image in CI?
  46. 46.Which CI artifacts help most when a Cypress run fails?
  47. 47.What does cy.log() do?
  48. 48.How do you clear cookies or storage inside a test?
  49. 49.How do you test responsive layouts in Cypress?
  50. 50.What does cy.contains('button', /^Save$/) add with a regex?
  51. 51.What is the difference between .within() and .find()?
  52. 52.How do you get a cookie value to assert on it?
  53. 53.How can code coverage be collected from Cypress tests?
  54. 54.Why are long, multi-page end-to-end tests harder to maintain?
  55. 55.What happens to the command queue when an assertion inside it fails?
  56. 56.What does cy.intercept route matching use by default for URLs?
  57. 57.If two intercepts match the same request, which handler runs first?
  58. 58.How do you test a request that should NOT happen?
  59. 59.How do you load a fixture and use it in assertions?
  60. 60.What is a good way to keep Cypress specs fast as a suite grows?
  61. 61.Why does Cypress run each spec in a fresh browser context?
  62. 62.How do you test a third-party payment iframe in Cypress?
  63. 63.How can a Cypress test fail if the app logs console errors?
  64. 64.What is onBeforeLoad in cy.visit useful for?
  65. 65.How do you test geolocation-based features in Cypress?
  66. 66.What's the role of defineConfig in cypress.config.ts?
  67. 67.How do you run Cypress against a local dev server in CI?
  68. 68.Why should tests avoid depending on the exact order of API items?
  69. 69.How do you assert that a button becomes enabled after a form is valid?
  70. 70.What does cy.document() yield?
  71. 71.How do you test keyboard navigation in Cypress?
  72. 72.What does cy.focused() yield?
  73. 73.When does it make sense to use cy.request for a whole test instead of the UI?
  74. 74.How do you share setup like login across many specs?
  75. 75.What does Cypress.env() read in the browser?
  76. 76.What does cy.writeFile do?
  77. 77.How do you assert a CSS property, like a colour?