Mobile Development 18 min read

iOS UI Automation Testing with KIF and Continuous Integration

The Meituan‑Dianping team selected KIF for iOS UI automation because it leverages private APIs, integrates with XCTest, and matches their Objective‑C expertise, then built a testing bundle, wrote page‑object‑style KIF tests, and integrated them into Jenkins pipelines that handle simulator resets, keystroke delays, and multiple system alerts for reliable continuous integration.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
iOS UI Automation Testing with KIF and Continuous Integration

Client UI automation testing is a major focus for many testing teams. This article introduces the Meituan‑Dianping testing team’s practice of UI automation for the iOS client using KIF and its integration into a continuous‑integration pipeline.

Selection of Test Frameworks

iOS offers several UI automation solutions. Apple’s early UI Automation uses JavaScript and accessibility identifiers. Third‑party extensions include:

Extended UI Automation (e.g., TuneupJs, ynm3k) that adds JavaScript helper libraries.

Driver‑based UI Automation (e.g., iOSDriver, Appium) which communicates with the UI Automation library via TCP, allowing languages other than JavaScript.

Other categories are private‑API frameworks (e.g., KIF) and injection‑compiled frameworks (e.g., Frank, Calabash). Since Xcode 7, Apple also provides UI Testing based on XCTest.

The team compared five representative frameworks—UI Automation, Appium, KIF, Frank, and UI Testing—considering language familiarity, UI operation richness, and development efficiency. KIF was chosen because it leverages private APIs, integrates with XCTest, and fits the team’s existing Objective‑C/XCTest skill set.

KIF Automation Implementation

KIF uses accessibility attributes (accessibilityLabel, accessibilityIdentifier, etc.) to locate UI elements and runs within an XCTest target. The setup steps are:

Create a Cocoa Touch Testing Bundle target.

Configure Build Phases → Target Dependencies to depend on the app target.

Set Build Settings:

Bundle loader = $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp

Test Host = $(BUILT_PRODUCTS_DIR)

Wrapper Extensions = xctest

After adding the KIF source to the project, test cases are written by subclassing KIFTestCase. Example of a simple test case:

‑ (void)tapViewWithAccessibilityLabel:(NSString *)label;
‑ (UIView *)waitForViewWithAccessibilityLabel:(NSString *)label;

Accessibility attributes must be set on UI controls (e.g., setting a cell’s label to "Section 01 Row 01"). The Accessibility Inspector can verify the attributes.

Typical KIF test code (simplified):

#import "TimerTests.h"
#import "KIFUITestActor+AccessibilityLabelAddition.h"
#import "KIFUITestActor+IdentifierAdditions.h"
#import "KIFUITestActor+TimerAdditions.h"

@implementation TimerTests
‑ (void)beforeAll { [tester setDebugModel]; }
‑ (void)afterAll { [tester resetDebugModel]; [tester clearHistory]; }
‑ (void)beforeEach { [tester setDebugModel]; }
‑ (void)afterEach { [tester clearParams]; }
‑ (void)testNamedTask {
    [tester enterText:@"myTask" intoViewWithAccessibilityLabel:@"Task Name Input"];
    [tester enterWorktime:10 Breaktime:4 Repetitions:5];
    [tester tapViewWithAccessibilityLabel:@"Start Working"];
    [tester waitForViewWithAccessibilityLabel:@"myTask"];
    [tester waitForViewWithAccessibilityLabel:@"Start Working"];
}
@end

Test organization follows the Page Object pattern: element discovery and actions are abstracted into helper classes, while test cases focus on business logic. Lifecycle hooks such as beforeEach/afterEach and beforeAll/afterAll ensure independent and repeatable tests.

Continuous Integration (CI) with Jenkins

Jenkins runs the UI automation as a job. The job can be triggered by:

Build after another project.

Periodic (daily) builds.

SCM polling (e.g., on pull‑request).

The job uses command‑line tools like xcodebuild or xctool to build the app and execute KIF tests, generating JUnit XML reports and coverage data (via Cobertura). Jenkins plugins visualize test stability and code coverage.

Problems Encountered in CI

Device reset: Simulators were not fully reset, causing leftover app artifacts. The solution was to script a reset of all simulators before each run.

Keyboard keystroke delay: On slower machines, rapid keystrokes caused truncated input. The KIF source KIFTypist.m was patched to increase keystrokeDelay.

Multiple system alerts: Some apps present several alerts at launch. The KIF acknowledgeSystemAlert method was extended with a loop to handle an arbitrary number of alerts.

References include Apple’s UI Automation guide, Appium documentation, Frank, the KIF GitHub repository, Ray Wenderlich’s KIF tutorial, and articles on the Test Pyramid, CI, and related tools.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

iOSUI automationXCTestKIF
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.