03 Cypress Setup - biswajitsundara/Cypress GitHub Wiki

1. Install Node.Js

  • Search "node download" in google or go to https://nodejs.org/en/download/
  • For windows download the installer (.msi) as per the system 32 or 64 bit.
  • Once installed go to program files/node js folder and copy the path C:\Program Files\nodejs
  • Create a new environment variable under system variables NODE_HOME with the above path
  • Append the path in Path variable also.
  • Then open command prompt and type this command node -v
  • If it returns the version number like v12.18.2 then node js is successfully installed.

2. Check npm is available

  • npm stands for node package manager. It's included in the Node.Js
  • Open command prompt and type this command npm -v
  • If it returns the version number like 6.14.5 then node js is successfully installed.

3. Install Visual Studio Code IDE

4. Install Cypress

  • Create an empty folder with name Cypress Basics and open the same in VS
  • Go to terminal and enter the command npm init -y this will create a basic package.json file
  • Then enter this command npm install cypress --save-dev this will download the desktop & CLI version of cypress tool
  • Once done then enter this command to run the test runner node_modules\.bin\cypress open
  • The test runner UI will open, under examples folder, click on any spec.js file, it will start executing the script.
  • Once the above steps are done, it will create a skeleton of Cypress project.
  • If you see cypress.json file, folders like fixtures, integration, plugins, support etc then installation is successful.

5. Update package.json

Though we can use the command node_modules\.bin\cypress open to open the test runner every time but it looks bit odd. So the best way is to add the command in package.json

{
  "scripts": {
    "cypress:open": "cypress open"
  }
}

Then to launch the test runner enter this command npm run cypress:open

6. Create jsconfig.json

To bring auto suggestions (means we type cy dot, and suggested methods should appear) in the editor we need to add below line to all the files.
/// <reference types="cypress" /> however the best approach will be to create jsconfig.json file under root folder and add the settings.

{
   "include": [
     "./node_modules/cypress",
     "cypress/**/*.js"
   ]

}

Alternate Download

Let's say if your company has any proxy or you are having trouble downloading through npm then you can use this approach to install cypress.

Tips & Tricks

If we want to format the code in Visual Studio Editor then use the keys Shift + Alt + F

Reference

https://docs.cypress.io/

⚠️ **GitHub.com Fallback** ⚠️