Folder Structure in a Cypress Project

Folder Structure in a Cypress Project – Explained Simply

When you set up Cypress in a project (npx cypress open or npm install cypress), it creates a default folder structure like this:

cypress/ ├── e2e/ # Your actual test files go here ├── fixtures/ # Static test data (JSON files) ├── support/ # Reusable code, custom commands, setup logic └── downloads/ # (Optional) For downloaded files during tests cypress.config.js # Cypress configuration file

πŸ” Let’s Break It Down

1. cypress/e2e/

E2E tests (end-to-end) are written here.

  • Test files usually end with .cy.js or .cy.ts

  • Each file contains one or more describe() and it() blocks.

πŸ“Œ Example: login.cy.js, signup.cy.ts


2. cypress/fixtures/ πŸ“„

Use this for test data in JSON format.

πŸ“Œ Example:
user.json might contain:

json
{ "username": "rasagna", "password": "test123" }

You can load it in your test:

js
cy.fixture('user').then((data) => { cy.get('#username').type(data.username) })

3. cypress/support/ 🧩

Used for shared logic, like:

  • commands.js: Add custom commands using Cypress.Commands.add()

  • e2e.js: Runs before every test file (good for global setup)

πŸ“Œ Example in commands.js:

js
Cypress.Commands.add('login', (username, password) => { cy.get('#user').type(username) cy.get('#pass').type(password) cy.get('#submit').click() })

4. cypress.config.js ⚙️

The main config file where you define:

  • Base URL

  • Timeouts

  • Reporter settings

  • Test patterns

πŸ“Œ Example:

const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { baseUrl: "http://localhost:3000", setupNodeEvents(on, config) { // plugins or reporters } } });

5. Other Optional Folders

  • downloads/: Created if your tests trigger file downloads

  • videos/, screenshots/: Cypress saves test run recordings and failure screenshots (if enabled)


🧠 Summary

Folder/FilePurpose
e2e/Where your test files live
fixtures/Test data (e.g., users, products)
support/Reusable code, custom commands
cypress.config.jsConfiguration settings


Comments

Popular posts from this blog

Tosca System Requirements and Installation Guide (Step-by-Step)

How to Install Selenium for Python Step-by-Step

Tosca Commander: A Beginner’s Overview