Tips & Tricks in iOS Test Automation #3

Okay this part will not be long, but has some stuff important I experienced lately, I hope it will be a benefit for you :)

Aya Akl
2 min readNov 1, 2019

Previous Tips:

Part 1

Part 2

For XCUITest:

1- It is for sure important to use async wait in your UI tests so that not to make them flaky if the UI was some how slow and selection of the UI element does not succeed because it didn’t find the element. So we async wait the XCUIElemet to appear or disappear or any other expectation

In order to to this I have been using XCTest wait function with expectations which is awesome feature. I was using #XCTKVOExpectation, beautiful way of code and you have your key and value to set the expectation to wait. Unfortunately although it looks good but it made UI tests so slow because it is slow in perforce and functionality. So I changed back to using #XCTNSPredicateExpectation which is waaaaaaaaay more faster and my UI tests execution time just dropped down and they are back to being fast again!

So my async wait helper will look like something like that:

let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == 1"), object: XCUIElement)XCTWaiter().wait(for: [expectation], timeout: timeout)

2- I think Apple made some enhancements in the permission handler checking from the UI, for example if you have a system alert you want to deal with when you are running your UI tests. So in my older helpers for dealing with this system permission alerts, I was just dealing with the alerts without the need to handle something from the app side. Now after dealing with the system alert either by allowing or dismissing, it is better to activate or tap on the app again.

So instead of using:

addUIInterruptionMonitor(withDescription: "Siri") { (alert) -> Bool inlet siriAlertButton = alert.buttons["OK"]if siriAlertButton.exists {siriAlertButton.tap()return true}return false}

I made a change and it would be something like this:

addUIInterruptionMonitor(withDescription: "Siri") { (alert) -> Bool inlet siriAlertButton = alert.buttons["OK"]if siriAlertButton.exists {siriAlertButton.tap()return true}return false}
app.tap()

3- I have been using some Notifications and Notification Center in dealing with some of the UI tests and in order of waiting for this notification to come, so I used this expectation: XCTNSNotificationExpectation

So my wait for notification helper will look like something like that:

let notificationsExpectation = XCTNSNotificationExpectation(name: .nameOfNotificationDidChange)XCTWaiter().wait(for: [notificationsExpectation], timeout: timeout)

That’s all for the time being :)

Again #3 :D , If you liked my tips please let me know to continue doing it in further posts ;)

HAPPY TESTING!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Aya Akl
Aya Akl

Written by Aya Akl

Author @QualityNexus || #Quality is my thing - Passionate human being who wants to change the world!!

No responses yet

Write a response