SlideShare a Scribd company logo
1 of 19
Download to read offline
USER INTERFACE
TESTING
WITH KIF & SWIFT
CASE FOR UI TESTING
INTEGRATION

NAVIGATION FLOW

DATA FLOW

USER EXPERIENCE

ACCESSIBILITY

REFACTORINGS / REGRESSIONS
UI TESTING IS HARD 

AND TIME CONSUMING
UNLESS

AUTOMATED 

EASYTO MAINTAIN

FAST
NATIVE SUPPORT 

FOR UI TESTING
UI AUTOMATION (JavaScript)

XCUI (Swift/Objective C)

BASED ON UIAcessibility PROTOCOL
KIF

Keep It Functional - An iOS Functional
Testing Framework
https://github.com/kif-framework/KIF

UICONF 2016 TALK BY ELLEN SHAPIRO

https://youtu.be/hYCUy-9yq_M
OBJECTIVE C - KIFTestCase
RUNS IN APP TARGET

beforeAll, beforeEach, afterAll, afterEach

KIFUITestActor - USER ACTIONS

KIFSystemTestActor - SYSTEM/DEVICE ACTIONS
SWIFT - XCTestCase
ADD SIMPLE EXTENSION TO ACCESS
KIFUITestActor AND KIFSystemTestActor
OBJECTIVE C
[tester tapViewWithAccessibilityLabel:@"Login"];


