Smart Monkey: An Exploratory UI Traversal Method for Mobile App Testing
The article introduces Smart Monkey, an exploratory UI traversal technique that systematically interacts with every UI element of Android and iOS apps, records element histories, assigns weighted priorities, and employs state‑breakthrough and ignore mechanisms to improve stability, compatibility, security, and performance testing.
Traditional Android Monkey testing generates random or simple scripted UI events, which cannot guarantee coverage of all interface elements or assess test effectiveness. To address this, the UI traversal approach aims to operate each UI element at least once while monitoring system logs and internal behavior.
360QA's platform implements an exploratory UI traversal method called Smart Monkey, which works on both Android and iOS with a common computational model. The method provides a systematic way for researchers and testers to explore UI elements.
1. UI Element Structure – UI elements form a tree where each node has a single parent and zero or more children. The root represents the app window, with sub‑trees for views, lists, and list items. In both Android UIAutomator and iOS UIAutomation, each element corresponds to a class (e.g., UIAButton, UIATextField) that offers actions such as tap and scrollToVisible .
2. Element Identification – Each element receives a unique ID composed of its name, class name, and parent ID. The name is obtained via the element’s name method; IDs may be long and can be compressed without losing uniqueness.
3. History Record and Visit Counters – For every element a history record stores four parameters: visitTimes (how many times the element was visited), gCnt (number of generated child elements), preOperated (its leading element), and rCnt (how many of its generated elements have been visited). These counters help determine whether an element has been fully explored.
4. Element Weighting and Selection – Elements are assigned a weight based on rules such as: deeper generated layers have higher priority (weight = layer*C + tree‑level, with C=5), negative‑meaning elements rank lower than positive‑meaning ones, visible unvisited elements outrank invisible ones, and elements that trigger navigation (e.g., “Back”) receive intermediate priority. Randomization is applied among equally weighted navigation elements.
5. State Breakthrough – When no further actionable elements are found, the system performs a series of gestures (left swipe, center tap, right swipe, etc.) to break out of the current state and discover hidden UI paths.
6. Ignoring Mechanisms – To avoid endless loops, the algorithm can skip overly similar elements in large lists, ignore newly appearing elements after a window has been displayed a certain number of times, and filter out non‑reproducible or disabled elements based on historical differences.
7. Additional Key Points – Special handling for text fields and keyboards, login screen detection, dealing with non‑visible elements via scrolling methods, and criteria for terminating the traversal when state breakthroughs exceed a threshold.
The article concludes with flowcharts illustrating the Smart Monkey process and invites readers to follow the associated public account for further discussion.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
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.