SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Automate your tests
with Cypress
Yong Shean
About myself
Yong Shean
Frontend Engineer /
WWCodeKL member
Blog :
:
:
yshean
@shin_chong
yshean.logdown.com 

(moving to yshean.github.io)
What this talk covers
• Helps you convince yourself / your manager to put time
and effort into writing tests

• High-level use cases

• 🔥 Some tips and tricks

• Link you up to key resources
What would not be covered
• Advanced use cases

• What is already covered in Cypress official documentation
What is ?
• A UI end-to-end testing framework

• Test scripts are written in Javascript

• Doesn’t matter how your web application is built
The Testing Trophy 🏆
Source: https://testingjavascript.com/
Why do we need it?
• Give confidence, to you and to your users

• ⌛ Save time from repetitive work

• Less worries when refactoring and dealing with change
requests
Why Cypress out of <…>?
• <…> : Selenium, Puppeteer, TestCafe, etc.

• Easy to setup

• Easy to write (it is Javascript)

• 🐞 Easy to debug

• Well-documented and easy to understand

• Fast to execute - can be incorporated into CI/CD pipeline
What Cypress cannot do
• Doesn’t support:

• certain native browser events: https://github.com/cypress-io/cypress/issues/
311 (file upload, mouse over, etc.)

• cross browser testing - yet (only Chrome and Electron for now)

• headless Chrome - yet

• iframe - yet

• Cross-domain testing

• OAuth 

• Read up on permanent and temporary trade-offs (https://docs.cypress.io/
guides/references/trade-offs.html#Permanent-trade-offs-1) and known issues:
https://docs.cypress.io/guides/references/known-issues.html
How to get started
• Create a new folder (say, test-my-app)

• Inside your folder, run yarn add cypress —dev
(or npm install cypress —save-dev) (yes, you need Node
installed)

• npx cypress open
npx cypress open
Where are the test
scripts?
• Open test-my-app folder

• Your tests will sit under cypress/
integration folder. 

• Usually name as <module>.spec.js
Real-world example
http://demo.realworld.io/#/
Today’s content is inspired by this video:

https://www.youtube.com/watch?v=5XQOK0v_YRE
What to test?
List down all the pages inside:

1. Register

2. Login

3. Settings

4. List Articles

5. View Article

6. Create New Article
What to test?
List down all the pages inside:

1. Register

2. Login

3. Settings

4. List Articles - Pagination, likes, tags, information displayed
properly?

5. View Article - Title, description displayed properly? Can edit or
delete article? Comments - can add new comment, edit comment?

6. New Article - Form validation, links working properly? Does publish
button creates a new article with the provided input?
Form validation, links and
buttons are working properly?
Identify the sequence
• What should be tested first? - Depends on your app

1. Register (before login)

2. Login (before login) - need to register first

3. Settings (after login) - need to login first

4. List Articles (before/after login) - need to create new article first

5. View Article (before/after login) - need to create new article first

6. Create New Article (after login) - need to login first
Create the files
1. Register: register.spec.js

2. Login: login.spec.js

3. Settings: settings.spec.js

4. Create New Article: article_new.spec.js

5. List Articles: articles.spec.js

6. View Article: article.spec.js
register.spec.js
https://speakerdeck.com/brianmann/cypress-best-practices
register.spec.js
beforeEach:
is where you put the function
to run before every “it”
Useful for:

- visiting the target page

- log in process

- setting up clean state
register.spec.js
register.spec.js
register.spec.js
It works!
What if the element to
select has a dynamic
classname?
Let’s say you want to test the
“Home” link…
Tips: You can copy from Cypress’ selector
playground…
And it works, but…
When the classname change, you need to
change your test script
NOT ROBUST to
development code
refactoring
Cypress-testing-library to the rescue!
https://github.com/testing-library/cypress-testing-library
Usage
Add this line to your project's cypress/support/
commands.js:

import “cypress-testing-library/add-commands”;
Now you can just write like
this…
What if the element you
wanna test is not visible?
Let’s say you want to click on the
“Basic” link inside the side menu…
Because it’s hidden, you need to click
on the menu icon first…
Of course, you also can get the selector
from Cypress’ selector playground…
Then click on the “Basic” link when it
becomes visible…
But if you (or your team) use styled-components,
the generated classname might change!
And just put inside the get()…
Tips for selecting icon/image
element: look for alt text or title
This should work… 🤔
Oops… Cypress complains that the
element is not visible (or covered by
another element)
Add {force: true} if you know
what you’re doing…
And it works! 🎉
Comparing both
approaches
There is countless ways to select an
element… but which is the most suitable
one?
https://testing-library.com/docs/guide-which-query
Luckily there’s a guide! Use this as your testing bible:
Takeaways
• Cypress can be used to test your web application as long
as it can be opened with Chrome

• Planning your tests is as important as executing them

• Test as if you’re the tester, not as if you’re the developer

• Read up docs and guides on Cypress 

• Listen to Kent C. Dodds for testing advice
We’re hiring!
• React developers

• Node + GraphQL developers

• QA engineers (bonus if you know how to write automated
tests ;))
Both experienced and non-experienced (but
passionate at learning) are welcomed!



