SlideShare a Scribd company logo
1 of 28
Download to read offline
Cypress
Automation
Testing
Tutorial
(Part 1)
www.bacancytechnology.com
Introduction
We build a good website using different
technologies such as React, Angular, and
other modern technologies. In terms of
testing, the client wants to do either Unit or
End-to-end testing. So in this blog: Cypress
Automation Testing Tutorial, you will learn
how to set up an end-to-end testing
framework called CYPRESS in an angular
application and some basic test cases.
What is
Cypress?
Cypress is an end-to-end automation
testing framework for website testing. If
your project needs to do automation
testing, you can start with cypress. The use
of JavaScript makes Cypress automation
especially attractive to developers.
Tutorial Goal:
Angular
Cypress
Automation
Testing
Before developing an application, let’s see
what we will build. Watch the below video
to understand what our demo app looks
like.
Does it take a hard time for
you to trust when
beginning with your web
app development?
Angular gives you the authentication to feel
secure. Hire Angular Developer to resolve
all your trust issues
Cypress
Automation
Testing
Tutorial:
Steps to
Implement
Install cypress


First, we need to add cypress in our
application, so use the below command to
add cypress in our master branch.
ng add @cypress/schematic
The above command will set up the basic
required configuration with some files and
create one sepc.ts file as a sample cypress
testing file.
npm run cypress:open
The above command will help open a
chrome browser to check the cypress test
cases like the below screen.
Click on the spec.ts file, and it will run the
cypress test cases for that file.


npm run cypress:run
It will run in a terminal and share the spec
success and failure report.
We will now see how to write the actual
cypress test cases using cypress and their
methods. So I hope now you are good with
the setup of this project along with the
cypress, and let’s make our hands dirty on
the cypress.


There are various methods in cypress by
which we can visit a particular URL of our
application. We can pick the element, such
as how we pick the HTML element using a
document.getElementById methods and
check the assertions on that.


This is similar to Unit testing in terms of
writing the spec like we need to write
descriptions, and inside that, we need to
write the spec using its method as displayed
below.
describe('My First Test', () =>{
it('Visits the initial project page', () =>{
cy.visit('/')
cy.contains ('Welcome')
cy.contains ('sandbox app is running!')
})
})
But here, one important thing is you don’t
need to import anything such as service or
any dependency, which we generally do in
the unit testing.


For the unit testing in Angular, you can visit
the previous blog, which can be very helpful
for you. Unit testing in Angular using
Jasmine and Karma (Part 1) and Unit testing
in Angular using Jasmine and Karma (Part 2)
First Test Case: Should Visit
the Login Page
// specs.ts
describe( 'My First Test', () =>{
it('Should visit the login page', ()={
cy.visit('/login');
cy.url().should('includes', 'login')
cy.get('#loginFormTitle').should
('be.visible');
cy.get('#loginFormTitle').should
('have.text', 'Login Form');
})
})
If we modify our existing test case mentioned in
the above image and click on spec.ts as taught
earlier in the blog, it will give output like the
below image with success test cases.
Explanation


What is the meaning of what we have
written in the test cases?


cy.visit(‘/login’);


➡It will visit/redirect to the given URL. For
example, cy.visit(‘/registration’); will visit
automatically to the registration page.
cy.url().should(‘includes’, ‘login’)


➡It will check whether the page where it
should redirect that URL includes the login
as a keyword or not. For example, if we will
use cy.url().should(‘includes’, ‘login1’);
instead of what was mentioned, then it will
give an error like the below image.
And then it will stop the execution of that
spec.
cy.get(‘#loginFormTitle’).should(‘be.visible’);


Using cy.get() method we can get the
element the way we access it using
“document.getelementbyid(#id)” in JS.
We can access a particular element using
class, id. A better practice is to get the
element using id only.
I that element will be in the DOM, then it
will be visible, and we can check cypress
assertions on it using the should() method
like .should(‘be.visible’); if it does not exist
in the dom then we can use
.should(‘not.exist’); For example, How
adding not.exit for the below image.
// specs.ts
describe('My First Test', () =>{
it('Should visit the login page', () =>{
cy.visit('/login');
cy.url().should('includes', 'login');
cy.get('#loginFormTitle').should('be.visible')
;
cy.get('#loginFormTitle').should
('have.text', 'Login Form');
cy.get('#loginFormEmailInputValue').shoul
d('not.exist');
cy.get('#loginFormPasswordInputValue').sh
ould ('not.exist');
})
});
Second Test Case: Should
Enter Valid Email and
Password. Redirect to the
Dashboard


// specs.ts
it Should enter valid email and password
and redirect to the dashboard', ()>{
cy.visit('/login');
cy.url().should ('includes', 'login');
cy.get('#loginFormEmailInput').type('parth
agmail.com);
cy.get('#loginFormPasswordInput').type(
'Parth@123');
cy.get('#loginFormSubmitButton').click();
cy.get('#loginFormEmailInputValue').should
'be.visible');
cy.get
('#loginFormEmailInputValue').should(
'have.text', 'Email: parth@gmail.com');
cy.get
('#loginFormPasswordInputValue').should(
'be.visible');
cy.get('#loginFormPasswordInputValue').sh
ould( 'have.text', 'Password: Parth@123');
});
Now, since you are very familiar with this
type() and click() method, I don’t need to
explain it, Isn’t it?
Github
Repository:
Angular
Cypress
Example
Just visit below the repository and set up
the project.


