Top iOS Automation Tools and What Their Code Looks Like
Considering the advancements introduced in testing, iOS automation tools is a new challenge for everyone. The platform can help to easily test various iOS devices.
Join the DZone community and get the full member experience.
Join For FreeThe yearly increase in iOS device sales has set the bar high for the assured success of iOS. However, when it comes to testing these devices, purchasing devices with various HW specs and iOS devices isn't viable for SMEs and startups. Additionally, there are better testing solutions than manual testing due to scalability and low-efficiency concerns.
Although iOS is still a more closed operating system than Android, you may use various free and open-source technologies to build effective automated tests. It makes iOS app testing activities simpler and more efficient for developers and testers using a cloud-based testing solution.
Here are some automated testing frameworks with code examples that you can use to test your iOS applications.
Appium
One of the most popular open-source solutions, Appium helps users manage hybrid, mobile, or native apps for Android, iOS, and Windows. It enables developers and testers to build automated tests for mobile applications, enabling them to produce high-quality software more quickly and at lower risk.
Appium Benefits
- Appium is free-to-use and open-source.
- It supports all WebDriver-compatible languages like Java, Objective-C, and JavaScript.
- Its developers created it using the same JSON wire protocol as Selenium, making the transition easy for QA testers and mobile developers.
- Appium tests native, mobile web, and hybrid applications and is compatible with iOS and Android operating systems.
- It has the support of a sizable and active community that offers users ongoing assistance and troubleshooting.
- For unit testing, pick a supporting framework like XCTest or XCUITest.
- Its cross-platform compatibility allows it to reuse test scenarios across mobile and online channels.
- It is the benchmark for iOS WebDriver development.
Appium Disadvantages
- Adds to the learning curve by requiring users to comprehend the Appium architecture and the principles of native apps/ selectors.
- It depends on a series of open-source parts that you must install separately in a version that supports the others.
Appium Sample Code for WebDriver
driver.findElement(By.id("com.example.app:id/radio0")).click();
driver.findElement(By.id("com.example.app:id/radio1")).click();
driver.findElement(By.id("com.example.app:id/radio2")).click();
driver.findElement(By.id("com.example.app:id/editText1")).click();
driver.findElement(By.id("com.example.app:id/editText1")).sendKeys("Simple Test");
driver.findElement(By.name("Answer")).click();
Calabash
Another excellent cross-platform framework that is compatible with Android and iOS apps is Calabash. Calabash test written in Cucumber is one of the framework's main distinctions from other frameworks: this means that while the test is basic and easy to read, even for non-technical individuals, an automation system can still execute the tests because we write it like a specification.
Calabash Code Sample
Feature: Answer the Question feature
Scenario: As a valid user I want to answer app question
I wait for text "What is the best way to test application on hundred devices?"
Then I press Radio button 0
Then I press Radio button 1
Then I press Radio button 2
Then I enter text "Simple Test" into field with id "editText1"
Then I press view with id "Button1"
Earl Grey
Earl Grey is an open-source iOS UI automation framework and Google's response to XCUITest for testing iOS apps. Only iOS devices can use Earl Grey, and developers must write tests in Swift or Objective-C. Earl Grey's primary advantage is that it extends Espresso's synchronization capabilities to iOS app automation testing, ensuring that the automation is not attempting to act while the app is in use.
EarlGrey Advantages
- Easy to add, either directly or through CacaoPods, to an iOS project
- A versatile framework with effective internal component synchronization features
- The complete framework is open source.
- Combined with XCode
EarlGrey Sample Code
// Objective-C
- (void)testInvokeCustomSelectorOnElement {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id_of_element")]
performAction:[GREYActionBlock actionWithName:@"Invoke clearStateForTest selector"
performBlock:^(id element, NSError *__strong *errorOrNil) {
[element doSomething];
return YES; // Return YES for success, NO for failure.
}
]];
}
XCUITest
On iOS devices like iPads and iPhones, XCUITest is a test automation framework for UI testing mobile apps and online applications. It's a piece of Apple's testing infrastructure.
XCUITest offers a framework that enables programmatic identification and interaction with UI components from other testing tools. By 2022, the only UI interaction library for iOS supported is XCUITest, which replaced the outdated UIAutomator technology.
XCUITest Advantages
- You can use Swift or Objective-C to write both your application and test code, and both can be modified entirely within XCode and stored in the same repository.
- Because XCUITest and iOS work so well together, tests might run more quickly than with competing frameworks.
- By creating test code while observing user interactions with a linked Simulator or Real Device, XCode's "Record" feature enables testing. You can then modify the recorded test code to produce a trustworthy, repeatable test, saving time during test creation.
- Testers can use XCUITest to locate elements by the element's title, label, value, or placeholder value. For testing purposes only, XCUIElements can also have a specific "accessibility identifier" that makes finding elements quick and simple.
XCUITest Drawbacks
- Every computer your team uses to run XCUITest, including tester computers and CI/CD setups, must have XCode installed.
- It would be best to run the tests using the XCUITest runner; you cannot run the XCUITest code independently of the XCUITest framework.
- Swift and object-C are the only available programming languages.
XCode Sample Code
- (void) testAdditionPerformance {
[self measureBlock:^{
// set the initial state
[calcViewController press:[calcView viewWithTag: 6]]; // 6
// iterate for 100000 cycles of adding 2
for (int i=0; i<100000; i++) {
[calcViewController press:[calcView viewWithTag:13]]; // +
[calcViewController press:[calcView viewWithTag: 2]]; // 2
[calcViewController press:[calcView viewWithTag:12]]; // =
}
}];
}
Conclusion
Trying to set up your testing capabilities is a challenge. Moreover, iOS device testing requires expertise. Test automation platforms can help test iOS devices. These platforms let you connect to SIM-enabled iOS devices worldwide. Through such platforms, you can get actionable insights that can help you improve your iOS app.
Opinions expressed by DZone contributors are their own.
Comments