Pls send resume to joel.choo@finexusgroup.com
(or talk to me!) if you’re interested.
finexusgroupofficial

Weitere ähnliche Inhalte

Was ist angesagt?

Getting Started With Cypress
Getting Started With CypressGetting Started With Cypress
Getting Started With CypressKnoldus Inc.
 
Why you should switch to Cypress for modern web testing?
Why you should switch to Cypress for modern web testing?Why you should switch to Cypress for modern web testing?
Why you should switch to Cypress for modern web testing?Shivam Bharadwaj
 
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
 
e2e testing with cypress
e2e testing with cypresse2e testing with cypress
e2e testing with cypressTomasz Bak
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressionsHans Emmel
 
Progressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.ioProgressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.ioKnoldus Inc.
 
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
 
Introduction cypress
Introduction cypressIntroduction cypress
Introduction cypressOim Trust
 
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
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Hong Tat Yew
 
QA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumQA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumLyudmil Latinov
 
Cypress test techniques cucumber bdd framework,tdd,api tests course
Cypress test techniques cucumber bdd framework,tdd,api tests courseCypress test techniques cucumber bdd framework,tdd,api tests course
Cypress test techniques cucumber bdd framework,tdd,api tests courseNarayanan Palani
 
Cypress report
Cypress reportCypress report
Cypress reportAdarsh
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Mindfire Solutions
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewDisha Srivastava
 
Introduction to E2E in Cypress
Introduction to E2E in CypressIntroduction to E2E in Cypress
Introduction to E2E in CypressFabio Biondi
 

Was ist angesagt? (20)

Getting Started With Cypress
Getting Started With CypressGetting Started With Cypress
Getting Started With Cypress
 
Why you should switch to Cypress for modern web testing?
Why you should switch to Cypress for modern web testing?Why you should switch to Cypress for modern web testing?
Why you should switch to Cypress for modern web testing?
 
Cypress for Testing
Cypress for TestingCypress for Testing
Cypress for Testing
 
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
 
e2e testing with cypress
e2e testing with cypresse2e testing with cypress
e2e testing with cypress
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressions
 
Progressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.ioProgressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.io
 
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
 
Introduction cypress
Introduction cypressIntroduction cypress
Introduction cypress
 
Component testing with cypress
Component testing with cypressComponent testing with cypress
Component testing with cypress
 
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 Testing
Cypress E2E TestingCypress E2E Testing
Cypress E2E Testing
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
QA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumQA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. Selenium
 
Cypress test techniques cucumber bdd framework,tdd,api tests course
Cypress test techniques cucumber bdd framework,tdd,api tests courseCypress test techniques cucumber bdd framework,tdd,api tests course
Cypress test techniques cucumber bdd framework,tdd,api tests course
 
Cypress report
Cypress reportCypress report
Cypress report
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Gherkin /BDD intro
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 
Introduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiewIntroduction to Automation Testing and Selenium overiew
Introduction to Automation Testing and Selenium overiew
 
Introduction to E2E in Cypress
Introduction to E2E in CypressIntroduction to E2E in Cypress
Introduction to E2E in Cypress
 

Ähnlich wie Automated testing with Cypress

Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Dinis Cruz
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoElad Elrom
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Easy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React StyleguidistEasy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React StyleguidistJames Stone
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkSusannSgorzaly
 
Owasp tds
Owasp tdsOwasp tds
Owasp tdssnyff
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineAnup Singh
 
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpnSync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpnLorenzo Barbieri
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascriptMichael Yagudaev
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5Derek Jacoby
 

Ähnlich wie Automated testing with Cypress (20)

Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Automated testing
Automated testingAutomated testing
Automated testing
 
Selenium Training in Chennai
Selenium Training in ChennaiSelenium Training in Chennai
Selenium Training in Chennai
 
Selenium training in chennai
Selenium training in chennaiSelenium training in chennai
Selenium training in chennai
 
Easy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React StyleguidistEasy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React Styleguidist
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Owasp tds
Owasp tdsOwasp tds
Owasp tds
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
 
Selenium training in chennai
Selenium training in chennaiSelenium training in chennai
Selenium training in chennai
 
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpnSync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpn
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascript
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5
 

Kürzlich hochgeladen

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 

Kürzlich hochgeladen (20)

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 

