Building a Mobile Automated Testing Platform with Airtest and Poco
This article describes how a team built a custom automated testing platform for React Native mobile apps using Airtest and Poco, covering tool selection, script examples, platform architecture with React frontend and Python backend, and solutions for parallel execution and mock services.
The article discusses challenges in frontend automated testing for React Native mobile apps, such as UI fragility, cross‑device compatibility, and handling asynchronous interactions, and explains why a custom testing platform was needed.
After evaluating cross‑platform, stable, low‑maintenance tools, the team chose Airtest (image‑based UI automation) and Poco (control‑based recognition) for writing test scripts in Python via AirtestIDE.
An example test script for a fund‑purchase flow is shown, illustrating image‑based waits, Poco‑based text verification, and handling iOS/Android differences when retrieving UI text.
def fetchCycleCardStr(): poco = importPoco() currentCycleStr = '' if isIOS: obj = poco(nameMatches="定投周期") text1 = obj.get_name() pattern = re.compile('(?<=定投周期).*(?=· 下次扣款:)') res = pattern.search(text1) currentCycleStr = res.group().replace(',', '') else: obj = poco(text="定投周期") targetObj = obj.sibling()[0] text1 = targetObj.get_text() currentCycleStr = text1 return currentCycleStr
The platform architecture consists of a React frontend (Ant Design) for script selection and execution visualization, a Python‑Flask backend with MySQL for records, Redis + RQ for job queues, and Supervisor‑managed RQ workers to enable parallel execution on multiple devices.
# supervisord.conf [program:rqworker1] command=rq worker 设备1 -u redis://127.0.0.1:6379/0 directory=/Users/snowball/Desktop/AutoTest/FundTest autorestart=true [program:rqworker2] command=rq worker 设备2 -u redis://127.0.0.1:6379/0 directory=/Users/snowball/Desktop/AutoTest/FundTest autorestart=true
To reduce flakiness caused by network latency, the team added a Mock Server using Charles for mapping and Mockoon for defining mock responses, allowing tests to focus on client‑side logic.
Snowball Engineer Team
Proactivity, efficiency, professionalism, and empathy are the core values of the Snowball Engineer Team; curiosity, passion, and sharing of technology drive their continuous progress.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.