SlideShare a Scribd company logo
1 of 28
Download to read offline
How to build testable UIs
@taishiling
Tai Shi Ling
Co-founder & CEO, UI-licious
Been building web apps since the golden era of
JQuery.
I used to write buggy code.
And I still do.
That’s why I write tests too. :)
Attitudes
Back-end
“How can we make the code
more testable?”
Front-end
“It’s QA’s job.”
That’s wrong!
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
This is what too many UI tests look like
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
Hey, this test is broken…
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
Wonder why...
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
Hmm...
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
… WTF does this do?
The reason why UI tests looks like this vomit...
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
The reason why UI tests looks like this vomit...
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
...is because the UI is not accessible.
Think
How is a screen
reader any different
from a UI testing tool?
How to build testable UIs
Clickable elements
DON’T:
- Use generic elements like <div> or <span>
for clickable elements. Some test engines
ignore generic elements if you are
attempting a click action.
DO:
- Use semantic HTML: If an element is
clickable, use <button>, or <a> if it is a link.
Custom components
DON’T:
- Create a purely javascript custom
component for dropdown, radio buttons,
checkboxes, date pickers.
DO:
- Implement fallbacks for custom components
using native HTML elements.
There’s nothing wrong with the good old
<select> element!
Custom components
Please add a date field for
keyboard input!
DON’T:
- Create a purely javascript custom
component for dropdown, radio buttons,
checkboxes, date pickers.
DO:
- Implement fallbacks for custom components
using native HTML elements.
- E.g. For custom date pickers, add <input
type=’date’/> elements as a fallback.
Here’s an example from MDN.
Custom components
DON’T:
- Create a purely javascript custom
component for dropdown, radio buttons,
checkboxes, date pickers.
DO:
- Implement fallbacks for custom components
using native HTML elements.
- E.g. For custom date pickers, add <input
type=’date’/> elements as a fallback.
- Use the ARIA “role” attribute
Icons
DON’T:
- Use icons without labels, because tests
would otherwise have to be written using
CSS or XPATHs which makes the test
fragile.
DO:
- Use “title” or “aria-label” for an icon if you
really want to save on that screen real
estate
Example test based on “title” or “ARIA-label”
// Selenium
driver.find_element_by_xpath(
"//*[@title="Google apps"]"
).click()
By the way… UI-licious automatically picks up
ARIA-labels and titles!
Example: https://snippet.uilicious.com/test/public/5CRWgffVmkHzvKZrziURCG
General Tips
● Write semantic HTML
● Use the native elements
● Label, label, label
○ <label for>
○ aria-label
In other words, make your UI accessible.
Let’s get back to this nasty thing...
// Selenium
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[1]/div/input").send_keys(“hello@uilicious.com”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/div[2]/div/input").send_keys(“secret”)
driver.find_element_by_xpath("//*[@id="root"]/div[3]/div[2]/di
v/form/button[2]").click()
Let’s test it with UI-licious
Example: https://snippet.uilicious.com/test/public/Ku2YRHYW98D2K3sbyN3DbZ
How to build testable UIs
@taishiling

More Related Content

What's hot

E Pi Server Easy Search Technical Overview
E Pi Server Easy Search Technical OverviewE Pi Server Easy Search Technical Overview
E Pi Server Easy Search Technical Overview
guestd9aa5
 

What's hot (19)

Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
 
Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERE
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
 
Enterprising JavaFX
Enterprising JavaFXEnterprising JavaFX
Enterprising JavaFX
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Angular Classy
Angular ClassyAngular Classy
Angular Classy
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
jQuery Intro
jQuery IntrojQuery Intro
jQuery Intro
 
Have Better Toys
Have Better ToysHave Better Toys
Have Better Toys
 
E Pi Server Easy Search Technical Overview
E Pi Server Easy Search Technical OverviewE Pi Server Easy Search Technical Overview
E Pi Server Easy Search Technical Overview
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a Startup
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFest
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 

Similar to How to build testable UIs

Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
Mark Rackley
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 

Similar to How to build testable UIs (20)

Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
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
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWT
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
jQuery
jQueryjQuery
jQuery
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...
iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...
iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Recently uploaded (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

How to build testable UIs