Automated testing with Cypress

  • 1. Automate your tests with Cypress Yong Shean
  • 2. About myself Yong Shean Frontend Engineer / WWCodeKL member Blog : : : yshean @shin_chong yshean.logdown.com 
 (moving to yshean.github.io)
  • 3. What this talk covers • Helps you convince yourself / your manager to put time and effort into writing tests • High-level use cases • 🔥 Some tips and tricks • Link you up to key resources
  • 4. What would not be covered • Advanced use cases • What is already covered in Cypress official documentation
  • 5. What is ? • A UI end-to-end testing framework • Test scripts are written in Javascript • Doesn’t matter how your web application is built
  • 6. The Testing Trophy 🏆 Source: https://testingjavascript.com/
  • 7. Why do we need it? • Give confidence, to you and to your users • ⌛ Save time from repetitive work • Less worries when refactoring and dealing with change requests
  • 8. Why Cypress out of <…>? • <…> : Selenium, Puppeteer, TestCafe, etc. • Easy to setup • Easy to write (it is Javascript) • 🐞 Easy to debug • Well-documented and easy to understand • Fast to execute - can be incorporated into CI/CD pipeline
  • 9. What Cypress cannot do • Doesn’t support: • certain native browser events: https://github.com/cypress-io/cypress/issues/ 311 (file upload, mouse over, etc.) • cross browser testing - yet (only Chrome and Electron for now) • headless Chrome - yet • iframe - yet • Cross-domain testing • OAuth • Read up on permanent and temporary trade-offs (https://docs.cypress.io/ guides/references/trade-offs.html#Permanent-trade-offs-1) and known issues: https://docs.cypress.io/guides/references/known-issues.html
  • 10. How to get started • Create a new folder (say, test-my-app) • Inside your folder, run yarn add cypress —dev (or npm install cypress —save-dev) (yes, you need Node installed) • npx cypress open
  • 12. Where are the test scripts? • Open test-my-app folder • Your tests will sit under cypress/ integration folder. • Usually name as <module>.spec.js
  • 13. Real-world example http://demo.realworld.io/#/ Today’s content is inspired by this video: https://www.youtube.com/watch?v=5XQOK0v_YRE
  • 14.
  • 15. What to test? List down all the pages inside: 1. Register 2. Login 3. Settings 4. List Articles 5. View Article 6. Create New Article
  • 16. What to test? List down all the pages inside: 1. Register 2. Login 3. Settings 4. List Articles - Pagination, likes, tags, information displayed properly? 5. View Article - Title, description displayed properly? Can edit or delete article? Comments - can add new comment, edit comment? 6. New Article - Form validation, links working properly? Does publish button creates a new article with the provided input? Form validation, links and buttons are working properly?
  • 17. Identify the sequence • What should be tested first? - Depends on your app 1. Register (before login) 2. Login (before login) - need to register first 3. Settings (after login) - need to login first 4. List Articles (before/after login) - need to create new article first 5. View Article (before/after login) - need to create new article first 6. Create New Article (after login) - need to login first
  • 18. Create the files 1. Register: register.spec.js 2. Login: login.spec.js 3. Settings: settings.spec.js 4. Create New Article: article_new.spec.js 5. List Articles: articles.spec.js 6. View Article: article.spec.js
  • 20. register.spec.js beforeEach: is where you put the function to run before every “it” Useful for: - visiting the target page - log in process - setting up clean state
  • 24. What if the element to select has a dynamic classname?
  • 25. Let’s say you want to test the “Home” link… Tips: You can copy from Cypress’ selector playground…
  • 26. And it works, but… When the classname change, you need to change your test script NOT ROBUST to development code refactoring
  • 27.
  • 28.
  • 29. Cypress-testing-library to the rescue! https://github.com/testing-library/cypress-testing-library
  • 30. Usage Add this line to your project's cypress/support/ commands.js: import “cypress-testing-library/add-commands”;
  • 31. Now you can just write like this…
  • 32. What if the element you wanna test is not visible?
  • 33. Let’s say you want to click on the “Basic” link inside the side menu… Because it’s hidden, you need to click on the menu icon first…
  • 34. Of course, you also can get the selector from Cypress’ selector playground… Then click on the “Basic” link when it becomes visible…
  • 35. But if you (or your team) use styled-components, the generated classname might change! And just put inside the get()…
  • 36. Tips for selecting icon/image element: look for alt text or title
  • 38. Oops… Cypress complains that the element is not visible (or covered by another element)
  • 39. Add {force: true} if you know what you’re doing…
  • 42. There is countless ways to select an element… but which is the most suitable one? https://testing-library.com/docs/guide-which-query Luckily there’s a guide! Use this as your testing bible:
  • 43. Takeaways • Cypress can be used to test your web application as long as it can be opened with Chrome • Planning your tests is as important as executing them • Test as if you’re the tester, not as if you’re the developer • Read up docs and guides on Cypress • Listen to Kent C. Dodds for testing advice
  • 44. We’re hiring! • React developers • Node + GraphQL developers • QA engineers (bonus if you know how to write automated tests ;)) Both experienced and non-experienced (but passionate at learning) are welcomed!
 
 Pls send resume to joel.choo@finexusgroup.com (or talk to me!) if you’re interested. finexusgroupofficial