SlideShare a Scribd company logo
1 of 19
Download to read offline
Scalable and Collaborative UI
Test Automation in Swift
Jason Hagglund
Staff Software Eng - Test, The Climate Corporation
https://github.com/TheMetalCode
Twitter - @jhagglund
Where are we going?
● Why bother with UI test automation?
● XCTest API and UI Elements
● Identifying UI Elements (Storyboard and Programmatically)
● Stop Relying on the Recorder and Automate Predictively
● Write Better UI Automation Code with Screen Objects
● Extras
● Questions
2
Why bother with UI test
automation?
Because this talk would be really lame if UI tests weren’t important or
useful.
It’s All About the Pyramid
4
http://martinfowler.com/bliki/TestPyramid.html
Why UI Test Automation Efforts Sometimes Fail
if effortToMaintain > valueAdded {
notWorthIt();
}
5
The iOS UI and the XCTest API
Looking at the structure of what we’re testing and the code that gives us
the access to the UI.
Our Toolbox for iOS UI Automation
● XCode 7+
● XCTest (supports UI testing as of
XCode 7, iOS 9+)
● Swift
7
● On the web: http://masilotti.com/xctest-
documentation/index.html
● Build it locally: https://github.
com/joemasilotti/XCTest-Documentation
Regarding XCTest Documentation...
8
What is XCTest?
9
A build target that targets your application’s build target. Say that 10x fast.
Your XCTest Bread and Butter
● XCUIApplication
○ This class models the application itself and has two functions:
launch and terminate.
● XCUIElement
○ This class models a UI element contained within the
application.
● XCUIElementQuery
○ This class models a search for an element.
10
UI Test Recorder: An Exploration Tool
11
Identify UI Elements from the
Storyboard
The least painful way to uniquely tag our UI elements for automation
purposes
13
Identity Inspector and Accessibility Are Your Friends Accessibility Identifier > Accessibility Label
14
● Lest we forget: the primary purpose of Accessibility-
enabled elements is to allow your app to be used in
accessibility mode on the device.
● Accessibility Labels are what the end user would
actually see/hear in order to interact with your app.
● Accessibility Identifiers don’t leave a mark.
Accessibility Identifier > Accessibility Label
Identify UI Elements
Programmatically
Our first encounter with the power of Swift Protocols
About Those Pesky Dynamically Generated Elements...
● Protocol (similar to an Interface in Java): a collection of
properties, methods, etc., that encapsulate common
behavior that you want otherwise unrelated classes to
share.
● UIKit elements conform to the
UIAccessibilityIdentification protocol, which has exactly
one contract requirement: accessibilityIdentifier.
17
Let’s ID Some Table Cells Programmatically
18
Stop Recording and Write
Predictive UI Tests
The recorder is an exploration tool, not a testing tool.
A Revelation from Morpheus
20
No Really, It’s This Easy (In Many Cases)
var someButton = app.buttons[“accessibilityIdentifier”]
“app” = instance of XCUIApplication
“buttons” = just one of many XCUIElementTypeQueryProvider methods (hey
look, another Protocol!)
“accessibilityIdentifier” = the accessibility identifier you have configured for
that element
21
Why This Matters
● Kill more bugs faster! (enables TDD-like
practices)
● Plus, just looks cleaner. Remember that ugly
recorder-generated code earlier?
22
Write Better UI Automation
with Screen Objects
Your tests are software. Code like it.
Which Would You Rather Maintain?
24
Which Would You Rather Maintain?
25
Morpheus Says Take Pride in Your Test Automation
Code!
26
Loadable: All Screen Objects Can Tell if They’re
allLoaded()
27
Encapsulate UI Element Identification
28
Encapsulate Actions
29
Encapsulate Complex Assertions
30
Behold! Clean, Easy-to-Write UI Tests!
31
Extras
For more advanced test automation needs
Asynchronous Test Expectations
● Doable, but kinda ugly. DRY and write methods that
wait on elements once.
● https://gist.github.
com/kcharwood/0a57d7a207aba1d578da
● http://masilotti.com/xctest-helpers/
33
Code Coverage for UI Tests
34
Cucumber/Gherkin Goodness!
● Yes, really, somebody is finally doing this!
● Integrates with both KIF and XCTest
● https://github.com/Ahmed-Ali/Cucumberish
35
Conclusion
Some stuff I hope you took away from all this that will stick.
Scalable and Collaborative
● Scalable: leverages the well-worn patterns and practices
of object-oriented programming to make producing UI
tests as easy and DRY as possible.
● Collaborative: a first class citizen that lives in the
application code and conforms to the same high-quality
standards.
● Devs + Testers can make awesome apps together
37
Email - hagglundized@gmail.com
Twitter - @jhagglund
Code - https://github.com/TheMetalCode/ios-ui-automation-demo
Thank you! Any Questions?

