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-devinstalls Cypress as a development dependency. - yarn:
yarn add cypress --devdoes 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
nodeandnpminstalled or outdated versions. - Using
npm install cypresswithout--save-devwhich adds Cypress as a regular dependency instead of a dev dependency. - Not running
npx cypress openafter 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 opento 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.