Top iOS Testing Frameworks

 

Did you know that the total number of iOS devices sold in the
market is 250 Million+?
11% of the iOS users remove the app after crashes
45% of iOS users would remove the paid apps after crashes
69% of iOS users would will stop playing and remove the games after first crash
6-7 iOS devices are sold every second

With the explosion of iOS devices year on year, the verge of iOS success is increasing higher than ever before. More start-ups and SMEs don’t find it financially sustainable to acquire every piece of iOS devices with different OS versions and hardware specs. On the other hand, testing apps or games manually is not anymore an ideal option for QA process due to low efficiency and scalability issue.

Test Automation

Though iOS is still a more closed operating system compared to Android, many open source test automation frameworks and tools can be utilized to create robust automated tests. Along with the help of a cloud-based testing solution, it enables developers/testers to verify app quality more efficient in a scalable way and makes iOS testing tasks easier.

Today we’d like to go through 5 widely used iOS testing frameworks nowadays with simple code samples to give you a basic understanding of getting started with your iOS testing. If you are also interested in Android test automation frameworks, do not forget to check out Top 5 Android Testing Frameworks, where code samples are provided as well.

Mobile-test-automation

APPIUM

Appiumappium logo is popular due to its flexibility and usability on both Android and iOS, and it works on native, hybrid and web applications. For iOS testing, it uses JSONWireProtocol to engage with iOS applications using Selenium WebDriver. Thanks for that, Appium does support mobile web testing very well and its use cases are very similar as if Selenium would be used for web testing.

APPIUM CODE SAMPLE

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();
// or alternatively with
driver.findElement(By.id(“com.example.app:id/button1”)).click();

XCTEST / KIF

XCTest is tightly coupled with Xcode but is still usable with both real iOS devices and simulators. XCTest allows developers to write tests for components at any level and also provides the framework for UI testing capabilities. XCTest tests are grouped into subclasses of XCTestCase. Writing any tests with XCTest should be trivial to iOS developers as XCTest is fully compatible with both Objective-C and Swift.

KIF (Keep It Functional) is an iOS integration test framework that is closely related to and uses XCTest test targets. KIF tests can be executed directly in XCTestCase or any subclass. KIF allows for easy automation of iOS applications by leveraging the accessibility attributes that the OS system makes available for those with visual disabilities.

CODE SAMPLE WITH OBJECTIVE-C

– (void)testClicksOnRadioButtons {
[tester tapViewWithAccessibilityLabel:@”Radio1”];
[tester tapViewWithAccessibilityLabel:@”Radio2”];
[tester tapViewWithAccessibilityLabel:@”Radio3”];
[tester enterText:@”Simple Test”
intoViewWithAccessibilityLabel:@”editText1”];
[tester tapViewWithAccessibilityLabel:@”Answer”];
}

CODE SAMPLE WITH SWIFT

testClicksOnRadioButtons() {
let app = XCUIApplication()
app.radiobutton[0].tap()
app.radiobutton[1].tap()
app.radiobutton[2].tap()

app.staticTexts[“Simple Test”]
app.button[0].tap()
}

Learn and get started with KIF by reading our blog about this: How to get started with KIF?

Know-more

CALABASH

Calabash logoCalabash is another great cross-platform framework that works perfectly with Android and iOS apps. One of the major differences to other frameworks is that Calabash tests are written in Cucumber. That means the test is written like a specification and is simple and easy to read even for non-tech people, but still executable by the automation system.

CALABASH CODE SAMPLE

Feature: Answer the Question feature
Scenario: As a valid user I want to answer app question
I wait for the 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”

Mobile Apps Testing

EARLGREY

To some degree, EarlGrey is the ‘Espresso for iOS’. It’s also developed and open sourced by Google. Google uses this test framework to test many iOS native apps including Google Calendar, YouTube, etc. As the codename goes, lots of similarities can be found between Espresso and EarlGrey. For example, EarlGrey tests will automatically wait for events (animations, network requests etc.) before trying to interact with the UI.

EARLGREY CODE SAMPLE

