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