Installing Cypress: Step-by-Step Guide

Installing Cypress: Step-by-Step Guide

Cypress is a popular testing tool for modern web applications.
It helps you write and run end-to-end tests in the browser.

Let’s walk through the full installation process.


✅ Prerequisites

Before installing Cypress, you need:

  1. Node.js and npm installed

    • You can download from https://nodejs.org

    • To check if it’s installed, run:

      node -v npm -v
  2. A project folder (use your app or create a new one)


๐Ÿ“ Step 1: Create a Project (if needed)

If you don’t have a project yet:

mkdir my-cypress-project cd my-cypress-project npm init -y

This creates a new Node.js project.


๐Ÿ“ฆ Step 2: Install Cypress

Use npm to install Cypress:

npm install cypress --save-dev

This installs Cypress as a dev dependency.


๐Ÿ” Step 3: Open Cypress for the First Time

To open the Cypress Test Runner:

npx cypress open
  • This will open the Cypress UI.

  • It will also create a cypress/ folder with example tests.


๐Ÿงช Step 4: Run Your First Test

  1. In the Cypress window, click E2E Testing.

  2. Choose a browser (like Chrome).

  3. Click Start E2E Testing.

  4. Select any test from the list and run it.

You’ll see the test run in real time in the browser!


๐Ÿ“ Step 5: Write Your Own Test

Create a file:
cypress/e2e/sampleTest.cy.js

Add a simple test:

describe('My First Test', () => { it('Visits Google', () => { cy.visit('https://www.google.com'); cy.title().should('include', 'Google'); }); });

Save and run this test from the Cypress runner.


๐Ÿงผ Optional: Ignore Example Tests

You can delete the sample tests from:

cypress/e2e/1-getting-started/

Keep your own clean structure.


๐Ÿ›  Bonus: Run Cypress in Headless Mode

To run tests without opening the Cypress UI:

npx cypress run

It runs in the terminal and outputs test results.


๐Ÿ“Œ Folder Structure Overview

cypress/ └── e2e/ → Your test files └── support/ → Custom commands, hooks cypress.config.js → Cypress settings

✅ You’re Done!

Now Cypress is installed and ready to test your app. ๐ŸŽ‰


๐Ÿ’ก Tip:

  • You can also install Cypress globally, but it's best to keep it project-specific.

  • Use cypress.config.js to customize test settings, base URL, timeouts, etc.


๐Ÿ”— Useful Links


Comments

Popular posts from this blog

Why Choose Python for Full-Stack Web Development

How Generative AI Differs from Traditional AI

What is Tosca? An Introduction