UI testing - How to inspect your iOS app with Calabash and Appium

Part of the journey in software development is testability. Regarding mobile development, testability for your iOS app goes through UI testing. Let’s see different way to inspect any UI elements and prepare your iOS app for UI automation testing.

Before inspecting anything, best is to place accessibility identifiers to make your work easier. If you don’t know where to start, easiest is to hardcode them programmatically as follow

enum AccessibilityIdentifiers : String {
    case searchDeparture
    case searchArrival
}

Implement your class in your ViewController

override func viewDidLoad() {
    super.viewDidLoad()

    self.departureButton.accessibilityIdentifier = AccessibilityIdentifiers.searchDeparture.rawValue
    self.arrivalButton.accessibilityIdentifier = AccessibilityIdentifiers.searchArrival.rawValue

    ...
}

That’s it, your element is ready to be found and inspected!

Xcode

Starting with Apple IDE, Xcode has already some built-in tools that you can use to detect your elements, first one is Accessibility Inspector

Under Xcode > Developer Tools > Accessibility Inspector, you can start inspecting UI elements in your app. Make sure to select your device or simulator in the dropdown.

xcode-inspector

The second way to make sure you identifier is properly setup and accessible with your testing framework is actually to record your journey.

Still in Xcode, after creating a UI testing target, you are able to record a journey in the app. Xcode will automatically generates the test for you: it translates your journey into steps, making an XCUITest ready to use, including the accessibility identifiers. That means you’ll be able to rerun this scenario every time, your identifiers will always be in the picture.

Calabash iOS

If you use Calabash library as testing framework for your iOS application, there is also a pretty niet way to quickly detect if the accessibility identifier and other elements are ready to get access to.

# launching calabash interactive console
$ calabash-ios console
...

# list all the accessibiltiy identifiers found in the view
> query("*",:accessibilityIdentifier)
[  0] nil,
...
[  45] "searchArrival",
...

Appium

I might not be the biggest fan of Appium when it comes to performance of UI tests , but its inspection tool works pretty good, it can be a good alternative.

The process is slightly different, no need to run a target in Xcode. You will need to start Appium Server using an app file previously generated and the inspector will do the rest.

appium-inspector

Why do you need all this tools?

UI Automation testing is a really good way to keep high quality of your app but it can be time consuming. There are some edge cases in iOS that you would prefer having covered, especially native components like the remote notification permission or review request popup from SKStoreReviewController.

Now you have many ways to make sure your iOS app is ready for your test, keeping the user experience at its best.

Happy testing!

© 2023 Benoit Pasquier. All Rights Reserved
Author's picture

Benoit Pasquier

Software Engineer 🇫🇷, writing about career development, mobile engineering and self-improvement

ShopBack 💰

Singapore 🇸🇬