– (void)testBasicSelectionAndAction {
[[EarlGrey selectElementWithMatcher::grey_accessibilityID(@”ClickHere”)]
performAction:grey_tap()];

// Example of long press with EarlGrey matchers
– (void)testLongPress {
[[EarlGrey selectElementWithMatcher::grey_accessibilityLabel(@”Box”

)]
performAction:grey_longPressWithDuration(0.5f)];
[[EarlGrey selectElementWithMatcher::grey_accessibilityLabel(@”One Long Press”)]
assertWithMatcher:grey_sufficientlyVisible()];

// Example of multi-select, visible click on items
– (void)testCollectionMatchers {
id visibleSendButtonMatcher =
grey_allOf(grey_accessibilityID(@”Box”), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:visibleSendButtonMatcher]
performAction:grey_tap()];
}

JEST / JASMINE

Jasmine-LogoJest uses Jasmine behavior-driven framework as the basis for testing JavaScript code. Every test case starts from describe() function call, similar to how JUnit uses TestCase class. The describe() function takes 2 parameters – the description/title of the test case and the function to be executed. The it() function includes all the test steps and provides (similar to JUnit) series of expect() functions.

JASMINE CODE SAMPLE

describe(“Player”, function() {
var player;
var song;
beforeEach(function() {
player = new Player();
song = new Song();
});
it(“should be able to play a Song”, function() {
player.play(song);
expect(player.currentlyPlayingSong).toEqual(song);
//demonstrates use of custom matcher
expect(player).toBePlaying(song);
});
describe(“when song has been paused”, function() {
beforeEach(function() {
player.play(song);
player.pause();
});

it(“should indicate the song is paused”, function() {
expect(player.isPlaying).toBeFalsy();
// demonstrates use of ‘not’ with a custom matcher
expect(player).not.toBePlaying(song);
});
it(“should be possible to resume”, function() {
player.resume();
expect(player.isPlaying).toBeTruthy();
expect(player.currentlyPlayingSong).toEqual(song);
});
});
// demonstrates use of spies to intercept and test method calls
it(“tells the current song if the user has made it a favorite”, function() {
spyOn(song, ‘persistFavoriteStatus’);
player.play(song);
player.makeFavorite();
expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
});
//demonstrates use of expected exceptions
describe(“#resume”, function() {
it(“should throw an exception if song is already playing”, function() {
player.play(song);
expect(function() {
player.resume();
}).toThrow(“song is already playing”);
});
});
});

BONUS: UI AUTOMATION

UI Automation is a tool developed by Apple that automates the testing of iOS applications. Put in another way, UI Automation to iOS is similar with UI Automator to Android. UI Automation tests are written in JavaScript, adhering to an API defined by Apple. Below is the code written on Apple’s Developer portal.

NOTE! UI Automation still works fine if you are some using older version of Xcode, but with the latest Xcode, the entire UI Automation framework is deprecated by Apple.

UI AUTOMATION CODE SAMPLE

UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0]
If Edit button is the first button in your code, you can also have the code as below:
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[“Edit”]
Then you can use any of these three ways to call an action to tap that button:
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0].tap();
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[“Edit”].tap();
var editButton=UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0];
editButton.tap();
The Automation instrument has a complete element hierarchy that represents your app’s user interface. To view that hierarchy, use the logElementTree method to write an outline of it to the log:
UIATarget.localTarget().frontMostApp().logElementTree()

CONCLUSION

Though iOS app testing is totally different from Android app testing, you can use either Appium or Calabash to create test scripts that can be used to do cross-platform testing. That being said, every framework has its advantages and requirements are unique for each project. It’s recommended to do some further research, learn more about each framework and choose the one you are comfortable with. Happy iOS testing.

Subscribe now

1 Comment

  1. Hi Christa,

    I have gone through the error Log. Please find my comments below,

    • First the Node JS has to be upgraded to the latest version since some of the Appium support were deprecated for Node version less than v0.12. Use this Link to download Node JS installer.
    • Ensure that you have the SDK package configured for the device you are trying to launch using Appium and the paths were set as follows,

    • ANDROID_HOME, User variable should be created in this name and the home directory of the ‘sdk package’ (C:\Users\Example\AppData\Local\Android\sdk) has to be set as value to this variable.
    • Path, Systems variables should be edited and the paths to the ‘tools’ (C:\Users\Example\AppData\Local\Android\sdk\tools) and ‘platform-tools’ (C:\Users\Example\AppData\Local\Android\sdk\platform-tools) have to appended to the existing value.

    Try above steps and for any further queries please attach the Detailed Appium log as opposed to screenshots for better solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shares