More Related Content

More from Josiah Renaudin

Solve Everyday IT Problems with DevOps
Solve Everyday IT Problems with DevOpsSolve Everyday IT Problems with DevOps
Solve Everyday IT Problems with DevOpsJosiah Renaudin
 
End-to-End Quality Approach: 14 Levels of Testing
End-to-End Quality Approach: 14 Levels of TestingEnd-to-End Quality Approach: 14 Levels of Testing
End-to-End Quality Approach: 14 Levels of TestingJosiah Renaudin
 
Product Management: The Innovation Glue for the Lean Enterprise
Product Management: The Innovation Glue for the Lean EnterpriseProduct Management: The Innovation Glue for the Lean Enterprise
Product Management: The Innovation Glue for the Lean EnterpriseJosiah Renaudin
 
Slay the Dragons of Agile Measurement
Slay the Dragons of Agile MeasurementSlay the Dragons of Agile Measurement
Slay the Dragons of Agile MeasurementJosiah Renaudin
 
Blending Product Discovery and Product Delivery
Blending Product Discovery and Product DeliveryBlending Product Discovery and Product Delivery
Blending Product Discovery and Product DeliveryJosiah Renaudin
 
Determining Business Value in Agile Development
Determining Business Value in Agile DevelopmentDetermining Business Value in Agile Development
Determining Business Value in Agile DevelopmentJosiah Renaudin
 
Three Things You MUST Know to Transform into an Agile Enterprise
Three Things You MUST Know to Transform into an Agile EnterpriseThree Things You MUST Know to Transform into an Agile Enterprise
Three Things You MUST Know to Transform into an Agile EnterpriseJosiah Renaudin
 
Internet of Things and the Wisdom of Mobile
Internet of Things and the Wisdom of MobileInternet of Things and the Wisdom of Mobile
Internet of Things and the Wisdom of MobileJosiah Renaudin
 
How to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentHow to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentJosiah Renaudin
 
The Power of an Agile Mindset
The Power of an Agile MindsetThe Power of an Agile Mindset
The Power of an Agile MindsetJosiah Renaudin
 
DevOps and the Culture of High-Performing Software Organizations
DevOps and the Culture of High-Performing Software OrganizationsDevOps and the Culture of High-Performing Software Organizations
DevOps and the Culture of High-Performing Software OrganizationsJosiah Renaudin
 
Uncover Untold Stories in Your Data: A Deep Dive on Data Profiling
Uncover Untold Stories in Your Data: A Deep Dive on Data ProfilingUncover Untold Stories in Your Data: A Deep Dive on Data Profiling
Uncover Untold Stories in Your Data: A Deep Dive on Data ProfilingJosiah Renaudin
 
Build a Quality Engineering and Automation Framework
Build a Quality Engineering and Automation FrameworkBuild a Quality Engineering and Automation Framework
Build a Quality Engineering and Automation FrameworkJosiah Renaudin
 
Don’t Be Another Statistic! Develop a Long-Term Test Automation Strategy
Don’t Be Another Statistic! Develop a Long-Term Test Automation StrategyDon’t Be Another Statistic! Develop a Long-Term Test Automation Strategy
Don’t Be Another Statistic! Develop a Long-Term Test Automation StrategyJosiah Renaudin
 
Testing Lessons from the Land of Make Believe
Testing Lessons from the Land of Make BelieveTesting Lessons from the Land of Make Believe
Testing Lessons from the Land of Make BelieveJosiah Renaudin
 
Finding Success with Test Process Improvement
Finding Success with Test Process ImprovementFinding Success with Test Process Improvement
Finding Success with Test Process ImprovementJosiah Renaudin
 
Git and GitHub for Testers
Git and GitHub for TestersGit and GitHub for Testers
Git and GitHub for TestersJosiah Renaudin
 
Stay Ahead of the Mobile and Web Testing Maturity Curve
Stay Ahead of the Mobile and Web Testing Maturity CurveStay Ahead of the Mobile and Web Testing Maturity Curve
Stay Ahead of the Mobile and Web Testing Maturity CurveJosiah Renaudin
 
The Selenium Grid: Run Multiple Automated Tests in Parallel
The Selenium Grid: Run Multiple Automated Tests in ParallelThe Selenium Grid: Run Multiple Automated Tests in Parallel
The Selenium Grid: Run Multiple Automated Tests in ParallelJosiah Renaudin
 
Testing at Startup Companies: What, When, Where, and How
Testing at Startup Companies: What, When, Where, and HowTesting at Startup Companies: What, When, Where, and How
Testing at Startup Companies: What, When, Where, and HowJosiah Renaudin
 