SWIFT
tester().tapView(withAccessibilityLabel : "Login")
EXTENSIONS FOR READIBILITY
extension KIFUITestActor {
@discardableResult func waitForButton(_ label: String) -> UIView! {
let button = self.waitForTappableView(withAccessibilityLabel: label, traits:
UIAccessibilityTraitButton)
return button
}
func tapButton(_ accessibilityLabel: String, value: String) {
let button = waitForButton(accessibilityLabel, value: value)
button?.tap()
}
}
RESULT
tester().tapButton(“Login”) // or even better – tester().tapLoginButton()
PROTOCOLTO ACCESS APP DATA
public protocol UsesCoreDataDatabase {
func dbContext() -> NSManagedObjectContext
func isDbEmpty(_ context: NSManagedObjectContext) -> Bool
func deleteDbData(_ context: NSManagedObjectContext)
}
public extension UsesCoreDataDatabase {
func dbContext() -> NSManagedObjectContext {
let appDelegate: YourAppDelegate = UIApplication.shared.delegate as! YourAppDelegate
let context = appDelegate.value(forKey: "context") as! NSManagedObjectContext
XCTAssertNotNil(context)
return context!
}
func isDbEmpty(_ context: NSManagedObjectContext) -> Bool {
// access model objects from context
let count = ….
return (count == 0)
}
func deleteDbData(_ context: NSManagedObjectContext) {
// Delete data
}
CUSTOM TEST CASES
class MyTestCaseWithEmptyDatabase: KIFTestCase, UsesCoreDataDatabase {
override func beforeEach() {
let context = dbContext()
if ! sDbEmpty(context) {
let name = MyAppServices.deviceModel()
if name == "iPhone Simulator" { deleteDbData(context) } else { } // Are you sure want to delete data from device?
}
}
}
class MyTestCaseWithWizardFilled: MyTestCaseWithEmptyDatabase {
var rentAmount = “100”; var unitName= “M10”; var tenantName = “Anna"
override func beforeEach() {
super.beforeEach()
let context = dbContext()
MyWizardController.saveFromWizard(in: context, address: unitName, tenant: tenantName amount: rentAmount)
}
}
class MyTestCaseWithFixturesLoaded : MyTestCaseWithEmptyDatabase {
// load fixture data in database
}
DRY, READABLE TESTS
class PaymentTests: MyTestCaseWithWizardFilled {
func testAddPayment_fromUnitDashboard() {
// given - tenantName, unitName, today are defined as MyTestCaseWithWizardFilled class variables
let amount = “5.1”; let paymentAmount = “$5.10”
tester().tapPropertiesTabButton()
tester().tapUnit(unitName, tenant: tenantName)
tester().waitForTenantBalanceScreen(tenantName, currentBalance: "$0.00")
tester().waitForLastPaymentLine("No rent payments received", amount: “") // even this should be replaced by waitForNoLastPaymentLine
// when
tester().tapAddPaymentButton()
tester().enterOnKeyboard(amount)
tester().tapSaveButton()
// then
tester().waitForTenantBalanceScreen(tenantName, currentBalance: paymentAmount)
tester().waitForLastRentPaymentLine(today, amount: paymentAmount)
}
}
…
public extension KIFUITestActor {
/// Returns last payment line in rental unit dashboard
@discardableResult func waitForLastPaymentLine(_ date: String, amount: String) -> UIView! {
let view = waitForView("Last rent payment", value: "(date), (amount)”) // Accessibility label & accessibility value
return view
}
}
FAST
NOT REALLY
MAKE UI TESTS FASTER
class MyTestCaseWithEmptyDatabase: KIFTestCase, UsesCoreDataDatabase {
override func beforeAll() {
UIApplication.shared.keyWindow!.layer.speed = 100; // faster animations
}
}
GOTCHAS & HINTS
OCCASIONALLY CAN FAIL WITHOUT A GOOD REASON

¯_( )_/¯

BEWARE OF UITableViewCells

ADD EVERYTHING AS SUBVIEWTO .contentView

SAVE SCREENSHOTS ON TEST FAILURE

SET ENVVARIABLE WITH FOLDER LOCATION- KIF_SCREENSHOTS= …



AFTER FAILING TEST IN MODAL VIEW ALL OTHER TEST RESULTS = USELESS

do { try tester().trySomething(); // then test } catch {}
ACCESSIBILITY
https://youtu.be/no12EfZUSQo
“You have no clue about your app
accessibility until you write app UI tests
that rely on accessibility”
/ me to myself /
UIAccessibility PROTOCOL
UIAccessibilityElement CLASS
UIAccessibilityContainer PROTOCOL
UIAccessibilityTraits



BUNDLED FREE WHEN USING UIKit,JUST SET 

accessibilityLabel, accessibilityValue, accessibilityHint 

IN IB AND/OR CODE
QUESTIONS?
Jurģis Ķiršakmens
jki@jki.lv
@jki / @xjki

More Related Content

What's hot

Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Natasha Murashev
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftAaron Douglas
 
Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.CocoaHeads France
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUIkiahiska
 
Reactive Programming with RxSwift
Reactive Programming with RxSwiftReactive Programming with RxSwift
Reactive Programming with RxSwiftScott Gardner
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 

What's hot (9)

Hello watchOS2
Hello watchOS2 Hello watchOS2
Hello watchOS2
 
Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)
 
Présentation de HomeKit
Présentation de HomeKitPrésentation de HomeKit
Présentation de HomeKit
 
NodeJs
NodeJsNodeJs
NodeJs
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
 
Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.Découvrir dtrace en ligne de commande.
Découvrir dtrace en ligne de commande.
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUI
 
Reactive Programming with RxSwift
Reactive Programming with RxSwiftReactive Programming with RxSwift
Reactive Programming with RxSwift
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 

Similar to Automated UI testing for iOS apps using KIF framework and Swift

Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09Daniel Bryant
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Paco de la Cruz
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeMacoscope
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architectureVitali Pekelis
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedToru Wonyoung Choi
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's NewTed Pennings
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisationgoldoraf
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfKAI CHU CHUNG
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4Naga Muruga
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemAndres Almiray
 
JEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon EuropeJEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon EuropeQAware GmbH
 

Similar to Automated UI testing for iOS apps using KIF framework and Swift (20)

Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisation
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
JEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon EuropeJEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon Europe
 
JEE on DC/OS
JEE on DC/OSJEE on DC/OS
JEE on DC/OS
 

More from Jurgis Kirsakmens

Using analytics in iOS apps - #uikonf2016 #unconference
Using analytics in iOS apps - #uikonf2016 #unconferenceUsing analytics in iOS apps - #uikonf2016 #unconference
Using analytics in iOS apps - #uikonf2016 #unconferenceJurgis Kirsakmens
 
Analytics for iOS apps (crash/diagnostic/usage/sales)
Analytics for iOS apps (crash/diagnostic/usage/sales) Analytics for iOS apps (crash/diagnostic/usage/sales)
Analytics for iOS apps (crash/diagnostic/usage/sales) Jurgis Kirsakmens
 
How much does it cost to build a mobile app?
How much does it cost to build a mobile app?How much does it cost to build a mobile app?
How much does it cost to build a mobile app?Jurgis Kirsakmens
 
Mobilās aplikācijas un uzņēmumu komunikācija
Mobilās aplikācijas un uzņēmumu komunikācijaMobilās aplikācijas un uzņēmumu komunikācija
Mobilās aplikācijas un uzņēmumu komunikācijaJurgis Kirsakmens
 
Future:apps&mobile - mobile landscape and development platforms
Future:apps&mobile - mobile landscape and development platformsFuture:apps&mobile - mobile landscape and development platforms
Future:apps&mobile - mobile landscape and development platformsJurgis Kirsakmens
 
Netiquette- short introduction
Netiquette- short introductionNetiquette- short introduction
Netiquette- short introductionJurgis Kirsakmens
 

More from Jurgis Kirsakmens (7)

Using analytics in iOS apps - #uikonf2016 #unconference
Using analytics in iOS apps - #uikonf2016 #unconferenceUsing analytics in iOS apps - #uikonf2016 #unconference
Using analytics in iOS apps - #uikonf2016 #unconference
 
Analytics for iOS apps (crash/diagnostic/usage/sales)
Analytics for iOS apps (crash/diagnostic/usage/sales) Analytics for iOS apps (crash/diagnostic/usage/sales)
Analytics for iOS apps (crash/diagnostic/usage/sales)
 
Take a Break
Take a BreakTake a Break
Take a Break
 
How much does it cost to build a mobile app?
How much does it cost to build a mobile app?How much does it cost to build a mobile app?
How much does it cost to build a mobile app?
 
Mobilās aplikācijas un uzņēmumu komunikācija
Mobilās aplikācijas un uzņēmumu komunikācijaMobilās aplikācijas un uzņēmumu komunikācija
Mobilās aplikācijas un uzņēmumu komunikācija
 
Future:apps&mobile - mobile landscape and development platforms
Future:apps&mobile - mobile landscape and development platformsFuture:apps&mobile - mobile landscape and development platforms
Future:apps&mobile - mobile landscape and development platforms
 
Netiquette- short introduction
Netiquette- short introductionNetiquette- short introduction
Netiquette- short introduction
 

Recently uploaded

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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
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
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
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
 
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
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
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
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Recently uploaded (20)

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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
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
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
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
 
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
 
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
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
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
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Automated UI testing for iOS apps using KIF framework and Swift

