Best Practices
@be_mannBrian Mann
• Organizing Tests
• Writing Tests
• Logging In
• Controlling State
What is Cypress?
First Commit
June 5th, 2014
Today
Public Beta
Oct 9th, 2017
gothinkster/realworld
https://demo.realworld.io
“…a medium.com clone”
Cypress - Best Practices
Organizing Tests
header_spec.jsƭ
Not Logged In
Logged In
login_spec.jsƭ
Login
http://BASE_URL/#/login
register_spec.jsƭ
Register
http://BASE_URL/#/register
settings_spec.jsƭ
Settings
http://BASE_URL/#/settings
Log out
articles_spec.jsƭ
Articles
Tags
http://BASE_URL/#/
article_spec.jsƭ
Article
http://BASE_URL/#/article/:slug
Comments
author_spec.jsƭ
Author
http://BASE_URL/#/@:author
?
new_article_spec.jsƭ
New Article
http://BASE_URL/#/editor
Cypress - Best Practices
Cypress - Best Practices
• View Articles
• View Article
• View Author
• View Comments
• Log In
• Register
Logged InNot Logged In
• Settings
• Log Out
• Create Article
• Edit Article
• Delete Article
• Favorite Articles
• Create Comments
• Delete Comments
Logging In
Edit Article
Delete Article
Favorite Article
Settings
Log Out Create Comment
Delete Comment
Create Article
View Article
View Comment
Register Log InServer
Database
Strategies
1
Stub Requests Control the network
- cy.server()
- cy.route()
- Set status codes
- Set response bodies
- Test edge cases (empty views / 500)
Fast, Easy, Flexible
No Server / DB
Not True E2E
Requires Fixtures
Strategies
1
Stub Requests
Fast, Easy, Flexible
No Server / DB
Not True E2E
Requires Fixtures
2
Static User
Shared User + Credentials
- OAuth Login (Github / Google)
- Pre-seeded Databases
- joe@example.com / joe
Strategies
1
Stub Requests
Fast, Easy, Flexible
No Server / DB
Not True E2E
Requires Fixtures
2
Static User
Real Session E2E
Shares Test State
Seed the DB
Requires Server
Strategies
1
Stub Requests
Fast, Easy, Flexible
No Server / DB
Not True E2E
Requires Fixtures
2
Static User
Real Session E2E
Shares Test State
Seed the DB
Requires Server
3
Dynamic User
New User for each Test
- Modify DB within Tests
- Query DB within Tests
Strategies
1
Stub Requests
Fast, Easy, Flexible
No Server / DB
Not True E2E
Requires Fixtures
2
Static User
Real Session E2E
Shares Test State
Seed the DB
Requires Server
3
Dynamic User
No State Mutations
Slow / Complex
DB Setup / Teardown
Flexible / Powerful
Cypress - Best Practices
Organizing
Tests
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
cypress
integration
ƭ login_spec.js 100% Confidence
Cypress - Best Practices
Cypress - Best Practices
Login Steps
Settings
Settings
Brittle Selectors
Abstraction
Reusable
Decoupled
What’s needed?
Duplicated Code
Settings
cypress
integration
ƭ login_spec.js
ƭ settings_spec.js
support
ƭ index.js
ƭ commands.js
settings_spec.js
login_spec.js
support/index.js
support/commands.js
Cypress - Best Practices
Settings
Commands (7 of 9)
Failed at testing in isolation
Settings
Commands (7 of 9)
Failed at testing in isolation
Added 0% more confidence
ƭ login_spec.js 100% Confidence
Settings
Commands (7 of 9)
Accounted for 75% of the duration
Failed at testing in isolation
Added 0% more confidence
1. onFormSubmit
2. Reads form values
1. onFormSubmit
2. Reads form values
3. POST /api/users/login
Request
1. onFormSubmit
2. Reads form values
3. POST /api/users/login
4. Success: Save Token
Response
1. onFormSubmit
2. Reads form values
3. POST /api/users/login
4. Success: Save Token
5. On load, check for token
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Cypress - Best Practices
Best Practices
Don’t use the UI to build up state
Set state directly / programmatically
Don’t use page objects to share UI knowledge
Write specs in isolation, avoid coupling
Don’t limit yourself trying to act like a user
You have native access to everything
No Constraints
•Control Time: cy.clock()
•Stub Objects: cy.stub()
•Modify Stores: cy.window()
Redux Store
docs.cypress.io
www.cypress.io

More Related Content

