iOS Automation Testing Best Practices
Cara Suarez
iOS automation testing involves testing applications that are made for iOS devices only. Testing applications, in general, requires the tester to understand the purpose of the application, its technical requirements, and performance metrics to compare the expected behavior versus the actual behavior. The iOS family is a closed environment that is licensed to operate on Apple devices only. This makes it easier to test the application across the device range as opposed to Android applications that can be deployed into a much larger array of devices.
Looking to find the right automation testing framework for your team? We can help you.
The iOS application needs to be tested both manually and using automation scripts. Bugs are inevitable in any application despite thoughtful designing. iOS automation testing is just as important as testing any application whether it is on iOS or Android platforms. Quality assurance activities must be performed right from the beginning of the application lifecycle. In iOS applications, since the devices are known, and the OS updates are well-planned, it is more convenient to perform testing on these devices. Automated testing on iOS applications has a multitude of benefits. Running automated test scripts helps save time and effort as it allows one test to run in parallel across multiple devices.
An iOS application needs to be tested not only for its functionality but its UI/UX design too. The test cases must be applied to the various iDevices – viz, iPhone, iPad, iPad mini, iPad Pro, Apple Watch, Apple TV, iMac (of various screen sizes), iPod Touch, Macbooks, etc. – to ensure the UI/UX is being implemented as expected on devices of varied resolutions. Apart from testing on the array of devices where the application will be deployed, as a tester, you would also require to test out the application from every angle. Some other types of testing that are essential include unit testing, functional testing, visual UI testing, as well as end-to-end testing. Let’s take a moment to look at each type of testing:
Having tight schedules for release is not uncommon when developing iOS applications. This gives the QA team less time to integrate the multitude of features that the application performs or to create new test scripts.
With the introduction of face-ID and fingerprint authentication methods, it can be harder to automate most of the test cases. Manual intervention is deemed necessary in such cases. It can be hard to automate the environments of dynamic carrier network conditions and related background processes which requires specialized expertise.
Some other challenges faced in automating iOS application testing include troubleshooting and debugging the test code due to lack of time. The absence of an adequate mobile testing lab can also prove arduous.
On top of that, the automation framework solutions for iOS automation testing, and for mobile application testing in general, is minimal compared to various frameworks and solutions provided for web applications.
When it comes to UI/UX testing, we are required to test the application on all the compatible devices, but it can get quite expensive for executing tests on all the devices. This is where emulators or simulators come into play. Apart from the cost perspective, there is also the matter of debugging the application step-by-step which is not as easy to spot when testing with real devices.
On the contrary, the processing speed of testing with a real device can be quicker than working with emulators/simulators. Reliability plays a major role here, as well. Real devices can be more reliable when compared to emulators/simulators since simulating all kinds of user interactions can be tedious.
Although emulators and simulators are easily attainable to spin up, they cannot quite capture the scenarios where the device’s battery or storage is low or when the flow is interrupted by calls or notifications. In such instances, manually testing with real devices can be more satisfactory. Additionally, as mentioned above, real devices are preferable in executing regression and end-to-end testing to simulate a user’s actions as close as possible.
When it comes to application testing, taking screenshots or recording the screen for every step or action can be crucial in debugging and understanding the application’s actual behavior. On iOS devices, screenshots can be taken manually by pressing the power and home buttons together on older devices and pressing the power and volume up buttons on the latest devices. To record the screen, we can use QuickTime to record the iOS device screen, provided it is connected to a Mac machine using a lightning cable. Some tools offer automated screenshots and screen recordings, such as fastlane, which uses XCUITest to take screenshots. Additionally, there are iOS automation testing frameworks that also deliver rich reporting and communication during your automation and testing efforts.
Crash logs are used to understand the root cause in case of application failure. In such instances, you need to catch the crash logs. The following steps can be taken to capture the crash logs:
Console logs, on the other hand, display the complete information of the AUT (application under test) on the iOS device. To view the console logs, you will need to use the iTools application. Once you’ve downloaded the application, connect the device to the system where the iTools application is running and click on the Toolbox icon. The last step is to click on the Real-Time Log button which displays the console log.
In some frameworks like XCTest and Appium, we can use SetUp and TearDown methods to customize the state of the test cases according to your testing needs.
setUp(): This method can be used to set the initial state of each test case before the particular test method is run.
tearDown(): This method can be used to clean up after each test case or test method is complete.
These methods are essential for effective iOS automation testing using some common testing frameworks to avoid test failure due to cache.
Created by Selenium, the pioneering web application automation framework, Appium is the mobile application automation framework. Since within the same family, Appium utilizes the same Selenium WebDriver and HTTP protocol process to automate mobile applications, including iOS applications. It is an open-source platform, and it is not restricted by programming languages, as you can test the application in most of the commonly used languages, such as Java, C#, Python, Ruby, etc. Additionally, Appium can be integrated with any additional framework or tool needed to help facilitate mobile application automation. Thus, Appium offers a flexible way of setting up your testing needs as you see fit.One of the major advantages of Appium is that it works on any kind of mobile application, including web, native, and hybrid, which implies that we can use the same Appium code on both iOS and Android devices.
XCTest is Apple’s official testing framework to perform unit tests. XCUITest is a UI testing framework that is built upon the XCTest framework and includes supplementary classes that aid in UI testing such as UIAccessibility. Both frameworks can be written in either Objective C or Swift. Since it is native to iOS devices, it does not require any supporting software or packages to perform testing on the AUT (application under test).XCTest/XCUITest is faster than other automation frameworks for iOS applications. XCTest does not require additional layers of abstraction APIs and is therefore lightweight. XCode Test Recorder is another option if you decide to use XCTest as your automation framework. With the test recorder, it is easier to perform UI test scenarios as we can record and playback the executed UI tests
Google has put forward its own, open-source, and flexible, internal UI Testing framework named EarlGrey. It comes with its distinctive advantages such as:
Calabash is also an open-source framework that can perform testing in both iOS and Android platforms. To automate test cases in Calabash, the test cases must be written in Cucumber. Cucumber is a Behavior Driven Development framework that uses the Gherkin language for writing test scenarios in the ‘Given, When, Then’ format that makes it easier for the business analysts and stakeholders to understand the test scenarios without demanding any technical coding knowledge from them. Calabash can interact with native as well as hybrid applications. It consists of various beneficial features such as screenshot recording capabilities, and gestures.
Detox is a tool that can be specifically used for end-to-end, UI automation testing needs. It supports JavaScript and is meant to work as a grey box testing framework that is easier to learn. Some of the advantages of Detox are:
This framework is used to create stub objects in the iOS AUT. It can be implemented with a static library to develop iOS applications or as a framework used for OS X development. Its strengths include:
Like most iOS automation testing frameworks out there, KIF is an open-source tool. It is an iOS native application, and a developer will need to add the KIF framework to the project. Some key benefits of KIF are listed below:
Performing iOS automation testing on iOS applications can be both interesting and challenging. As discussed above, it can be strenuous to keep up with the advancing technology, such as face-ID and fingerprint authentication, that have taken over the age-old PIN and password authentication methods. It is not easy, considering the time-restricting OS version upgrades that occur periodically, but fortunately, these upgrades are well-planned.
To summarize, it is crucial for the development and QA teams to put forth best practices to be well-equipped to handle any challenge that may arise. It is important to know when to use emulators/simulators and when the real devices need to be put to test. We need to make use of screen capturing and recording tools, as well as, crash and console logs to trace the steps of the test cases and to understand potential UI issues that may surface in order to fix them in a timely manner.
Now that we have discussed an overview of testing iOS applications, it is apparent that choosing the right automation framework, the right supplementary tools and methods, as well as testing devices (emulators/simulators/stubs) for your project team are vital in successfully testing the application. Based on the skillset of your team, choose the best framework to test your iOS application.
Looking for a mobile automation testing framework?