  • 2. CASE FOR UI TESTING INTEGRATION
 NAVIGATION FLOW
 DATA FLOW
 USER EXPERIENCE
 ACCESSIBILITY
 REFACTORINGS / REGRESSIONS
  • 3. UI TESTING IS HARD 
 AND TIME CONSUMING UNLESS
 AUTOMATED 
 EASYTO MAINTAIN
 FAST
  • 4.
  • 5. NATIVE SUPPORT 
 FOR UI TESTING UI AUTOMATION (JavaScript)
 XCUI (Swift/Objective C)
 BASED ON UIAcessibility PROTOCOL
  • 6. KIF
 Keep It Functional - An iOS Functional Testing Framework https://github.com/kif-framework/KIF
 UICONF 2016 TALK BY ELLEN SHAPIRO
 https://youtu.be/hYCUy-9yq_M
  • 7. OBJECTIVE C - KIFTestCase RUNS IN APP TARGET
 beforeAll, beforeEach, afterAll, afterEach
 KIFUITestActor - USER ACTIONS
 KIFSystemTestActor - SYSTEM/DEVICE ACTIONS SWIFT - XCTestCase ADD SIMPLE EXTENSION TO ACCESS KIFUITestActor AND KIFSystemTestActor
  • 9. EXTENSIONS FOR READIBILITY extension KIFUITestActor { @discardableResult func waitForButton(_ label: String) -> UIView! { let button = self.waitForTappableView(withAccessibilityLabel: label, traits: UIAccessibilityTraitButton) return button } func tapButton(_ accessibilityLabel: String, value: String) { let button = waitForButton(accessibilityLabel, value: value) button?.tap() } } RESULT tester().tapButton(“Login”) // or even better – tester().tapLoginButton()
  • 10. PROTOCOLTO ACCESS APP DATA public protocol UsesCoreDataDatabase { func dbContext() -> NSManagedObjectContext func isDbEmpty(_ context: NSManagedObjectContext) -> Bool func deleteDbData(_ context: NSManagedObjectContext) } public extension UsesCoreDataDatabase { func dbContext() -> NSManagedObjectContext { let appDelegate: YourAppDelegate = UIApplication.shared.delegate as! YourAppDelegate let context = appDelegate.value(forKey: "context") as! NSManagedObjectContext XCTAssertNotNil(context) return context! } func isDbEmpty(_ context: NSManagedObjectContext) -> Bool { // access model objects from context let count = …. return (count == 0) } func deleteDbData(_ context: NSManagedObjectContext) { // Delete data }
  • 11. CUSTOM TEST CASES class MyTestCaseWithEmptyDatabase: KIFTestCase, UsesCoreDataDatabase { override func beforeEach() { let context = dbContext() if ! sDbEmpty(context) { let name = MyAppServices.deviceModel() if name == "iPhone Simulator" { deleteDbData(context) } else { } // Are you sure want to delete data from device? } } } class MyTestCaseWithWizardFilled: MyTestCaseWithEmptyDatabase { var rentAmount = “100”; var unitName= “M10”; var tenantName = “Anna" override func beforeEach() { super.beforeEach() let context = dbContext() MyWizardController.saveFromWizard(in: context, address: unitName, tenant: tenantName amount: rentAmount) } } class MyTestCaseWithFixturesLoaded : MyTestCaseWithEmptyDatabase { // load fixture data in database }
  • 12. DRY, READABLE TESTS class PaymentTests: MyTestCaseWithWizardFilled { func testAddPayment_fromUnitDashboard() { // given - tenantName, unitName, today are defined as MyTestCaseWithWizardFilled class variables let amount = “5.1”; let paymentAmount = “$5.10” tester().tapPropertiesTabButton() tester().tapUnit(unitName, tenant: tenantName) tester().waitForTenantBalanceScreen(tenantName, currentBalance: "$0.00") tester().waitForLastPaymentLine("No rent payments received", amount: “") // even this should be replaced by waitForNoLastPaymentLine // when tester().tapAddPaymentButton() tester().enterOnKeyboard(amount) tester().tapSaveButton() // then tester().waitForTenantBalanceScreen(tenantName, currentBalance: paymentAmount) tester().waitForLastRentPaymentLine(today, amount: paymentAmount) } } … public extension KIFUITestActor { /// Returns last payment line in rental unit dashboard @discardableResult func waitForLastPaymentLine(_ date: String, amount: String) -> UIView! { let view = waitForView("Last rent payment", value: "(date), (amount)”) // Accessibility label & accessibility value return view } }
  • 14. MAKE UI TESTS FASTER class MyTestCaseWithEmptyDatabase: KIFTestCase, UsesCoreDataDatabase { override func beforeAll() { UIApplication.shared.keyWindow!.layer.speed = 100; // faster animations } }
  • 15. GOTCHAS & HINTS OCCASIONALLY CAN FAIL WITHOUT A GOOD REASON
 ¯_( )_/¯
 BEWARE OF UITableViewCells
 ADD EVERYTHING AS SUBVIEWTO .contentView
 SAVE SCREENSHOTS ON TEST FAILURE
 SET ENVVARIABLE WITH FOLDER LOCATION- KIF_SCREENSHOTS= …
 
 AFTER FAILING TEST IN MODAL VIEW ALL OTHER TEST RESULTS = USELESS
 do { try tester().trySomething(); // then test } catch {}
  • 16. ACCESSIBILITY https://youtu.be/no12EfZUSQo “You have no clue about your app accessibility until you write app UI tests that rely on accessibility” / me to myself /
  • 17.
  • 18. UIAccessibility PROTOCOL UIAccessibilityElement CLASS UIAccessibilityContainer PROTOCOL UIAccessibilityTraits
 
 BUNDLED FREE WHEN USING UIKit,JUST SET 
 accessibilityLabel, accessibilityValue, accessibilityHint 
 IN IB AND/OR CODE