Professional Documents
Culture Documents
Cypress First Class - Ranjan Dhakal
Cypress First Class - Ranjan Dhakal
InfoDev
Cypress Introduction
• Cypress is an open-source end-to-end testing framework for web applications.
• It is designed to simplify and streamline the process of testing web applications by providing a fast,
reliable, and easy-to-use testing environment.
Cypress InfoDev
Cypress Setup
• For Cypress environment setup(node), visit the link: https://nodejs.org/en/download/
• The screen that will appear is given below.(Download MSI)
Cypress InfoDev
Code Editor Setup
• Next, we need to have a IDE to write the code for Cypress.
• For this, we can download Visual Studio Code from the link https://code.visualstudio.com/
Cypress InfoDev
Install Cypress:
npm install --save-dev cypress
Open Cypress
npx cypress open
Cypress InfoDev
Cypress InfoDev
Cypress InfoDev
Cypress InfoDev
Cypress InfoDev
Cypress InfoDev
Folder Structure
Cypress InfoDev
Test Execution
• From the command line
npx cypress run
Cypress InfoDev
Execution from Other Browsers
• In Chrome
npx cypress run -- browser chrome
• In Firefox
npx cypress run -- browser firefox
Cypress InfoDev
First Cypress test
Cypress InfoDev
First Cypress test
Cypress InfoDev
It and describe grouped
Cypress InfoDev
describe('User management', () => {
context('Registration', () => {
it('should allow a user to register with valid details', () => {
// Test code for user registration with valid details
});
context {
it('should display an error for invalid email during registration', () =>
context('Login', () => {
it('should allow a registered user to log in', () => {
// Test code for user login
});
Cypress InfoDev
cy.get() - Element Selection:
//select by placeholder
cy.get('[placeholder="your_placeholder_text"]’)
// Select by ID
cy.get('#my-id');
// Select by attribute
cy.get('[data-test=my-element]');
// Select by attribute
cy.get('[data-cy=my-element]')
Cypress InfoDev
Commands in Cypress are for Interacting
.click()
.dblclick()
.rightclick()
.type()
.clear()
.check()
.uncheck()
.select()
.trigger()
.selectFile()
.focus()
.blur()
Cypress InfoDev
Task
Learn About Different Trigger actions in cypress
Cypress InfoDev
Assertions in Cypress
1. Validation: The core purpose of testing is to verify if your application behaves as expected. Assertions allow
you to explicitly define your expectations for an element, interaction, or data in your Cypress tests.
2. Failure Detection: Tests without assertions are essentially blind. Assertions help you catch any deviations
from expected behavior by explicitly declaring what constitutes a successful or failed test step.
3. Debugging and Feedback: When an assertion fails, Cypress provides clear error messages indicating the
expected and actual values. This simplifies debugging and helps you identify and fix issues quickly.
Cypress InfoDev
Types of Assertions in Cypress
Cypress InfoDev
Types of Assertions in Cypress
2. Chaining Assertions:
Cypress InfoDev
Types of Assertions in Cypress
Cypress InfoDev
Types of Assertions in Cypress
Cypress InfoDev
Types of Assertions in Cypress
4. Assertion on length :
cy.get('#txt-fld').should('have.length',5)
Cypress InfoDev
Types of Assertions in Cypress
cy.visit('http://localhost:3000/admin')
cy.location('pathname').should('eq', '/login')
Cypress InfoDev
Anything Wrong Here?
Cypress InfoDev
Anything Wrong Here?
Cypress InfoDev
Thank You
Cypress InfoDev