SlideShare a Scribd company logo
iOS X-Code UI Testing
Jianbin LIN
2
X-Code UI Testing
• Supported natively by each version of X-Code
• Faster than any 3rd party framework
3
Architecture
4
Architecture Level: Acceptance test
5
Acceptance Test
• Arrange: fulfill the preconditions & inputs
• Act: execute some task
• Assert: Verify some question
6
Acceptance Test Example
func testLoggedUserCanDeactivateUserPreferenceAndPerformanceIsActivated() {
// Arrange
var home = Tester(testCase: self).logInWithValidCredentials()
// Act
let tasks = CookiesManagementTasks(testCase: self)
home = tasks.deactivateUserPreferenceAndPerformanceOnCookiesSettings(home:
home).backToHome()
// Assert
let cookiesManagementQuestions = CookiesManagementQuestions(testCase: self)
XCTAssert(!cookiesManagementQuestions.userPreferenceAndPerformanceIsActivated(curre
ntPage: home))
}
7
Architecture Level: Business Logics
8
Tasks: the business tasks to be tested
- Login
- Register
- Read an article
- Post a comment
- Take a quiz
- ……
9
Tasks Example
class CookiesManagementTasks {
func deactivateInterestBasedAdvertisingOnCookiesSettings(home: HomePage) ->
ManageYourCookiesPage {
gdprStubService.mockSummitConsent(succeeded: true)
return home.openProfile()
.openSettingsPage()
.openManageMyPreference()
.openManageYourCookies()
.setInterestBasedAdvertising(agree: false)
}
}
10
Questions: the post conditions to be verified
- Whether use has actually logged-in ?
- Whether user has registerred correctly ?
- Whether an article is read ?
- Whether a comment is posted correctly ?
- Quiz is actually took ?
- ……
11
Questions Example
class CookiesManagementQuestions {
func ananymousTrackingIsActivated(currentPage: BasePage) -> Bool {
let page = currentPage.backToHome()
.openProfile()
.openSettingsPage()
.openManageMyPreference()
.openManageYourCookies()
return page.anonymousTrackingIsActivated()
}
…
}
12
Architecture Level: Page Objects
13
Page object pattern
- A famous pattern used for web automated testing
- Synthesize all the actions/conditions to be taken on one screen/page into a Page Object
14
Page object example
class CookieWallPage {
func tapOnConfirmButton() {
…
}
func acceptAllOnCookieWall() -> HomePage {
…
}
}
15
BasePage protocol: back to home page
protocol BasePage {
…
func backToHome() -> HomePage
}
16
How to reference UI element on page
- Find by accessibility Id (need to set accessibility id for the element for which to be
searched)
- Find by element type(cell, button, etc)
- Find by text (need to be localized)
17
Find element by localized text
func personalisedAdvertisingOutsiteUnivadisWebstiesAndServicesSettingExists() -> Bool {
let tablesQuery = app.tables
let cell = tablesQuery.cells.containing(.staticText, identifier:
testCase.localized("Consult.Settings.PrivacyPreferences.AdvertisingOutsideOfUnivadis.Title")).cont
aining(.switch, identifier: nil)
return app.scrollToElement(element: cell.element, maxScroll: 3)
}
18
Mock API calls with SBTUITestTunnel
class LogInStubService {
func validLoginUserResponse() -> [String: Any] {
switch environment.selectedCountry {
case .uk:
return ["data": ["errorCode": 0, "msg": "User is validated", "login": true,
"validationStatus": "VP", "autoLogin": false, "userId": "axxxx-xxxx-4c91-b2b1-
xx12e5ddd6b8", "profile": ["firstName": "Auxxx", "lastName": "Dutxxxx"]]]
}
…
}
func mockLoginResponseWithValidUser() {
app.stubRequests(matching: SBTRequestMatch(url: "profile/login"),
response: SBTStubResponse(response: validLoginUserResponse()))
}
Questions ?

More Related Content

PDF
Introduction to Protractor
PDF
Velocity EU 2014 — Offline-first web apps
PDF
How to write easy-to-test JavaScript
PDF
Introduction to Django
KEY
Taking a Test Drive
KEY
Making Django and NoSQL Play Nice
PDF
Web ui testing
PDF
Better Testing With PHP Unit
Introduction to Protractor
Velocity EU 2014 — Offline-first web apps
How to write easy-to-test JavaScript
Introduction to Django
Taking a Test Drive
Making Django and NoSQL Play Nice
Web ui testing
Better Testing With PHP Unit

What's hot (20)

PPTX
Setting up Page Object Model in Automation Framework
PDF
Introducing jQuery
KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
PDF
Excellent
PDF
Web ui tests examples with selenide, nselene, selene & capybara
PDF
Kiss PageObjects [01-2017]
PPTX
PDF
The Django Book - Chapter 5: Models
PDF
Rails is not just Ruby
PPTX
Tango with django
PDF
Service Workers
PPTX
Introduction to jQuery - The basics
KEY
New Design of OneRing
PPTX
Factory girl
PDF
PageObject
PPTX
Nodejs do teste de unidade ao de integração
PPTX
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
PDF
Testing for Pragmatic People
PDF
ReactJS
Setting up Page Object Model in Automation Framework
Introducing jQuery
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Excellent
Web ui tests examples with selenide, nselene, selene & capybara
Kiss PageObjects [01-2017]
The Django Book - Chapter 5: Models
Rails is not just Ruby
Tango with django
Service Workers
Introduction to jQuery - The basics
New Design of OneRing
Factory girl
PageObject
Nodejs do teste de unidade ao de integração
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
Testing for Pragmatic People
ReactJS
Ad

Similar to X-Code UI testing architecture and tools (20)

PDF
BDD, ATDD, Page Objects: The Road to Sustainable Web Testing
PDF
Easy tests with Selenide and Easyb
PDF
Automation Abstraction Layers: Page Objects and Beyond
PDF
Web UI test automation instruments
PPTX
Android Unit Test
PDF
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
PPTX
Advanced SharePoint Web Part Development
PPTX
WuKong - Framework for Integrated Test
PDF
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
PPTX
Automation - web testing with selenium
PPTX
A test framework out of the box - Geb for Web and mobile
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
PPTX
iOS and Android apps automation
PDF
jQuery in the [Aol.] Enterprise
PDF
Top100summit 谷歌-scott-improve your automated web application testing
PPTX
Testing ASP.NET - Progressive.NET
PDF
UPC Testing talk 2
PDF
Automating Django Functional Tests Using Selenium on Cloud
ZIP
Javascript Everywhere
PPTX
Writing automation tests with python selenium behave pageobjects
BDD, ATDD, Page Objects: The Road to Sustainable Web Testing
Easy tests with Selenide and Easyb
Automation Abstraction Layers: Page Objects and Beyond
Web UI test automation instruments
Android Unit Test
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
Advanced SharePoint Web Part Development
WuKong - Framework for Integrated Test
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Automation - web testing with selenium
A test framework out of the box - Geb for Web and mobile
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
iOS and Android apps automation
jQuery in the [Aol.] Enterprise
Top100summit 谷歌-scott-improve your automated web application testing
Testing ASP.NET - Progressive.NET
UPC Testing talk 2
Automating Django Functional Tests Using Selenium on Cloud
Javascript Everywhere
Writing automation tests with python selenium behave pageobjects
Ad

Recently uploaded (20)

PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Artificial Intelligence
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
composite construction of structures.pdf
PPTX
Construction Project Organization Group 2.pptx
PPT
Project quality management in manufacturing
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Geodesy 1.pptx...............................................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Artificial Intelligence
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
composite construction of structures.pdf
Construction Project Organization Group 2.pptx
Project quality management in manufacturing
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Internet of Things (IOT) - A guide to understanding
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Model Code of Practice - Construction Work - 21102022 .pdf

X-Code UI testing architecture and tools

  • 1. iOS X-Code UI Testing Jianbin LIN
  • 2. 2 X-Code UI Testing • Supported natively by each version of X-Code • Faster than any 3rd party framework
  • 5. 5 Acceptance Test • Arrange: fulfill the preconditions & inputs • Act: execute some task • Assert: Verify some question
  • 6. 6 Acceptance Test Example func testLoggedUserCanDeactivateUserPreferenceAndPerformanceIsActivated() { // Arrange var home = Tester(testCase: self).logInWithValidCredentials() // Act let tasks = CookiesManagementTasks(testCase: self) home = tasks.deactivateUserPreferenceAndPerformanceOnCookiesSettings(home: home).backToHome() // Assert let cookiesManagementQuestions = CookiesManagementQuestions(testCase: self) XCTAssert(!cookiesManagementQuestions.userPreferenceAndPerformanceIsActivated(curre ntPage: home)) }
  • 8. 8 Tasks: the business tasks to be tested - Login - Register - Read an article - Post a comment - Take a quiz - ……
  • 9. 9 Tasks Example class CookiesManagementTasks { func deactivateInterestBasedAdvertisingOnCookiesSettings(home: HomePage) -> ManageYourCookiesPage { gdprStubService.mockSummitConsent(succeeded: true) return home.openProfile() .openSettingsPage() .openManageMyPreference() .openManageYourCookies() .setInterestBasedAdvertising(agree: false) } }
  • 10. 10 Questions: the post conditions to be verified - Whether use has actually logged-in ? - Whether user has registerred correctly ? - Whether an article is read ? - Whether a comment is posted correctly ? - Quiz is actually took ? - ……
  • 11. 11 Questions Example class CookiesManagementQuestions { func ananymousTrackingIsActivated(currentPage: BasePage) -> Bool { let page = currentPage.backToHome() .openProfile() .openSettingsPage() .openManageMyPreference() .openManageYourCookies() return page.anonymousTrackingIsActivated() } … }
  • 13. 13 Page object pattern - A famous pattern used for web automated testing - Synthesize all the actions/conditions to be taken on one screen/page into a Page Object
  • 14. 14 Page object example class CookieWallPage { func tapOnConfirmButton() { … } func acceptAllOnCookieWall() -> HomePage { … } }
  • 15. 15 BasePage protocol: back to home page protocol BasePage { … func backToHome() -> HomePage }
  • 16. 16 How to reference UI element on page - Find by accessibility Id (need to set accessibility id for the element for which to be searched) - Find by element type(cell, button, etc) - Find by text (need to be localized)
  • 17. 17 Find element by localized text func personalisedAdvertisingOutsiteUnivadisWebstiesAndServicesSettingExists() -> Bool { let tablesQuery = app.tables let cell = tablesQuery.cells.containing(.staticText, identifier: testCase.localized("Consult.Settings.PrivacyPreferences.AdvertisingOutsideOfUnivadis.Title")).cont aining(.switch, identifier: nil) return app.scrollToElement(element: cell.element, maxScroll: 3) }
  • 18. 18 Mock API calls with SBTUITestTunnel class LogInStubService { func validLoginUserResponse() -> [String: Any] { switch environment.selectedCountry { case .uk: return ["data": ["errorCode": 0, "msg": "User is validated", "login": true, "validationStatus": "VP", "autoLogin": false, "userId": "axxxx-xxxx-4c91-b2b1- xx12e5ddd6b8", "profile": ["firstName": "Auxxx", "lastName": "Dutxxxx"]]] } … } func mockLoginResponseWithValidUser() { app.stubRequests(matching: SBTRequestMatch(url: "profile/login"), response: SBTStubResponse(response: validLoginUserResponse())) }