iOS | XCUITest — How to Automate Tests for Apps without having access to Dev Source Code?

Suparna Khamaru
3 min readAug 23, 2020

--

It may sound unusual to treat XCUITest to behave like Appium in an unfortunate situation such as while learning and exploring hands on with XCUITest, if you do not have access to development source code, even though it may not be a preferred way of testing and scripting.

This article picks up a random app from app store, and automates a few use cases to see if XCUITest does not limit a tester from automating, when user has no access to development source code (as in Appium world).

What is the first step to know before automating the App Under Test?

In iOS, all apps are identified by unique bundle identifiers. So as an automation test professional, first agenda is to find out the bundle identifier of the App Under Test.

While there are many ways to find bundle identifiers, I can also confirm that the following approaches do work: https://mrvirk.com/how-to-find-app-bundle-id-ios.html

Where to start automating if you do not have access to Development Source Code?

When you do not have access to development source code, one approach could be to automate the app store user journey itself, where you search the app under test in the app store and open/download/update as needed, eliminating manual intervention completely.

What bundle identifiers would we require to start automation from the app store?

Step 1: As “App Store” itself is an app pre-installed in all iOS devices, initialise the bundle identifier of App Store app in Test Framework, as given below:

let appStore = XCUIApplication(bundleIdentifier: “com.apple.AppStore”)

Step 2: Initialise your desired “App Under Test” in Test Framework

let abcApp = XCUIApplication(bundleIdentifier: “com.company.abcApp”)

Step 3: Initialise springboard, as we will have to automate some of the home screen elements in the iOS device

let springBoard = XCUIApplication(bundleIdentifier: “com.apple.springboard”)

Step 4: Initialise settings, if we have to deal with any settings and preferences in the iOS device while running scripts

let settings = XCUIApplication(bundleIdentifier: “com.apple.Preferences”)

How to use the above initialised bundle identifiers in the iOS test framework?

Let us consider the case where an app is to be searched in app store and then install/open/upgrade, based on situation.

How would my test look like, with the addition of the above functions?

func test_Download_Install_Open_TwitterApp_From_AppStore() { 

appStore.launch()
AppInstall()
.open_AppStore_And_Search_Twitter_App()
.download_Install_And_Open_Twitter_App_From_AppStore()
}

How far can you automate an app without the source code?

Not having access to source code could be frustrating as that also disallows us from making any required changes in the source code that otherwise may help in scripting easy.

However, the entire app may be automated in XCUITest smoothly, as good as its done in Appium.

Sample of a demo ran using XCUITest is attached below:

Automated Test Runs of a sample app, with no access to source code

Note: Numbering & segregation is just for the demo. In Realtime, it’s best to keep each test independent from the other tests.

How does the tests run, when some of the app features are automated using XCUITest?

It looks really cool & runs very fast. See it yourself below!

Video of the Test runs using XCUITest

Conclusion

Anything that can be ran using Appium, can also be done using XCUITest. However, with XCUITest — much more uncountable test flows & user journeys can be achieved much faster and more reliably.

Thanks for reading this article! Leave a comment below if you have any questions. Be sure to click on the 👏 icon to let me know that you encourage my writing.

Connect with me:

--

--

Suparna Khamaru
Suparna Khamaru

Written by Suparna Khamaru

I am passionate about iOS, Android, Web apps,API test, Automation & ACI— https://www.linkedin.com/in/suparnakhamaru/

Responses (3)