Mobile Development 11 min read

UI Automation Testing for Mobile Apps: Tools, Challenges, and Implementation

The article explains why UI automation is essential for mobile apps, compares tools such as UIAutomator, Robotium and Appium (chosen for its cross‑platform support), addresses challenges like backend instability by using Appmock‑based mock servers, adopts the Page Object pattern, and shows how the suite cut testing time from half a day to twenty minutes, delivering lasting efficiency gains.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
UI Automation Testing for Mobile Apps: Tools, Challenges, and Implementation

Automated testing is a crucial part of quality assurance for developers. A solid automation mechanism helps discover logical defects early, shifting risk forward. In fast‑iteration environments, manual regression of main business flows is time‑consuming and repetitive; integrating UI automation with these regressions improves code quality while saving manpower.

Why UI automation is needed:

Ensure quality – detect defects early.

Reduce repetitive work – large human effort is required for full‑flow regression.

Standardize – different developers have varying test‑case interpretations.

Challenges faced when adopting UI automation:

Choosing the right tool.

Minimizing backend dependency to avoid failures caused by unstable test environments.

Integrating test cases for reuse and lower maintenance cost.

Tool comparison:

UIAutomator

Robotium

Appium

Supported platforms

Android

Android, H5

Android, iOS, H5

Script language

Java

Java

Almost any

Source‑less testing

Yes

Yes

Yes

Supported API level

16+

All

All

Because Appium supports both Android and iOS and the team already had Appium experience, it was selected as the automation framework.

Interface stability and data variability: Business cases frequently request backend data, making test stability dependent on backend reliability. Two main difficulties arise:

Backend interface stability – test environments are not 24/7 stable; failures often require waiting for third‑party fixes.

Test data configuration – many scenarios (e.g., various discount configurations) require frequent data changes, which is labor‑intensive if done manually.

Introducing Appmock: Appmock is a mock tool from Meituan‑Dianping that can capture and mock network requests. By registering a specific HTTP link, tests can retrieve predefined mock data, greatly reducing backend failure risk.

To further automate data configuration, a custom mock‑server was built on top of Appmock using NodeJS. Mock data are stored in a database and exposed via APIs to switch data per test case. The architecture is illustrated in the original article.

Writing test cases with the Page Object pattern: This pattern abstracts each page as an object, encapsulating element locators and actions, which reduces code duplication, improves readability, and eases maintenance.

Example test class structure (setUp, tearDown, test methods):

@Before public void setUp() throws Exception {
    File apk = new File(APK_NOVA);
    DesiredCapabilities capabilities = DesiredCapabilities.android();
    capabilities.setCapability("device", Platform.ANDROID);
    capabilities.setCapability(CapabilityType.VERSION, "5.1");
    // ... other capabilities
    driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    splashScreen = new SplashScreen(driver);
    mainPage = new MainPage(driver);
    // Page Object initialization
}
@After public void tearDown() throws Exception {
    driver.quit();
}
@Test public void testQueueNormalQueue() {
    // test steps
}

Base page class example:

public class BasePage {
    private static final int TIMEOUT = 1; // short timeout
    private static final int TIMEOUT_LONG = 10; // long timeout
    public AndroidDriver<AndroidElement> driver;
    public WebDriverWait driverWait;
    public WebDriverWait driverLongWait;
    public BasePage(AndroidDriver<AndroidElement> driver) {
        this.driver = driver;
        this.driverWait = new WebDriverWait(this.driver, TIMEOUT);
        this.driverLongWait = new WebDriverWait(this.driver, TIMEOUT_LONG);
        PageFactory.initElements(this.driver, this);
    }
}

Page subclasses extend BasePage and use @FindBy annotations for element locating, e.g.:

@FindBy(id = "login_tip") private WebElement clickLoginButton;
@FindBy(xpath = "//*[contains(@resource-id, 'id/mapi_item')]//*[contains(@resource-id, 'id/debug_domain')]") private WebElement mapiDomainText;

Common utility methods in BaseUtils include openDebugPanel(), clickPoint(), swipeToUp()/swipeToDown(), prepareMockData(), saveScreenshot(), and various waitForElementXXX() helpers.

Test results: On two business lines (queue and flash‑discount), the full UI automation suite completed within 20 minutes, compared to half‑day manual testing, dramatically reducing labor cost and freeing engineers for higher‑value work.

Initial setup (environment, data preparation, test case authoring) requires upfront effort, but it is a one‑time investment that yields long‑term efficiency.

References: Appium documentation, Selenium Page Object design pattern.

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.

UI automationmobile testingAppiumMock ServerPage Object
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.