0
0
CypressHow-ToBeginner ยท 3 min read

How to Install Cypress: Step-by-Step Guide

To install Cypress, run npm install cypress --save-dev in your project folder using a terminal. Alternatively, use yarn add cypress --dev if you prefer yarn as your package manager.
๐Ÿ“

Syntax

Use the following commands in your project folder terminal to install Cypress:

  • npm: npm install cypress --save-dev installs Cypress as a development dependency.
  • yarn: yarn add cypress --dev does the same using yarn.

After installation, you can open Cypress with npx cypress open or yarn run cypress open.

bash
npm install cypress --save-dev
๐Ÿ’ป

Example

This example shows how to install Cypress using npm and then open the Cypress Test Runner.

bash
npm install cypress --save-dev
npx cypress open
Output
Installing packages... + cypress@12.17.0 added 1 package in 10s Opening Cypress Test Runner... Cypress Test Runner window opens allowing you to run tests.
โš ๏ธ

Common Pitfalls

Common mistakes when installing Cypress include:

  • Running the install command outside your project folder, causing Cypress to install globally or fail.
  • Not having node and npm installed or outdated versions.
  • Using npm install cypress without --save-dev which adds Cypress as a regular dependency instead of a dev dependency.
  • Not running npx cypress open after installation to verify it works.
bash
Wrong:
npm install cypress

Right:
npm install cypress --save-dev
๐Ÿ“Š

Quick Reference

Summary tips for installing Cypress:

  • Always install Cypress as a dev dependency.
  • Use npx cypress open to launch the test runner after install.
  • Ensure Node.js and npm are installed and updated.
  • Run commands inside your project folder.
โœ…

Key Takeaways

Install Cypress using npm install cypress --save-dev or yarn add cypress --dev inside your project folder.
Always run npx cypress open after installation to open the Cypress Test Runner.
Make sure Node.js and npm are installed and updated before installing Cypress.
Avoid installing Cypress globally; keep it as a development dependency in your project.
Run all commands in the terminal inside your project directory to avoid path issues.