Github source code: angular-cypress-
example


Open a terminal and run the below
command to set up the demo app in your
local system.




git clone https://github.com/bacancy-
parthsardhara/cypress-testing-angular.git
cd cypress-testing-angular
npm install
ng s -o
Conclusion
So this is the basics of the Cypress test
cases. I hope the Cypress Automation
Testing Tutorial helped you to get started
with testing your Angular app. Feel free to
write us back your suggestions and
feedback. You can visit Cypress’s official
site and check the API. We will be back in
the next part on how to write efficient
cypress test cases.
Thank You
www.bacancytechnology.com

More Related Content

What's hot

Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarApplitools
 
Cypress e2e automation testing - day1 intor by: Hassan Hameed
Cypress e2e automation testing -  day1 intor by: Hassan HameedCypress e2e automation testing -  day1 intor by: Hassan Hameed
Cypress e2e automation testing - day1 intor by: Hassan HameedHassan Muhammad
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best PracticesBrian Mann
 
End to end test automation with cypress
End to end test automation with cypressEnd to end test automation with cypress
End to end test automation with cypressPankajSingh184960
 
Cypress report
Cypress reportCypress report
Cypress reportAdarsh
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressionsHans Emmel
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with PostmanPostman
 

What's hot (20)

Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
 
Cypress testing
Cypress testingCypress testing
Cypress testing
 
End to end test automation with cypress
End to end test automation with cypressEnd to end test automation with cypress
End to end test automation with cypress
 
Cypress e2e automation testing - day1 intor by: Hassan Hameed
Cypress e2e automation testing -  day1 intor by: Hassan HameedCypress e2e automation testing -  day1 intor by: Hassan Hameed
Cypress e2e automation testing - day1 intor by: Hassan Hameed
 
Cypress Automation
Cypress  AutomationCypress  Automation
Cypress Automation
 
Cypress for Testing
Cypress for TestingCypress for Testing
Cypress for Testing
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
 
End to end test automation with cypress
End to end test automation with cypressEnd to end test automation with cypress
End to end test automation with cypress
 
Cypress report
Cypress reportCypress report
Cypress report
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressions
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Component testing with cypress
Component testing with cypressComponent testing with cypress
Component testing with cypress
 
Cypress E2E Testing
Cypress E2E TestingCypress E2E Testing
Cypress E2E Testing
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with Postman
 
BDD with Cucumber
BDD with CucumberBDD with Cucumber
BDD with Cucumber
 
Rest assured
Rest assuredRest assured
Rest assured
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 

Similar to Cypress Automation Testing Tutorial (Part 1).pdf

Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfKaty Slemon
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplifiedVikas Singh
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfJohnLeo57
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Full Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemFull Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemDigamber Singh
 
01 startoff angularjs
01 startoff angularjs01 startoff angularjs
01 startoff angularjsErhwen Kuo
 
Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6AIMDek Technologies
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneAaron Saunders
 
Testing Angular Applications - Jfokus 2017
Testing Angular Applications - Jfokus 2017Testing Angular Applications - Jfokus 2017
Testing Angular Applications - Jfokus 2017Matt Raible
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Katy Slemon
 
Part 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicePart 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicekrishmdkk
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.jsMek Srunyu Stittri
 
Simple setup for an Angular EventEmitter
Simple setup for an Angular EventEmitterSimple setup for an Angular EventEmitter
Simple setup for an Angular EventEmittermike2071
 
angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxshekharmpatil1309
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting startedHemant Mali
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentation
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentationAWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentation
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentationServerless User Group Poland
 
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,..."Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...LCloud
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Page object from the ground up.ppt
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.pptJoseph Beale
 

Similar to Cypress Automation Testing Tutorial (Part 1).pdf (20)

Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplified
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Full Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication SystemFull Angular 7 Firebase Authentication System
Full Angular 7 Firebase Authentication System
 
01 startoff angularjs
01 startoff angularjs01 startoff angularjs
01 startoff angularjs
 
Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part One
 
Testing Angular Applications - Jfokus 2017
Testing Angular Applications - Jfokus 2017Testing Angular Applications - Jfokus 2017
Testing Angular Applications - Jfokus 2017
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...
 
Part 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicePart 1 implementing a simple_web_service
Part 1 implementing a simple_web_service
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
Simple setup for an Angular EventEmitter
Simple setup for an Angular EventEmitterSimple setup for an Angular EventEmitter
Simple setup for an Angular EventEmitter
 
angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptx
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting started
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentation
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentationAWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentation
AWS UG Warsaw & Serverless warsztatowo! 19.09.2019 | Hillel Solow's presentation
 
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,..."Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Page object from the ground up.ppt
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.ppt
 

