Cypress Junior interview questions and answers

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

Take this quiz
  1. 1.Where do Cypress tests run?
  2. 2.Which command opens the interactive Cypress app?
  3. 3.Which command runs all Cypress tests headlessly, e.g. in CI?
  4. 4.Where is the main Cypress configuration usually defined?
  5. 5.What does setting baseUrl in the Cypress config allow?
  6. 6.What is a spec file in Cypress?
  7. 7.Which functions structure Cypress tests?
  8. 8.What does cy.visit('/products') do?
  9. 9.What does cy.get('[data-cy=submit]') do?
  10. 10.Why does Cypress recommend data-cy or data-test attributes for selectors?
  11. 11.What does cy.contains('Save') find?
  12. 12.How do you type into an input in Cypress?
  13. 13.How do you press Enter after typing?
  14. 14.How do you select an option in a native <select>?
  15. 15.How do you tick a checkbox in Cypress?
  16. 16.What does Cypress check before clicking an element?
  17. 17.What does { force: true } on a click do, and why is it risky?
  18. 18.What does .should('be.visible') do?
  19. 19.Which assertion checks an input's value?
  20. 20.How do you check a list has exactly 3 items?
  21. 21.How do you assert an element is NOT on the page?
  22. 22.Which assertion checks the current URL contains /dashboard?
  23. 23.What is the default timeout for most Cypress queries like cy.get?
  24. 24.Why should you avoid cy.wait(5000) in tests?
  25. 25.What are Cypress commands, in terms of timing?
  26. 26.Why can't you write const btn = cy.get('button') and use btn as an element?
  27. 27.What does .then() give you in Cypress?
  28. 28.What does .as('user') do?
  29. 29.What does cy.intercept() let you do?
  30. 30.How do you wait for a request before asserting the UI?
  31. 31.How do you stub an API response with fixed data?
  32. 32.What are fixtures in Cypress?
  33. 33.What does cy.request() do?
  34. 34.Why log in through cy.request or cy.session instead of the UI in most tests?
  35. 35.What does cy.session() do?
  36. 36.What is test isolation in Cypress?
  37. 37.Why shouldn't one test depend on another test's result?
  38. 38.How do you run only one test while working on it?
  39. 39.How do you skip a test?
  40. 40.Where should code that runs before each test, like cy.visit('/'), go?
  41. 41.What does cy.viewport('iphone-x') do?
  42. 42.What does cy.screenshot() do?
  43. 43.Which browsers can Cypress run tests in?
  44. 44.What does the Cypress command log show?
  45. 45.How do you pause a test to inspect the page in the Cypress app?
  46. 46.How do you scope queries to one part of the page?
  47. 47.How do you get the second item from a list?
  48. 48.How do you find a child element of a found element?
  49. 49.How do you read environment-specific values in Cypress?
  50. 50.Why should secrets not be committed in cypress.env.json?
  51. 51.What is a custom command?
  52. 52.Where are custom commands usually registered?
  53. 53.What does cy.task() do?
  54. 54.How do you test a feature that depends on time, like a countdown?
  55. 55.What does cy.stub() create?
  56. 56.What happens to a window.alert() in a Cypress test?
  57. 57.Why does Cypress record screenshots on failure in cypress run?
  58. 58.What is Cypress component testing?
  59. 59.What does the Cypress Testing Library add?
  60. 60.How can test retries be enabled in Cypress?
  61. 61.Why does a hard-coded cy.wait(2000) before checking a result usually fail sometimes?
  62. 62.What should a Cypress test check after submitting a form?
  63. 63.What does cy.reload() do?
  64. 64.What does cy.go('back') do?
  65. 65.How do you test a file upload in Cypress?
  66. 66.How do you assert that a text appears somewhere in an element?
  67. 67.What is the role of the support file cypress/support/e2e.ts?
  68. 68.Why is cy.get('.btn-primary:nth-child(3)') a fragile selector?
  69. 69.What does Cypress do with an uncaught exception from the app?
  70. 70.How do you run one spec file from the command line?
  71. 71.What does Cypress Cloud add on top of the open-source runner?
  72. 72.Why should tests clean up or create their own data?
  73. 73.What is a common mistake when asserting on text that loads asynchronously?
  74. 74.How does Cypress handle a click that triggers navigation?
  75. 75.Which kind of tests does Cypress mainly target?