Mobile Development 7 min read

Remote Control of Non‑Jailbroken iOS Devices Using XCUITest and WebDriverAgent

This article explains how to leverage Apple’s XCUITest framework, private XCUIApplication APIs, and Facebook’s WebDriverAgent to implement a web‑based service that remotely controls non‑jailbroken iOS devices for automated testing without requiring device rooting.

Baidu Intelligent Testing
Baidu Intelligent Testing
Baidu Intelligent Testing
Remote Control of Non‑Jailbroken iOS Devices Using XCUITest and WebDriverAgent

The author, a lead of Baidu’s MTC testing team, describes a solution that bridges the gap between iOS and Android testing by enabling remote control of iOS devices without jailbreak, using a combination of XCUITest, private APIs, and WebDriverAgent.

XCUITest is Apple’s UI testing framework introduced in Xcode 7 and fully replacing UIAutomation in Xcode 8. It simplifies UI test creation and can record user interactions to generate test code.

Creating a new UI test target generates a test case file similar to the following:

#import
@interface testUI : XCTestCase
@end
@implementation testUI
- (void)setUp {
    [super setUp];
    self.continueAfterFailure = NO;
    [[[XCUIApplication alloc] init] launch];
}
- (void)tearDown {
    [super tearDown];
}
- (void)testExample {
    // recording generated code goes here
}
@end

Developers can use Xcode’s record button to capture interactions, which are then compiled and deployed to a real device or simulator. The generated code can be edited manually to suit specific test scenarios.

When the test runs, Xcode launches a helper app (e.g., xcuitesdemoUITests ) on the device, which cannot be started directly but is invoked via the test runner. The helper app launches the target application and executes the recorded UI actions.

Beyond the public -launch and -terminate methods, the private XCUIApplication API exposes many additional functions, such as appWithPID: , _waitForQuiescence , and initPrivateWithPath:bundleID: . Using initPrivateWithPath:bundleID: , any installed app can be launched and controlled. For example, the following code starts Safari and navigates to a URL:

NSString *appBundleID = @"com.apple.mobilesafari";
XCUIApplication *app = [[XCUIApplication alloc] initPrivateWithPath:nil bundleID:appBundleID];
[app launch];
[app.otherElements[@"URL"] tap];
[app typeText:@"mtc.baidu.com\n"];

WebDriverAgent (https://github.com/facebook/WebDriverAgent) is an open‑source iOS automation framework built on top of XCUITest. It runs an HTTP server on the device, exposing APIs for launching apps, tapping, swiping, taking screenshots, and querying UI elements. Appium’s iOS driver relies on this component.

By combining XCUITest recording, private APIs, and WebDriverAgent, the author built a web service that periodically polls the device screen, translates mouse clicks and swipe gestures from a browser into XCUITest commands, and sends them to the device, achieving full remote control of a non‑jailbroken iOS device through a web interface.

iosautomationXCUITestWebDriverAgentRemoteControlMobileTesting
Baidu Intelligent Testing
Written by

Baidu Intelligent Testing

Welcome to follow.

0 followers
Reader feedback

How this landed with the community

login 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.