Recently uploaded

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Cypress Automation Testing Tutorial (Part 1).pdf

  • 3. We build a good website using different technologies such as React, Angular, and other modern technologies. In terms of testing, the client wants to do either Unit or End-to-end testing. So in this blog: Cypress Automation Testing Tutorial, you will learn how to set up an end-to-end testing framework called CYPRESS in an angular application and some basic test cases.
  • 5. Cypress is an end-to-end automation testing framework for website testing. If your project needs to do automation testing, you can start with cypress. The use of JavaScript makes Cypress automation especially attractive to developers.
  • 7. Before developing an application, let’s see what we will build. Watch the below video to understand what our demo app looks like.
  • 8. Does it take a hard time for you to trust when beginning with your web app development? Angular gives you the authentication to feel secure. Hire Angular Developer to resolve all your trust issues
  • 10. Install cypress First, we need to add cypress in our application, so use the below command to add cypress in our master branch. ng add @cypress/schematic The above command will set up the basic required configuration with some files and create one sepc.ts file as a sample cypress testing file.
  • 11. npm run cypress:open The above command will help open a chrome browser to check the cypress test cases like the below screen.
  • 12. Click on the spec.ts file, and it will run the cypress test cases for that file. npm run cypress:run It will run in a terminal and share the spec success and failure report.
  • 13.
  • 14. We will now see how to write the actual cypress test cases using cypress and their methods. So I hope now you are good with the setup of this project along with the cypress, and let’s make our hands dirty on the cypress. There are various methods in cypress by which we can visit a particular URL of our application. We can pick the element, such as how we pick the HTML element using a document.getElementById methods and check the assertions on that. This is similar to Unit testing in terms of writing the spec like we need to write descriptions, and inside that, we need to write the spec using its method as displayed below.
  • 15. describe('My First Test', () =>{ it('Visits the initial project page', () =>{ cy.visit('/') cy.contains ('Welcome') cy.contains ('sandbox app is running!') }) }) But here, one important thing is you don’t need to import anything such as service or any dependency, which we generally do in the unit testing. For the unit testing in Angular, you can visit the previous blog, which can be very helpful for you. Unit testing in Angular using Jasmine and Karma (Part 1) and Unit testing in Angular using Jasmine and Karma (Part 2)
  • 16. First Test Case: Should Visit the Login Page // specs.ts describe( 'My First Test', () =>{ it('Should visit the login page', ()={ cy.visit('/login'); cy.url().should('includes', 'login') cy.get('#loginFormTitle').should ('be.visible'); cy.get('#loginFormTitle').should ('have.text', 'Login Form'); }) }) If we modify our existing test case mentioned in the above image and click on spec.ts as taught earlier in the blog, it will give output like the below image with success test cases.
  • 17. Explanation What is the meaning of what we have written in the test cases? cy.visit(‘/login’); ➡It will visit/redirect to the given URL. For example, cy.visit(‘/registration’); will visit automatically to the registration page.
  • 18. cy.url().should(‘includes’, ‘login’) ➡It will check whether the page where it should redirect that URL includes the login as a keyword or not. For example, if we will use cy.url().should(‘includes’, ‘login1’); instead of what was mentioned, then it will give an error like the below image. And then it will stop the execution of that spec.
  • 19. cy.get(‘#loginFormTitle’).should(‘be.visible’); Using cy.get() method we can get the element the way we access it using “document.getelementbyid(#id)” in JS. We can access a particular element using class, id. A better practice is to get the element using id only. I that element will be in the DOM, then it will be visible, and we can check cypress assertions on it using the should() method like .should(‘be.visible’); if it does not exist in the dom then we can use .should(‘not.exist’); For example, How adding not.exit for the below image.
  • 20. // specs.ts describe('My First Test', () =>{ it('Should visit the login page', () =>{ cy.visit('/login'); cy.url().should('includes', 'login'); cy.get('#loginFormTitle').should('be.visible') ; cy.get('#loginFormTitle').should ('have.text', 'Login Form'); cy.get('#loginFormEmailInputValue').shoul d('not.exist'); cy.get('#loginFormPasswordInputValue').sh ould ('not.exist'); }) });
  • 21.
  • 22. Second Test Case: Should Enter Valid Email and Password. Redirect to the Dashboard // specs.ts it Should enter valid email and password and redirect to the dashboard', ()>{ cy.visit('/login'); cy.url().should ('includes', 'login'); cy.get('#loginFormEmailInput').type('parth agmail.com); cy.get('#loginFormPasswordInput').type( 'Parth@123'); cy.get('#loginFormSubmitButton').click();
  • 25. Just visit below the repository and set up the project. Github source code: angular-cypress- example Open a terminal and run the below command to set up the demo app in your local system. git clone https://github.com/bacancy- parthsardhara/cypress-testing-angular.git cd cypress-testing-angular npm install ng s -o
  • 27. So this is the basics of the Cypress test cases. I hope the Cypress Automation Testing Tutorial helped you to get started with testing your Angular app. Feel free to write us back your suggestions and feedback. You can visit Cypress’s official site and check the API. We will be back in the next part on how to write efficient cypress test cases.