More from Josiah Renaudin (20)

Solve Everyday IT Problems with DevOps
Solve Everyday IT Problems with DevOpsSolve Everyday IT Problems with DevOps
Solve Everyday IT Problems with DevOps
 
End-to-End Quality Approach: 14 Levels of Testing
End-to-End Quality Approach: 14 Levels of TestingEnd-to-End Quality Approach: 14 Levels of Testing
End-to-End Quality Approach: 14 Levels of Testing
 
Product Management: The Innovation Glue for the Lean Enterprise
Product Management: The Innovation Glue for the Lean EnterpriseProduct Management: The Innovation Glue for the Lean Enterprise
Product Management: The Innovation Glue for the Lean Enterprise
 
Slay the Dragons of Agile Measurement
Slay the Dragons of Agile MeasurementSlay the Dragons of Agile Measurement
Slay the Dragons of Agile Measurement
 
Blending Product Discovery and Product Delivery
Blending Product Discovery and Product DeliveryBlending Product Discovery and Product Delivery
Blending Product Discovery and Product Delivery
 
Determining Business Value in Agile Development
Determining Business Value in Agile DevelopmentDetermining Business Value in Agile Development
Determining Business Value in Agile Development
 
Three Things You MUST Know to Transform into an Agile Enterprise
Three Things You MUST Know to Transform into an Agile EnterpriseThree Things You MUST Know to Transform into an Agile Enterprise
Three Things You MUST Know to Transform into an Agile Enterprise
 
Internet of Things and the Wisdom of Mobile
Internet of Things and the Wisdom of MobileInternet of Things and the Wisdom of Mobile
Internet of Things and the Wisdom of Mobile
 
How to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentHow to Do Kick-Ass Software Development
How to Do Kick-Ass Software Development
 
The Power of an Agile Mindset
The Power of an Agile MindsetThe Power of an Agile Mindset
The Power of an Agile Mindset
 
DevOps and the Culture of High-Performing Software Organizations
DevOps and the Culture of High-Performing Software OrganizationsDevOps and the Culture of High-Performing Software Organizations
DevOps and the Culture of High-Performing Software Organizations
 
Uncover Untold Stories in Your Data: A Deep Dive on Data Profiling
Uncover Untold Stories in Your Data: A Deep Dive on Data ProfilingUncover Untold Stories in Your Data: A Deep Dive on Data Profiling
Uncover Untold Stories in Your Data: A Deep Dive on Data Profiling
 
Build a Quality Engineering and Automation Framework
Build a Quality Engineering and Automation FrameworkBuild a Quality Engineering and Automation Framework
Build a Quality Engineering and Automation Framework
 
Don’t Be Another Statistic! Develop a Long-Term Test Automation Strategy
Don’t Be Another Statistic! Develop a Long-Term Test Automation StrategyDon’t Be Another Statistic! Develop a Long-Term Test Automation Strategy
Don’t Be Another Statistic! Develop a Long-Term Test Automation Strategy
 
Testing Lessons from the Land of Make Believe
Testing Lessons from the Land of Make BelieveTesting Lessons from the Land of Make Believe
Testing Lessons from the Land of Make Believe
 
Finding Success with Test Process Improvement
Finding Success with Test Process ImprovementFinding Success with Test Process Improvement
Finding Success with Test Process Improvement
 
Git and GitHub for Testers
Git and GitHub for TestersGit and GitHub for Testers
Git and GitHub for Testers
 
Stay Ahead of the Mobile and Web Testing Maturity Curve
Stay Ahead of the Mobile and Web Testing Maturity CurveStay Ahead of the Mobile and Web Testing Maturity Curve
Stay Ahead of the Mobile and Web Testing Maturity Curve
 
The Selenium Grid: Run Multiple Automated Tests in Parallel
The Selenium Grid: Run Multiple Automated Tests in ParallelThe Selenium Grid: Run Multiple Automated Tests in Parallel
The Selenium Grid: Run Multiple Automated Tests in Parallel
 
Testing at Startup Companies: What, When, Where, and How
Testing at Startup Companies: What, When, Where, and HowTesting at Startup Companies: What, When, Where, and How
Testing at Startup Companies: What, When, Where, and How
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%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 Stilfonteinmasabamasaba
 
%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 tembisamasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
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...Jittipong Loespradit
 
%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 tembisamasabamasaba
 
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...Shane Coughlan
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+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
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%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
 
%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 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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...
 
%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
 
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...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+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...
 

