In this tutorial, I would be discussing step by step on how to install cypress via npm. This tutorial can be used for both Mac and Windows.

Step 1: Download and Install Node js and npm from the Node JS Official website. Both Node Js and Node package manager(npm) will be installed from a single installer file.

Node js download

node js install

Step 1(a): For windows, we have to do just one additional step after Step 1, which is to set the NODE_HOME in the environment variable. To set the environment variable, go to My Computer(or This PC) -> Properties -> Advanced System Settings -> Environment Variables -> System Variables (New) and then input Variable name as NODE_HOME and Variable value as C:\Program Files\nodejs (By default Node JS is installed under Program Files, in case if it’s not there, mention the correct path) and click OK.

node js system variable

 

Step 2: Create a folder where you will install cypress.

create folder from terminal

 

Step 3: The next step is to create a package.json file inside our folder. Package.json files contain the metadata of the relevant project. To create the file, open Terminal(for MAC) or Command Prompt(for Windows) and run the command –

1
npm init

If you want to read more about package JSON you can refer to this article. After npm init you will be asked to input a few details, but except package name, version, description, author press Enter key keeping the value as empty for all other options. The screenshot below will give you a better idea.

create package json with npm init

 

Step 4: We will now install cypress inside our folder. You can find the commands to install cypress from here. The command we will use is:

1
npm install cypress --save-dev

npm install cypress

During the installation, we can ignore all warnings and notices that we get. Once the installation is successful we could see a node_modules folder and a package-lock.json file being created.

 

Step 5: Next step is to create the cypress specific folders. To do that we will run the command:

1
node_modules/.bin/cypress open

Two things will happen. One, the cypress Test Runner will open. Second, a folder named cypress and a file named cypress.json will be created.

cypress test runner

cypress folder

 
That’s it! You’ve successfully installed cypress. If you’re facing any issues while installing cypress or have any questions, please let me know in the comments.

Do check out 🙂

Github: https://github.com/alapanme/Cypress-Automation
All Cypress Articles: https://testersdock.com/cypress-tutorial/