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] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
[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
 
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] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] 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] Functions 2.0: 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
JEE on DC/OSJEE on DC/OS
JEE on DC/OS
 
JEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon EuropeJEE on DC/OS - MesosCon Europe
JEE on DC/OS - MesosCon Europe
 

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

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 2024VictoriaMetrics
 
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 SoftwareJim McKeeth
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%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
 
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 SituationJuha-Pekka Tolvanen
 
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...Bert Jan Schrijver
 
%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
 
%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
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%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 Hazyviewmasabamasaba
 
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
 
%+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
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
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.pptxAnnaArtyushina1
 

Recently uploaded (20)

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
 
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
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
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...
 
%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
 
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...
 
%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
 
%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
 
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...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
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...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%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
 
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...
 
%+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 Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
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
 

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