YouTube magic that brings views, likes and suibscribers
Get Free YouTube Subscribers, Views and Likes

Cypress Complete Beginners Masterclass 3 | Step by Step | Raghav Pal |

Follow
Automation Step by Step

All FREE courses https://automationstepbystep.com/
QUIZ https://forms.gle/MJFQSFU6bkFP8Ter9
CLI
Package.json
File Handling
(Read, Write, Upload, Download)

In next parts:
Reporting
API Testing
Custom Commands
Cypress Studio
Cypress Dashboard
Cypress BDD Framework
Database Integration

Why CLI
easier, faster, efficient
less memory consuming
to integrate testing with external process
CI & CD

Step 1 Open terminal and run command
npx cypress run
npx cypress run help
spec or s
browser or b
headless

Step 2 Open package.json file
Step 3 Add under scripts section
Every line under this section can be run with npm run command

"scripts": {
"test": "echo \" Hello World\"",
"log" : "echo Hello",
"cytest" : "cypress run"
}

npm run cytest

Step 4 Can set configurations from command line

Syntax: cypress run config configValues
cypress run config pageLoadTimeout=100000,watchForFileChanges=false

Cypress Commands

cypress run Runs cypress tests from CLI
cypress open Opens Cypress App
cypress verify Verifies Cypress is installed correctly and is executable
cypress version Prints Cypress version
cypress info Prints information about Cypress and current Env
cypress cache Prints info about global Cypress cache

What is package.json
Every Node.js project has package.json file located in the root folder
Information about NodeJS project
List of dependencies with version
How to create :
npm init
npm init y

devDependencies used during dev or build phase
npm install installs both dev and normal dependencies
npm install dev installs only dev dependencies
npm install prod will not include dev dependencies
~1.2.3 will match all 1.2.x versions but will miss 1.3.0
^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0

Package.json
records the minimum version needed (with ^ and ~)
is used for more than dependencies like defining project info, description, author & license, scripts, etc

Packagelock.json
records the exact version of each installed package which allows you to reinstall them
locks the dependencies with the installed version

Difference between tilde (~) and caret (^) in package.json

On npm install get the latest minor or patch version of the dependency mentioned in package.json

^ install the latest minor version 1.x.x
tells npm that if someone clones the project and runs npm install then install the latest minor version of the package in his node_modules

~ install the latest patch version 1.2.x
tells npm that if someone clones the project and runs npm install then install the latest patch version of the package in his node_modules

~1.2.3 will match all 1.2.x versions but will miss 1.3.0
^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0

How to Read and Write files in Cypress
Read files using fixture()
Read files using readFile()
Write files using writeFile()

Read files using fixture()

Step 1 Create a new test spec file
Step 2 Add a file under fixtures folder
Step 3 Create a test and add command
Step 4 To use data from file in all tests create a before function
Step 5 Now use data from file in tests

Notes
If the file is in fixture folder it can be referenced directly by name without extension
For a JSON file its function can be used to access the values using keys
cy.fixture("filename").its('name').should('eq', 'hello')

Read files using readFile()
Step 1 Create a new test in spec file
Step 2 Test commands
Step 3 Use cy.readFile() function

For JSON files can use its .its('name').should('eq', ‘ data ‘)

Write files using writeFile()
Step 1 Create a new test in spec file
Step 2 Test commands
cy.writeFile('sample.txt', 'Hello l am learning Cypress\n')
cy.writeFile('sample.txt', 'Hello I am Raghav', { flag: 'a+' })

Relative file paths can be used
cy.writeFile('./cypress/fixtures/files/sample.txt','Hell World’')
____________________________________________________________
Stories by Raghav https://automationstepbystep.com/stor...
My Udemy Courses https://automationstepbystep.com/udem...

Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you

You can support my mission for education by sharing this knowledge and helping as many people as you can

If my work has helped you, consider helping any animal near you, in any way you can

Ask Raghav https://bit.ly/2CoJGWf
Interviews https://bit.ly/2NIPPxk
All Playlists https://bit.ly/2LSiezA

Connect with Raghav
Udemy Courses https://www.udemy.com/user/raghavpal3/
Twitter   / learnwithraghav  
Youtube    / automationstepbystep  

Never Stop Learning
Raghav

posted by Defereriasu