SlideShare a Scribd company logo
iOS Automation
XCUITest + Gherkin
โ€ข Technical Lead iOS Engineer @ PropertyGuru
โ€ข Agile, Xtreme Programming
โ€ข Tests
โ€ข Calabash-iOS ----> XCUITest
โ€ข Demo [https://github.com/depoon/WeatherAppDemo]
Agenda
1. Introduction XCUITest
2. Building a simple Test Suite
3. Gherkin for XCUITest
XCUITest
โ€ข Introduced in Xcode 7 in 2015
โ€ข xUnit Test Cases (XCTestCase)
โ€ข UITest targets cant see production codes
โ€ข Builds and tests are all executed using XCode
(ObjC/Swift)
โ€ข Record functionality
1. Introduction (iOS Automation Tools, XCUITest)
XCUITest - Recording
1. Introduction (iOS Automation Tools, XCUITest)
[Source] http://blog.xebia.com/automated-ui-testing-with-react-native-on-ios/
XCUITest - XCUIElement
1. Introduction (iOS Automation Tools, XCUITest)
XCUIElement
//Elements are objects encapsulating the information needed to dynamically locate a user interface.element in an
application. Elements are described in terms of queries [Apple Documentation - XCTest]
let app = XCUIApplication() //Object that queries views on the app
app.staticTexts //returns XCUIElementQuery โ€œcollectionโ€ representing โ€œUILabelsโ€
app.buttons //returns XCUIElementQuery โ€œcollectionโ€ of representing โ€œUIButtonsโ€
app.tables //returns XCUIElementQuery โ€œcollectionโ€ of representing โ€œUITablesโ€
app.tables.staticTexts
//returns XCUIElementQuery โ€œcollectionโ€ representing โ€œUILabelsโ€ which has superviews of type โ€œUITableโ€
app.staticTexts[โ€œHello Worldโ€]
//returns a label element with accessibilityIdentifier or text value โ€œHello Worldโ€
app.tables[โ€œmyTableโ€]
//returns a table element with accessibilityIdentifier โ€œmyTableโ€
1. Introduction (iOS Automation Tools, XCUITest)
groups
disclosureTrian
gles
tabGroups sliders images menus
windows popUpButtons toolbars pageIndicators icons menuItems
sheets comboBoxes statusBars
progressIndicat
ors
searchFields menuBars
drawers menuButtons tables
activityIndicator
s
scrollViews menuBarItems
alerts toolbarButtons tableRows
segmentedCon
trols
scrollBars maps
dialogs popovers tableColumns pickers staticTexts webViews
buttons keyboards outlines pickerWheels textFields steppers
radioButtons keys outlineRows switches
secureTextFiel
ds
cells
radioGroups navigationBars browsers toggles datePickers layoutAreas
checkBoxes tabBars collectionViews links textViews otherElements
app.otherElements //returns [ elements ] of UIView
XCUITest - XCUIElement
XCUITest - Interactions
1. Introduction (iOS Automation Tools, XCUITest)
let app = XCUIApplication() //Object that queries views on the app
app.staticTexts[โ€œHello Worldโ€].exists //returns true if element exists
app.buttons[โ€œSaveโ€].tap() //taps the โ€œSaveโ€ button
app.tables[โ€œmyTableโ€].swipeUp() //swipes up the table
app.textFields[โ€œmyFieldโ€].typeText(โ€œJohn Doeโ€) //types value in textField
Other interactions: pinchWithScale, pressForDuration, doubleTap()
XCTAssertTrue(app.staticTexts[โ€œHello Worldโ€].exists) //Throws exception if label does not exists
Requirements
2. Building a simple test suite
Create a Weather App
1. Given I am at the City Search Screen
When I search for a valid city (eg โ€œLondonโ€)
Then I should see a weather details page of that city
2. Given I am at the City Search Screen
When I search for an invalid city (eg โ€œNotACityโ€)
Then I should see an error message
Hereโ€™s what we built
2. Building a simple test suite
Creating a UITest Target
2. Building a simple test suite
Recording - Valid City
2. Building a simple test suite
Recording - Invalid City
2. Building a simple test suite
Generated Code - Valid City
2. Building a simple test suite
func testUserAbleToSearchForValidCity() {
let app = app2
app.searchFields["Search a city"].tap()
app.searchFields["Search a city"]
let app2 = app
app2.buttons["Search"].tap()
app.searchFields["Search a city"]
let tablesQuery = app2.tables
tablesQuery.staticTexts["London"].tap()
tablesQuery.staticTexts["53"].tap()
tablesQuery.staticTexts["Partly Cloudy"].tap()
}
Generated Code - Invalid City
2. Building a simple test suite
func testUserSeesErrorMessageForInvalidCity() {
let app = XCUIApplciation()
app.searchFields["Search a city"].tap()
app.searchFields["Search a city"]
app.buttons["Search"].tap()
app.searchFields["Search a city"]
let errorAlert = app.alerts["Error"]
errorAlert.staticTexts["Error"].tap()
errorAlert.staticTexts[
"Unable to find any matching weather location to the query submitted!โ€
].tap()
errorAlert.collectionViews["OK"].tap()
}
2. Building a simple test suite
func testUserAbleToSearchForValidCity() {
let app = XCUIApplication()
let searchField = app.searchFields["Search a city"]
searchField.tap()
searchField.typeText("London")
app.buttons["Search"].tap()
self.userWaitsToSeeText("London")
self.userWaitsToSeeText("53")
self.userWaitsToSeeText("Partly Cloudyโ€)
self.waitForExpectationsWithTimeout(5, handler: nil)
}
private func userWaitsToSeeText(text: String){
self.expectationForPredicate(
NSPredicate(format: "exists == 1"),
evaluatedWithObject: XCUIApplication().tables.staticTexts[text],
handler: nil
)
// XCUIApplication().tables.staticTexts[text].exists <โ€” boolean
}
Refactored Code
2. Building a simple test suite
func testUserSeesErrorMessageForInvalidCity() {
let app = XCUIApplication()
let searchField = app.searchFields["Search a cityโ€]
searchField.tap()
searchField.typeText("NotACity")
app.buttons["Search"].tap()
self.userWaitsToSeeText("Error")
self.userWaitsToSeeText(
"Unable to find any matching weather location to the query submitted!"
)
self.waitForExpectationsWithTimeout(5, handler: nil)
self.userTapsOnAlertButton("OK")
}
private func userTapsOnAlertButton(buttonTitle: String){
XCUIApplication().buttons[buttonTitle].tap()
}
Refactored Code
2. Building a simple test suite
Scheme Management
2. Building a simple test suite
Scheme Management
Gherkin
3. Use Gherkins
(User Registration)
Given I am at the user registration page
When I enter invalid email address
And I tap โ€œRegisterโ€œ
Then I should see โ€œInvalid Email Addressโ€
Gherkin - Example 1
3. Use Gherkins
(Shopping with existing Items in shopping cart)
Given I have 1 Wallet and 1 Belt in my shopping cart
And I am at the Shopping Item Details Page for a Bag
When I select quantity as โ€œ1โ€
And I tap on โ€œAdd to Shopping Cartโ€
Then I should be at Shopping Cart Screen
And I should see โ€œ3โ€ total items in my shopping cart
Gherkin - Example 2
3. Use Gherkins
2. Building a simple test suite
Given I am at Weather Search Form Page
When I enter city search for โ€œLondonโ€
Then I should be at Weather Details Page
And I wait to see โ€œLondonโ€
And I wait to see โ€œ53โ€
Gherkin - Our Acceptance Tests
2. Building a simple test suite
Given I am at Weather Search Form Page
When I enter city search for โ€œNotACityโ€
Then I wait to see โ€œErrorโ€
And I wait to see โ€œUnable to โ€ฆโ€
And I tap on alert button โ€œOKโ€
Gherkin - Our Acceptance Tests
3. Use Gherkins
โ€ข Language used in Behavioural Driven Development (BDD) to
specify software requirements with examples
โ€ข Executable, facilitate collaboration with non developers
โ€ข Lets add Gherkin to our project in Xcode
https://github.com/net-a-porter-mobile/XCTest-Gherkin
pod 'XCTest-Gherkin'
Gherkin
3. Use Gherkins[Source] https://github.com/net-a-porter-mobile/XCTest-Gherkin
Gherkin
3. Use Gherkins
Given I am at Weather Search Form Page
When I enter city search for โ€œLondonโ€
Then I should be at Weather Details Page
And I wait to see โ€œLondonโ€
And I wait to see โ€œ53โ€
step("I (am|should be) at Weather Search Form Pageโ€) {
let weatherSearchPage = WeatherSearchPage(self.test)
}
struct WeatherSearchPage{
init(testCase: XCTestCase){
testCase.expectationForPredicate(
NSPredicate(format: โ€œexists == 1โ€),
evaluatedWithObject: XCUIApplication().otherElements[โ€œWeatherSearchPageโ€],
handler: nil
)
testCase.waitForExpectationsWithTimeout(5, handler: nil)
}
}
3. Use Gherkins
Given I am at Weather Search Form Screen
When I enter city search for โ€œLondonโ€
Then I should be at Weather Details Page
And I wait to see โ€œLondonโ€
And I wait to see โ€œ53โ€
step("I enter city search for โ€(.*?)โ€โ€) { (matches: [String]) in
let weatherSearchPage = WeatherSearchPage(testCase: self.test)
weatherSearchPage.userSearchForCity(matches.first!)
}
struct WeatherSearchPage{
func userSearchForCity(city: String){
let app = XCUIApplication()
let searchField = app.searchFields[โ€œSearch a cityโ€]
searchField.tap()
searchField.typeText(city)
app.buttons[โ€œSearchโ€].tap()
}
}
3. Use Gherkins
Given I am at Weather Search Form Page
When I enter city search for โ€œLondonโ€
Then I should be at Weather Details Page
And I wait to see โ€œLondonโ€
And I wait to see โ€œ53โ€
step("I (am|should be) at Weather Details Pageโ€) {
WeatherDetailsPage(testCase: self.test)
}
struct WeatherDetailsPage{
init(testCase: XCTestCase){
testCase.expectationForPredicate(
NSPredicate(format: โ€œexists == 1โ€),
evaluatedWithObject: XCUIApplication().otherElements[โ€œWeather Forecastโ€],
handler: nil
)
testCase.waitForExpectationsWithTimeout(5, handler: nil)
}
}
3. Use Gherkins
Given I am at Weather Search Form Page
When I enter city search for โ€œLondonโ€
Then I should be at Weather Details Page
And I wait to see โ€œLondonโ€
And I wait to see โ€œ53โ€
step("I wait to see โ€(.*?)โ€โ€) { (matches: [String]) in
self.test.expectationForPredicate(
NSPredicate(format: โ€œexists == 1โ€),
evaluatedWithObject: XCUIApplication().staticTexts[matches.first!],
handler: nil
)
self.test.waitForExpectationsWithTimeout(5, handler: nil)
}
3. Use Gherkins
Given I am at Weather Search Form Page
When I enter city search for โ€œNotACityโ€
Then I wait to see โ€œErrorโ€
Then I wait to see โ€œUnable to โ€ฆโ€
Then I tap on alert button โ€œOKโ€
step("I tap on alert button โ€(.*?)โ€โ€) {
XCUIApplication().buttons[matches.first!].tap()
}
3. Use Gherkins
Using an additional pod to simply statements -
https://github.com/joemasilotti/JAMTestHelper
Gherkin
3. Use Gherkins
Using an additional pod to simply statements -
https://github.com/joemasilotti/JAMTestHelper
Gherkin
3. Use Gherkins
Gherkin
3. Use Gherkins
Gherkin
3. Use Gherkins
Gherkin
Gherkin
3. Use Gherkins
Gherkin
3. Use Gherkins
Gherkin - Using Feature File
3. Use Gherkins
Why should I use Gherkin with
XCUITest?
3. Use Gherkins
โ€ข Acceptance Test Driven Development
โ€ข Cross platform testing is still possible without need for 3rd
party tools
โ€ข Objective C + Swift
Questions?
kenneth@propertyguru.com.sg
de_poon@hotmail.com

More Related Content

What's hot (20)

PDF
API_Testing_with_Postman
Mithilesh Singh
ย 
PDF
CIใŒๅˆ†ใ‹ใ‚‰ใชใ„ PE๏ผˆSETใ‚จใƒณใ‚ธใƒ‹ใ‚ข๏ผ‰๏ผ‘ๅนด็”ŸใŒ VRT๏ผˆใƒ“ใ‚ธใƒฅใ‚ขใƒซใƒชใ‚ฐใƒฌใƒƒใ‚ทใƒงใƒณใƒ†ใ‚นใƒˆ๏ผ‰ใ‚’ใƒใƒผใƒ‰ใƒซไฝŽใCIใ‚’้‹็”จใ—ใŸ
ssuser0be501
ย 
PPTX
Katalon Studio Presentation.pptx
MuhammadHassan440279
ย 
PDF
ใ‚ขใƒƒใƒ—ใƒซใฎ็‰น่จฑใซ่ฆ‹ใ‚‹UI็‰น่จฑใฎใƒใ‚คใƒณใƒˆ
kurikiyo
ย 
PPTX
Robot control
Hiran Gabriel
ย 
PPTX
Introduction to Unified Functional Testing 12 (UFT)
Archana Krushnan
ย 
PPTX
Software evolution and Verification,validation
ArchanaMani2
ย 
ODP
Why Katalon Studio?
Knoldus Inc.
ย 
PPTX
60ๅˆ†ใฆใ‚™ใ‚ใ‹ใฃใŸๆฐ—ใซใชใ‚‹ISO29119 #wacate
Kinji Akemine
ย 
PPTX
Automation testing & Unit testing
Kapil Rajpurohit
ย 
PDF
Autoware vs. Computer Performance @ ROS Japan UG #43 ็ต„ใฟ่พผใฟๅ‹‰ๅผทไผš
kfunaoka
ย 
PDF
(์• ์ž์ผ) ํ…Œ์ŠคํŠธ ๊ณ„ํš์„œ ์ƒ˜ํ”Œ
SangIn Choung
ย 
PPT
Stub Testing and Driver Testing
Popescu Petre
ย 
PDF
ใƒใƒผใƒ ใฟใ‚’ๅคงๅˆ‡ใซใ—ใŸ ็งใŸใกใฎโ€œๅ—่จ—ใ‚ขใ‚ธใƒฃใ‚คใƒซใƒปใ‚นใ‚ฏใƒฉใƒ โ€ไฝ“้จ“่ซ‡
IIJ
ย 
PDF
What is UFT? HP's unified functional testing.
Confiz
ย 
PPTX
Core Java
NA
ย 
PDF
ใ‚ขใ‚ธใƒฃใ‚คใƒซร—ใƒ†ใ‚นใƒˆ้–‹็™บใ‚’่€ƒใˆใ‚‹
yasuohosotani
ย 
PDF
Sqa, test scenarios and test cases
Confiz
ย 
PDF
ใกใ‚‡ใฃใจๆ˜Žๆ—ฅใฎใƒ†ใ‚นใƒˆใฎ่ฉฑใ‚’ใ—ใ‚ˆใ†
Yasuharu Nishi
ย 
PPT
pick and place robotic arm
ANJANA ANILKUMAR
ย 
API_Testing_with_Postman
Mithilesh Singh
ย 
CIใŒๅˆ†ใ‹ใ‚‰ใชใ„ PE๏ผˆSETใ‚จใƒณใ‚ธใƒ‹ใ‚ข๏ผ‰๏ผ‘ๅนด็”ŸใŒ VRT๏ผˆใƒ“ใ‚ธใƒฅใ‚ขใƒซใƒชใ‚ฐใƒฌใƒƒใ‚ทใƒงใƒณใƒ†ใ‚นใƒˆ๏ผ‰ใ‚’ใƒใƒผใƒ‰ใƒซไฝŽใCIใ‚’้‹็”จใ—ใŸ
ssuser0be501
ย 
Katalon Studio Presentation.pptx
MuhammadHassan440279
ย 
ใ‚ขใƒƒใƒ—ใƒซใฎ็‰น่จฑใซ่ฆ‹ใ‚‹UI็‰น่จฑใฎใƒใ‚คใƒณใƒˆ
kurikiyo
ย 
Robot control
Hiran Gabriel
ย 
Introduction to Unified Functional Testing 12 (UFT)
Archana Krushnan
ย 
Software evolution and Verification,validation
ArchanaMani2
ย 
Why Katalon Studio?
Knoldus Inc.
ย 
60ๅˆ†ใฆใ‚™ใ‚ใ‹ใฃใŸๆฐ—ใซใชใ‚‹ISO29119 #wacate
Kinji Akemine
ย 
Automation testing & Unit testing
Kapil Rajpurohit
ย 
Autoware vs. Computer Performance @ ROS Japan UG #43 ็ต„ใฟ่พผใฟๅ‹‰ๅผทไผš
kfunaoka
ย 
(์• ์ž์ผ) ํ…Œ์ŠคํŠธ ๊ณ„ํš์„œ ์ƒ˜ํ”Œ
SangIn Choung
ย 
Stub Testing and Driver Testing
Popescu Petre
ย 
ใƒใƒผใƒ ใฟใ‚’ๅคงๅˆ‡ใซใ—ใŸ ็งใŸใกใฎโ€œๅ—่จ—ใ‚ขใ‚ธใƒฃใ‚คใƒซใƒปใ‚นใ‚ฏใƒฉใƒ โ€ไฝ“้จ“่ซ‡
IIJ
ย 
What is UFT? HP's unified functional testing.
Confiz
ย 
Core Java
NA
ย 
ใ‚ขใ‚ธใƒฃใ‚คใƒซร—ใƒ†ใ‚นใƒˆ้–‹็™บใ‚’่€ƒใˆใ‚‹
yasuohosotani
ย 
Sqa, test scenarios and test cases
Confiz
ย 
ใกใ‚‡ใฃใจๆ˜Žๆ—ฅใฎใƒ†ใ‚นใƒˆใฎ่ฉฑใ‚’ใ—ใ‚ˆใ†
Yasuharu Nishi
ย 
pick and place robotic arm
ANJANA ANILKUMAR
ย 

Similar to iOS Automation: XCUITest + Gherkin (20)

PDF
Automated Xcode 7 UI Testing
Jouni Miettunen
ย 
PPTX
open-west
Konnor Willison
ย 
PDF
SauceCon19: Fashionable XCUITest for iOS App
Shashikant Jagtap
ย 
PDF
Fashionable XCUITest for iOS Apps by Shashikant Jagtap
Sauce Labs
ย 
PDF
Cucumber meets iPhone
Erin Dees
ย 
PDF
Ui testing in xcode
allanh0526
ย 
PDF
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
pCloudy
ย 
PDF
Mobile Development integration tests
Kenneth Poon
ย 
PDF
Make XCUITest Great Again
Kenneth Poon
ย 
PDF
iOS Automation Frameworks evaluation
Serghei Moret
ย 
PDF
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
kalichargn70th171
ย 
PDF
The Cowardly Test-o-Phobe's Guide To Testing
Tim Duckett
ย 
PDF
DevOpsGirls at TConf 2019
Theresa Neate
ย 
PPTX
XCUITest for iOS App Testing and how to test with Xcode
pCloudy
ย 
PPTX
Suparna - XCUITest
SUPARNA KHAMARU
ย 
PDF
X-Code UI testing architecture and tools
Jianbin LIN
ย 
KEY
Ui BDD Testing
Taras Kalapun
ย 
PDF
Automated interactive testing for i os
Mobile March
ย 
KEY
Continuous integration & deployment
Alan Harper
ย 
PDF
Testing iOS Apps with HadoopUnit 3rd Edition Scott Tilley Krissada Dechokul
peshekaowlad
ย 
Automated Xcode 7 UI Testing
Jouni Miettunen
ย 
open-west
Konnor Willison
ย 
SauceCon19: Fashionable XCUITest for iOS App
Shashikant Jagtap
ย 
Fashionable XCUITest for iOS Apps by Shashikant Jagtap
Sauce Labs
ย 
Cucumber meets iPhone
Erin Dees
ย 
Ui testing in xcode
allanh0526
ย 
Understanding XCUITest Framework Your Guide to Efficient iOS Testing.pdf
pCloudy
ย 
Mobile Development integration tests
Kenneth Poon
ย 
Make XCUITest Great Again
Kenneth Poon
ย 
iOS Automation Frameworks evaluation
Serghei Moret
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
kalichargn70th171
ย 
The Cowardly Test-o-Phobe's Guide To Testing
Tim Duckett
ย 
DevOpsGirls at TConf 2019
Theresa Neate
ย 
XCUITest for iOS App Testing and how to test with Xcode
pCloudy
ย 
Suparna - XCUITest
SUPARNA KHAMARU
ย 
X-Code UI testing architecture and tools
Jianbin LIN
ย 
Ui BDD Testing
Taras Kalapun
ย 
Automated interactive testing for i os
Mobile March
ย 
Continuous integration & deployment
Alan Harper
ย 
Testing iOS Apps with HadoopUnit 3rd Edition Scott Tilley Krissada Dechokul
peshekaowlad
ย 
Ad

Recently uploaded (20)

PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
ย 
PPTX
Cutting Optimization Pro 5.18.2 Crack With Free Download
cracked shares
ย 
PPTX
Operations Profile SPDX_Update_20250711_Example_05_03.pptx
Shane Coughlan
ย 
PDF
Instantiations Company Update (ESUG 2025)
ESUG
ย 
PDF
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
ย 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
ย 
PPT
Brief History of Python by Learning Python in three hours
adanechb21
ย 
PDF
Code and No-Code Journeys: The Maintenance Shortcut
Applitools
ย 
PDF
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
ย 
PDF
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
ย 
PDF
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
ย 
PPTX
Transforming Lending with IntelliGrow โ€“ Advanced Loan Software Solutions
Intelli grow
ย 
PDF
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
ย 
PPTX
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
ย 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
ย 
PDF
Introduction to Apache Icebergโ„ข & Tableflow
Alluxio, Inc.
ย 
PPTX
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
ย 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
ย 
PPTX
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
ย 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
ย 
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
ย 
Cutting Optimization Pro 5.18.2 Crack With Free Download
cracked shares
ย 
Operations Profile SPDX_Update_20250711_Example_05_03.pptx
Shane Coughlan
ย 
Instantiations Company Update (ESUG 2025)
ESUG
ย 
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
ย 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
ย 
Brief History of Python by Learning Python in three hours
adanechb21
ย 
Code and No-Code Journeys: The Maintenance Shortcut
Applitools
ย 
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
ย 
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
ย 
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
ย 
Transforming Lending with IntelliGrow โ€“ Advanced Loan Software Solutions
Intelli grow
ย 
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
ย 
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
ย 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
ย 
Introduction to Apache Icebergโ„ข & Tableflow
Alluxio, Inc.
ย 
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
ย 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
ย 
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
ย 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
ย 
Ad

iOS Automation: XCUITest + Gherkin

  • 2. โ€ข Technical Lead iOS Engineer @ PropertyGuru โ€ข Agile, Xtreme Programming โ€ข Tests โ€ข Calabash-iOS ----> XCUITest โ€ข Demo [https://github.com/depoon/WeatherAppDemo]
  • 3. Agenda 1. Introduction XCUITest 2. Building a simple Test Suite 3. Gherkin for XCUITest
  • 4. XCUITest โ€ข Introduced in Xcode 7 in 2015 โ€ข xUnit Test Cases (XCTestCase) โ€ข UITest targets cant see production codes โ€ข Builds and tests are all executed using XCode (ObjC/Swift) โ€ข Record functionality 1. Introduction (iOS Automation Tools, XCUITest)
  • 5. XCUITest - Recording 1. Introduction (iOS Automation Tools, XCUITest) [Source] http://blog.xebia.com/automated-ui-testing-with-react-native-on-ios/
  • 6. XCUITest - XCUIElement 1. Introduction (iOS Automation Tools, XCUITest) XCUIElement //Elements are objects encapsulating the information needed to dynamically locate a user interface.element in an application. Elements are described in terms of queries [Apple Documentation - XCTest] let app = XCUIApplication() //Object that queries views on the app app.staticTexts //returns XCUIElementQuery โ€œcollectionโ€ representing โ€œUILabelsโ€ app.buttons //returns XCUIElementQuery โ€œcollectionโ€ of representing โ€œUIButtonsโ€ app.tables //returns XCUIElementQuery โ€œcollectionโ€ of representing โ€œUITablesโ€ app.tables.staticTexts //returns XCUIElementQuery โ€œcollectionโ€ representing โ€œUILabelsโ€ which has superviews of type โ€œUITableโ€ app.staticTexts[โ€œHello Worldโ€] //returns a label element with accessibilityIdentifier or text value โ€œHello Worldโ€ app.tables[โ€œmyTableโ€] //returns a table element with accessibilityIdentifier โ€œmyTableโ€
  • 7. 1. Introduction (iOS Automation Tools, XCUITest) groups disclosureTrian gles tabGroups sliders images menus windows popUpButtons toolbars pageIndicators icons menuItems sheets comboBoxes statusBars progressIndicat ors searchFields menuBars drawers menuButtons tables activityIndicator s scrollViews menuBarItems alerts toolbarButtons tableRows segmentedCon trols scrollBars maps dialogs popovers tableColumns pickers staticTexts webViews buttons keyboards outlines pickerWheels textFields steppers radioButtons keys outlineRows switches secureTextFiel ds cells radioGroups navigationBars browsers toggles datePickers layoutAreas checkBoxes tabBars collectionViews links textViews otherElements app.otherElements //returns [ elements ] of UIView XCUITest - XCUIElement
  • 8. XCUITest - Interactions 1. Introduction (iOS Automation Tools, XCUITest) let app = XCUIApplication() //Object that queries views on the app app.staticTexts[โ€œHello Worldโ€].exists //returns true if element exists app.buttons[โ€œSaveโ€].tap() //taps the โ€œSaveโ€ button app.tables[โ€œmyTableโ€].swipeUp() //swipes up the table app.textFields[โ€œmyFieldโ€].typeText(โ€œJohn Doeโ€) //types value in textField Other interactions: pinchWithScale, pressForDuration, doubleTap() XCTAssertTrue(app.staticTexts[โ€œHello Worldโ€].exists) //Throws exception if label does not exists
  • 9. Requirements 2. Building a simple test suite Create a Weather App 1. Given I am at the City Search Screen When I search for a valid city (eg โ€œLondonโ€) Then I should see a weather details page of that city 2. Given I am at the City Search Screen When I search for an invalid city (eg โ€œNotACityโ€) Then I should see an error message
  • 10. Hereโ€™s what we built 2. Building a simple test suite
  • 11. Creating a UITest Target 2. Building a simple test suite
  • 12. Recording - Valid City 2. Building a simple test suite
  • 13. Recording - Invalid City 2. Building a simple test suite
  • 14. Generated Code - Valid City 2. Building a simple test suite func testUserAbleToSearchForValidCity() { let app = app2 app.searchFields["Search a city"].tap() app.searchFields["Search a city"] let app2 = app app2.buttons["Search"].tap() app.searchFields["Search a city"] let tablesQuery = app2.tables tablesQuery.staticTexts["London"].tap() tablesQuery.staticTexts["53"].tap() tablesQuery.staticTexts["Partly Cloudy"].tap() }
  • 15. Generated Code - Invalid City 2. Building a simple test suite func testUserSeesErrorMessageForInvalidCity() { let app = XCUIApplciation() app.searchFields["Search a city"].tap() app.searchFields["Search a city"] app.buttons["Search"].tap() app.searchFields["Search a city"] let errorAlert = app.alerts["Error"] errorAlert.staticTexts["Error"].tap() errorAlert.staticTexts[ "Unable to find any matching weather location to the query submitted!โ€ ].tap() errorAlert.collectionViews["OK"].tap() }
  • 16. 2. Building a simple test suite func testUserAbleToSearchForValidCity() { let app = XCUIApplication() let searchField = app.searchFields["Search a city"] searchField.tap() searchField.typeText("London") app.buttons["Search"].tap() self.userWaitsToSeeText("London") self.userWaitsToSeeText("53") self.userWaitsToSeeText("Partly Cloudyโ€) self.waitForExpectationsWithTimeout(5, handler: nil) } private func userWaitsToSeeText(text: String){ self.expectationForPredicate( NSPredicate(format: "exists == 1"), evaluatedWithObject: XCUIApplication().tables.staticTexts[text], handler: nil ) // XCUIApplication().tables.staticTexts[text].exists <โ€” boolean } Refactored Code
  • 17. 2. Building a simple test suite func testUserSeesErrorMessageForInvalidCity() { let app = XCUIApplication() let searchField = app.searchFields["Search a cityโ€] searchField.tap() searchField.typeText("NotACity") app.buttons["Search"].tap() self.userWaitsToSeeText("Error") self.userWaitsToSeeText( "Unable to find any matching weather location to the query submitted!" ) self.waitForExpectationsWithTimeout(5, handler: nil) self.userTapsOnAlertButton("OK") } private func userTapsOnAlertButton(buttonTitle: String){ XCUIApplication().buttons[buttonTitle].tap() } Refactored Code
  • 18. 2. Building a simple test suite Scheme Management
  • 19. 2. Building a simple test suite Scheme Management
  • 21. (User Registration) Given I am at the user registration page When I enter invalid email address And I tap โ€œRegisterโ€œ Then I should see โ€œInvalid Email Addressโ€ Gherkin - Example 1 3. Use Gherkins
  • 22. (Shopping with existing Items in shopping cart) Given I have 1 Wallet and 1 Belt in my shopping cart And I am at the Shopping Item Details Page for a Bag When I select quantity as โ€œ1โ€ And I tap on โ€œAdd to Shopping Cartโ€ Then I should be at Shopping Cart Screen And I should see โ€œ3โ€ total items in my shopping cart Gherkin - Example 2 3. Use Gherkins
  • 23. 2. Building a simple test suite Given I am at Weather Search Form Page When I enter city search for โ€œLondonโ€ Then I should be at Weather Details Page And I wait to see โ€œLondonโ€ And I wait to see โ€œ53โ€ Gherkin - Our Acceptance Tests
  • 24. 2. Building a simple test suite Given I am at Weather Search Form Page When I enter city search for โ€œNotACityโ€ Then I wait to see โ€œErrorโ€ And I wait to see โ€œUnable to โ€ฆโ€ And I tap on alert button โ€œOKโ€ Gherkin - Our Acceptance Tests
  • 25. 3. Use Gherkins โ€ข Language used in Behavioural Driven Development (BDD) to specify software requirements with examples โ€ข Executable, facilitate collaboration with non developers โ€ข Lets add Gherkin to our project in Xcode https://github.com/net-a-porter-mobile/XCTest-Gherkin pod 'XCTest-Gherkin' Gherkin
  • 26. 3. Use Gherkins[Source] https://github.com/net-a-porter-mobile/XCTest-Gherkin Gherkin
  • 27. 3. Use Gherkins Given I am at Weather Search Form Page When I enter city search for โ€œLondonโ€ Then I should be at Weather Details Page And I wait to see โ€œLondonโ€ And I wait to see โ€œ53โ€ step("I (am|should be) at Weather Search Form Pageโ€) { let weatherSearchPage = WeatherSearchPage(self.test) } struct WeatherSearchPage{ init(testCase: XCTestCase){ testCase.expectationForPredicate( NSPredicate(format: โ€œexists == 1โ€), evaluatedWithObject: XCUIApplication().otherElements[โ€œWeatherSearchPageโ€], handler: nil ) testCase.waitForExpectationsWithTimeout(5, handler: nil) } }
  • 28. 3. Use Gherkins Given I am at Weather Search Form Screen When I enter city search for โ€œLondonโ€ Then I should be at Weather Details Page And I wait to see โ€œLondonโ€ And I wait to see โ€œ53โ€ step("I enter city search for โ€(.*?)โ€โ€) { (matches: [String]) in let weatherSearchPage = WeatherSearchPage(testCase: self.test) weatherSearchPage.userSearchForCity(matches.first!) } struct WeatherSearchPage{ func userSearchForCity(city: String){ let app = XCUIApplication() let searchField = app.searchFields[โ€œSearch a cityโ€] searchField.tap() searchField.typeText(city) app.buttons[โ€œSearchโ€].tap() } }
  • 29. 3. Use Gherkins Given I am at Weather Search Form Page When I enter city search for โ€œLondonโ€ Then I should be at Weather Details Page And I wait to see โ€œLondonโ€ And I wait to see โ€œ53โ€ step("I (am|should be) at Weather Details Pageโ€) { WeatherDetailsPage(testCase: self.test) } struct WeatherDetailsPage{ init(testCase: XCTestCase){ testCase.expectationForPredicate( NSPredicate(format: โ€œexists == 1โ€), evaluatedWithObject: XCUIApplication().otherElements[โ€œWeather Forecastโ€], handler: nil ) testCase.waitForExpectationsWithTimeout(5, handler: nil) } }
  • 30. 3. Use Gherkins Given I am at Weather Search Form Page When I enter city search for โ€œLondonโ€ Then I should be at Weather Details Page And I wait to see โ€œLondonโ€ And I wait to see โ€œ53โ€ step("I wait to see โ€(.*?)โ€โ€) { (matches: [String]) in self.test.expectationForPredicate( NSPredicate(format: โ€œexists == 1โ€), evaluatedWithObject: XCUIApplication().staticTexts[matches.first!], handler: nil ) self.test.waitForExpectationsWithTimeout(5, handler: nil) }
  • 31. 3. Use Gherkins Given I am at Weather Search Form Page When I enter city search for โ€œNotACityโ€ Then I wait to see โ€œErrorโ€ Then I wait to see โ€œUnable to โ€ฆโ€ Then I tap on alert button โ€œOKโ€ step("I tap on alert button โ€(.*?)โ€โ€) { XCUIApplication().buttons[matches.first!].tap() }
  • 32. 3. Use Gherkins Using an additional pod to simply statements - https://github.com/joemasilotti/JAMTestHelper Gherkin
  • 33. 3. Use Gherkins Using an additional pod to simply statements - https://github.com/joemasilotti/JAMTestHelper Gherkin
  • 39. Gherkin - Using Feature File 3. Use Gherkins
  • 40. Why should I use Gherkin with XCUITest? 3. Use Gherkins โ€ข Acceptance Test Driven Development โ€ข Cross platform testing is still possible without need for 3rd party tools โ€ข Objective C + Swift

Editor's Notes

  • #3: The codes mentioned in the later slides can be found here show of hands: How Many people in the room are testers, developers, non-technical How many developers write Unit Tests? UI Automated Tests?
  • #4: Based on a couple of requirements, we will attempt to write XCUITest cases. Introducing the Gherkin Language and how we can bring this tool to XCUITest Wanted to share a segment on setting up fixtures for XCUITest
  • #5: Out of the box test automation Tool introduced in Xcode7. the way you would write tests is by querying for elements/subviews on the main app window XCUITest uses the XCTest framework which generally xUnitTest patterns. (abt testCases, setup/teardown, assertion when we run XCUITest, we build/install testTargetApp + testRunner. TestsR will launch+query elements on screen (blackbox) No Mocking
  • #6: Helpful for developers to discover how to use the api Look at the codesโ€ฆ explain
  • #7: youโ€™ll mainly be working with XCUIElement
  • #8: you can also use โ€œother elementsโ€™ to return a collection of anything that is subclass of UIView
  • #9: Now that you have some idea of what the api can do, lets go ahead and write our first XCUITest case!
  • #12: show the plus sign before running
  • #13: We will record the test case for the first requirement for Valid city One importantly tip here, you may want to click on the elements during recordings as Xcode will help generate the statements we may need to use later
  • #15: Explain code As u can see, Xcode may not always generate the desired codes. For this case, the codes for typing the search string is missing
  • #18: As you can see hereโ€ฆ. we simply filled in the blanks for the missing/incorrect codesโ€ฆ and we organised them little bit
  • #19: You can use Scheme to manage your tests. This allows you to build tests against just 1 test target and use different scheme to decide which tests you want to run. Smoke vs Regression. Local vs Running in a particular env.
  • #20: of course, changing env requires you to change api target in your app If you want to change which env you want your app to be run in, you can use scheme to modify your config - ** remember to encrypt your config file before you package your .app / .ipa file
  • #21: If you don't know whatโ€™s Gherkin, this is an example of a feature file written in Gherkin Gherkin is a human readable syntax use to construct acceptance test cases. BDD Keywords: Feature, Scenario, (below scenario are steps) Given, When Then Today, focus on how to use Given When Then
  • #24: - Btw, this is taken from our iOS offline interview assignment where we ask candidates to code, and the interview panel conducts very thorough code reviewโ€ฆ Look at how you architect/decouple codes, name variables, any abuse of coding structures/design patterns, how you write tests, whether you have proper code coverage
  • #25: - Btw, this is taken from our iOS offline interview assignment where we ask candidates to code, and the interview panel conducts very thorough code reviewโ€ฆ Look at how you architect/decouple codes, name variables, any abuse of coding structures/design patterns, how you write tests, whether you have proper code coverage
  • #27: In our test case file, specify the Given When Then in a test method create a subclass of StepDefiner that evaluates the GWT steps definition
  • #28: Specify steps without using โ€œGWTโ€ specify โ€œamโ€ or โ€œshould beโ€ โ€ฆ so that i can reuse it in Given or Then Where do i put this string? i can go to VC.viewDidLoad
  • #41: ATTD: Work with QA, PO. They can fill up features. 1st specify features, hook it into CI and get it to pass. in PG we asked PO to write and commit the feature before we start any work android/ios devโ€ฆ u only need feature files to bind same requirements together No need to learn other programming language required by any 3rd party tool
  • #42: I hope you guys gotten a good picture on how to use XCUITest and Gherkin. If any of you guys need help or tips to kickstart UITest+Gherkin in your personal or company work, feel free to chat with me later during the break or buzz me via my emails