Scalable and Collaborative iOS UI Test Automation in Swift

  • 1. Scalable and Collaborative UI Test Automation in Swift Jason Hagglund Staff Software Eng - Test, The Climate Corporation https://github.com/TheMetalCode Twitter - @jhagglund Where are we going? ● Why bother with UI test automation? ● XCTest API and UI Elements ● Identifying UI Elements (Storyboard and Programmatically) ● Stop Relying on the Recorder and Automate Predictively ● Write Better UI Automation Code with Screen Objects ● Extras ● Questions 2
  • 2. Why bother with UI test automation? Because this talk would be really lame if UI tests weren’t important or useful. It’s All About the Pyramid 4 http://martinfowler.com/bliki/TestPyramid.html
  • 3. Why UI Test Automation Efforts Sometimes Fail if effortToMaintain > valueAdded { notWorthIt(); } 5 The iOS UI and the XCTest API Looking at the structure of what we’re testing and the code that gives us the access to the UI.
  • 4. Our Toolbox for iOS UI Automation ● XCode 7+ ● XCTest (supports UI testing as of XCode 7, iOS 9+) ● Swift 7 ● On the web: http://masilotti.com/xctest- documentation/index.html ● Build it locally: https://github. com/joemasilotti/XCTest-Documentation Regarding XCTest Documentation... 8
  • 5. What is XCTest? 9 A build target that targets your application’s build target. Say that 10x fast. Your XCTest Bread and Butter ● XCUIApplication ○ This class models the application itself and has two functions: launch and terminate. ● XCUIElement ○ This class models a UI element contained within the application. ● XCUIElementQuery ○ This class models a search for an element. 10
  • 6. UI Test Recorder: An Exploration Tool 11 Identify UI Elements from the Storyboard The least painful way to uniquely tag our UI elements for automation purposes
  • 7. 13 Identity Inspector and Accessibility Are Your Friends Accessibility Identifier > Accessibility Label 14 ● Lest we forget: the primary purpose of Accessibility- enabled elements is to allow your app to be used in accessibility mode on the device. ● Accessibility Labels are what the end user would actually see/hear in order to interact with your app. ● Accessibility Identifiers don’t leave a mark.
  • 8. Accessibility Identifier > Accessibility Label Identify UI Elements Programmatically Our first encounter with the power of Swift Protocols
  • 9. About Those Pesky Dynamically Generated Elements... ● Protocol (similar to an Interface in Java): a collection of properties, methods, etc., that encapsulate common behavior that you want otherwise unrelated classes to share. ● UIKit elements conform to the UIAccessibilityIdentification protocol, which has exactly one contract requirement: accessibilityIdentifier. 17 Let’s ID Some Table Cells Programmatically 18
  • 10. Stop Recording and Write Predictive UI Tests The recorder is an exploration tool, not a testing tool. A Revelation from Morpheus 20
  • 11. No Really, It’s This Easy (In Many Cases) var someButton = app.buttons[“accessibilityIdentifier”] “app” = instance of XCUIApplication “buttons” = just one of many XCUIElementTypeQueryProvider methods (hey look, another Protocol!) “accessibilityIdentifier” = the accessibility identifier you have configured for that element 21 Why This Matters ● Kill more bugs faster! (enables TDD-like practices) ● Plus, just looks cleaner. Remember that ugly recorder-generated code earlier? 22
  • 12. Write Better UI Automation with Screen Objects Your tests are software. Code like it. Which Would You Rather Maintain? 24
  • 13. Which Would You Rather Maintain? 25 Morpheus Says Take Pride in Your Test Automation Code! 26
  • 14. Loadable: All Screen Objects Can Tell if They’re allLoaded() 27 Encapsulate UI Element Identification 28
  • 16. Behold! Clean, Easy-to-Write UI Tests! 31 Extras For more advanced test automation needs
  • 17. Asynchronous Test Expectations ● Doable, but kinda ugly. DRY and write methods that wait on elements once. ● https://gist.github. com/kcharwood/0a57d7a207aba1d578da ● http://masilotti.com/xctest-helpers/ 33 Code Coverage for UI Tests 34
  • 18. Cucumber/Gherkin Goodness! ● Yes, really, somebody is finally doing this! ● Integrates with both KIF and XCTest ● https://github.com/Ahmed-Ali/Cucumberish 35 Conclusion Some stuff I hope you took away from all this that will stick.
  • 19. Scalable and Collaborative ● Scalable: leverages the well-worn patterns and practices of object-oriented programming to make producing UI tests as easy and DRY as possible. ● Collaborative: a first class citizen that lives in the application code and conforms to the same high-quality standards. ● Devs + Testers can make awesome apps together 37 Email - hagglundized@gmail.com Twitter - @jhagglund Code - https://github.com/TheMetalCode/ios-ui-automation-demo Thank you! Any Questions?