Mobile Development 12 min read

A Hands‑On Guide to UI Automation Using Airtest

This hands‑on guide explains how to set up the cross‑platform Airtest framework, connect Android or iOS devices, record and edit Python‑based UI scripts, use image‑and value‑based assertions, generate HTML reports, and leverage Poco for element‑level automation in agile mobile development.

DeWu Technology
DeWu Technology
DeWu Technology
A Hands‑On Guide to UI Automation Using Airtest

This article introduces the background and motivation for UI automation in agile mobile development, highlighting the need to reduce repetitive manual regression testing.

Airtest is presented as a cross‑platform UI automation framework based on image recognition, suitable for both games and mobile apps. Its companion framework Poco enables UI‑element search for Unity, Cocos2d, Android, iOS, WeChat mini‑programs, and H5 applications.

Key features of AirtestIDE include one‑click script recording, playback, report viewing, and support for Windows and macOS.

Device connection

For Android devices, connect via ADB: enable USB debugging, refresh ADB in AirtestIDE, and click the connect button. Example command line:

airtest run untitled.air --device Android:///YOUR_DEVICE_ID --log log

For iOS devices, a Mac with Xcode is required; refer to the official documentation for setup.

Recording scripts

After connecting a device, click the “Record” button in AirtestIDE. The tool generates Python code automatically. Simulated inputs such as touch , swipe , text , keyevent , wait , and snapshot are available.

Manual adjustments can be made by selecting precise UI elements or by editing the generated code.

Assertions

Airtest provides assert_exists / assert_not_exists for image‑based checks and assert_equal / assert_not_equal for value comparisons. Example:

assert_exists(Template("button.png"))

These assertions help verify UI state and numeric results.

Test report

After script execution, click “View Report” to open an HTML report showing step screenshots and execution results.

Script structure

An Airtest .air project contains a Python .py file. A typical script starts with:

from airtest.core.api import *

and initializes the environment with:

auto_setup(__file__)

Command‑line execution can be performed with:

airtest run test.air --device Android:///...

When running via Python directly, the same auto_setup call configures the environment.

Core APIs

The framework offers high‑level functions such as touch , swipe , text , keyevent , wait , and snapshot . Template objects enable image‑based targeting.

Overall, the guide demonstrates how to set up Airtest, connect devices, record and edit scripts, perform assertions, and review reports, providing a practical foundation for mobile UI automation.

pythonUI AutomationMobile TestingAirtestPOCOTest script
DeWu Technology
Written by

DeWu Technology

A platform for sharing and discussing tech knowledge, guiding you toward the cloud of technology.

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.