Cypress · Browser testing end to end
How do you set up a Cypress project?
Short answer
Install Cypress, run it once to scaffold the folders, and configure baseUrl, spec patterns and the support file in cypress.config.ts. Add a TypeScript config and the Cypress types for editor support.
A new project needs the Cypress package, a config file and the conventional folder layout. Running the interactive runner once creates example specs and support files. After that you can delete the examples and write your own suite.
npm install --save-dev cypress
npx cypress openimport { defineConfig } from "cypress";
export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
supportFile: "cypress/support/e2e.ts",
specPattern: "cypress/e2e/**/*.cy.ts",
viewportWidth: 1280,
viewportHeight: 800,
},
});The typical layout
- cypress/e2e for end-to-end specs
- cypress/support for shared commands and global hooks
- cypress/fixtures for JSON or other test data
- cypress.config.ts for project configuration
- A root tsconfig.json that includes the Cypress types
Add the Cypress types to the TypeScript configuration so cy, Cypress and the custom command declarations resolve in the editor. If the project already has a frontend tsconfig, keep the Cypress config separate to avoid mixing browser and Node settings.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does baseUrl change in a test?
- 2Why keep a separate tsconfig for Cypress?
- 3Which folders should be committed?
- 4How do you change the default spec location?
Say it in the interview
I install Cypress and run it once so it scaffolds the config, support and example folders. Then I set baseUrl, specPattern and the support file in cypress.config.ts, and make sure the Cypress types are available to TypeScript. I keep e2e specs, fixtures and support code in the cypress folder and ignore screenshots and videos. The goal is a small, predictable config that a new teammate can run immediately.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.