How to install or Setup Cypress in Windows - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Thursday, 16 July 2020

How to install or Setup Cypress in Windows

Installation of Cypress

Downloading Cypress

Run the below command in power shell
npm install cypress










After Installation is done, you will see something like below in terminal

Finished Installation C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0

You can now open Cypress by running: node_modules\.bin\cypress open

https://on.cypress.io/installing-cypress


Steps to create a Node Project

1.) Go to Cypress Path in my case (C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress)
2.) Create a test folder under this path

Under that path write command "npm init"

C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress\test> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (test)


Keep pressing Enter :)

You will see package.json file created









Package,json will look like

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Type below command
PS C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress\test> npm install --save-dev cypress

Till now, we have downloaded node and initialized npm, Here in this command ,install Cypress so that we can start writing our tests

This will install the latest version of Cypress for you and –save-dev saves the dependencies in package.json so that if you share this project with a colleague, he/she need not repeat the same activity.

Now after Cypress is installed
If you open package.json file , it should look like below add devDependencies  should be added

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^4.9.0"
  }
}


How to Open or Run Cypress

PS C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress\test> .\node_modules\.bin\cypress open


























Cypress will be opened and look like above

This is list of existing test cases (actions.spec.js)

Open Sublime
Create a folder under integration


















Create a new js file example CBT.js 

/// <reference types="cypress" />

context('Window', () => {
  beforeEach(() => {
    cy.visit('https://scrolltest.com')
  })

  it('cy.window() - get the global window object', () => {
    // https://on.cypress.io/window
    cy.window().should('have.property', 'top')
  })
})

No comments:

Post a Comment