PDF
e2e testing with cypress
PPTX
End to end test automation with cypress
PPTX
Why you should switch to Cypress for modern web testing?
PPTX
Cypress Testing.pptx
PPTX
Introduction to Integration Testing With Cypress
PDF
Automated testing with Cypress
PDF
Cypress testing
e2e testing with cypress
End to end test automation with cypress
Why you should switch to Cypress for modern web testing?
Cypress Testing.pptx
Introduction to Integration Testing With Cypress
Automated testing with Cypress
Cypress testing

What's hot (20)

PPTX
How to Get Started with Cypress
PPTX
Cypress Automation
PPTX
Cypress for Testing
PDF
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
PPTX
Progressive Web App Testing With Cypress.io
PDF
Introduction cypress
PDF
Getting Started With Cypress
PDF
Cypress e2e automation testing - day1 intor by: Hassan Hameed
PPTX
Introduction to cypress in Angular (Chinese)
PPTX
Cypress E2E Testing
PPTX
Cypress first impressions
PPTX
Cypress report
PDF
Introduction to E2E in Cypress
PPTX
QA Challenge Accepted 4.0 - Cypress vs. Selenium
PPTX
End to end test automation with cypress
PPT
Automation With A Tool Demo
PPSX
Cucumber & gherkin language
DOCX
Cypress.docx
PPTX
Test Automation Framework with BDD and Cucumber
PDF
Testes automatizados com Cypress
How to Get Started with Cypress
Cypress Automation
Cypress for Testing
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Progressive Web App Testing With Cypress.io
Introduction cypress
Getting Started With Cypress
Cypress e2e automation testing - day1 intor by: Hassan Hameed
Introduction to cypress in Angular (Chinese)
Cypress E2E Testing
Cypress first impressions
Cypress report
Introduction to E2E in Cypress
QA Challenge Accepted 4.0 - Cypress vs. Selenium
End to end test automation with cypress
Automation With A Tool Demo
Cucumber & gherkin language
Cypress.docx
Test Automation Framework with BDD and Cucumber
Testes automatizados com Cypress
Ad

Similar to Cypress - Best Practices (20)

PPTX
cypress course slides e2e automatic testing .pptx
PDF
Cypress Best Pratices for Test Automation
PPTX
Building reliable web applications using Cypress
PDF
Cypress Testing Demystified: A Practical Guide
PPTX
Slides for Automation Testing or End to End testing
PDF
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
PDF
Automated testing in javascript
PDF
Cypress Automation : Increase Reusability with Custom Commands
PDF
Testing the way it should be
PPTX
Automation using Cypress
PDF
Testing at Both Ends of the Triangle
PDF
MoT Athens meets Thessaloniki Software Testing & QA meetup
PDF
Cypress Test Automation: Managing Complex Interactions
PPTX
Cypress.pptx
PDF
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
PDF
Boosting QA Efficiency: Benefits of Cypress for API Automation
PPTX
Jordan Powell - API Testing with Cypress.pptx
PDF
Testing Without Waste - Automatic Testing
PDF
Testing at Both Ends of the Triangle.
PPTX
Introduction toTesting with Cypress (Tool)
cypress course slides e2e automatic testing .pptx
Cypress Best Pratices for Test Automation
Building reliable web applications using Cypress
Cypress Testing Demystified: A Practical Guide
Slides for Automation Testing or End to End testing
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Automated testing in javascript
Cypress Automation : Increase Reusability with Custom Commands
Testing the way it should be
Automation using Cypress
Testing at Both Ends of the Triangle
MoT Athens meets Thessaloniki Software Testing & QA meetup
Cypress Test Automation: Managing Complex Interactions
Cypress.pptx
Achievement Unlocked: Drive development, increase velocity, and write blissfu...
Boosting QA Efficiency: Benefits of Cypress for API Automation
Jordan Powell - API Testing with Cypress.pptx
Testing Without Waste - Automatic Testing
Testing at Both Ends of the Triangle.
Introduction toTesting with Cypress (Tool)
Ad

Recently uploaded (20)

PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Unlock new opportunities with location data.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
August Patch Tuesday
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
STKI Israel Market Study 2025 version august
PPTX
The various Industrial Revolutions .pptx
O2C Customer Invoices to Receipt V15A.pptx
WOOl fibre morphology and structure.pdf for textiles
observCloud-Native Containerability and monitoring.pptx
Benefits of Physical activity for teenagers.pptx
Hindi spoken digit analysis for native and non-native speakers
A comparative study of natural language inference in Swahili using monolingua...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Unlock new opportunities with location data.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
sustainability-14-14877-v2.pddhzftheheeeee
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
August Patch Tuesday
Module 1.ppt Iot fundamentals and Architecture
DP Operators-handbook-extract for the Mautical Institute
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
STKI Israel Market Study 2025 version august
The various Industrial Revolutions .pptx

Cypress - Best Practices