How Fastbot Uses Reinforcement Learning for Faster Android GUI Testing

Fastbot is a reusable, model‑based Android GUI testing tool that leverages reinforcement‑learning techniques to learn from previous test runs, accelerating coverage and crash detection through a two‑phase workflow, probabilistic and learning‑based event selection, and provides configurable custom events, widget blocking, and tree‑pruning features.

ByteDance SE Lab
ByteDance SE Lab
ByteDance SE Lab
How Fastbot Uses Reinforcement Learning for Faster Android GUI Testing

1. Problem Background

In recent years, the number of mobile applications has exploded, raising user expectations for app quality. Automated GUI testing has become a cost‑effective solution for maintaining quality, especially for industrial apps that receive weekly core updates. Traditional GUI testing tools simply replay tests without reusing knowledge from previous runs, leading to low efficiency. To address this, ByteDance Software Engineering Lab introduced Fastbot, a reusable, model‑based Android testing tool enhanced by reinforcement learning.

2. Workflow

Fastbot accepts an APK as input and outputs coverage reports and discovered crashes. Its workflow consists of two main phases:

(a) Pre‑test setup: a1 decompile the APK to collect static widget text; a2 install the APK on a set of devices; a3 load historical test data into the model.

(b) Guided UI exploration: b1 capture the current GUI page; b2 identify and abstract "hyper‑events" on the page; b3 select a UI event likely to increase activity coverage; b4 execute the event; b5 update historical data and the probability model; b6 update the reinforcement‑learning agent. These steps repeat until the time budget is exhausted.

3. Core Concepts

4. Technical and Algorithm Principles

Fastbot’s key idea is to use prior knowledge stored in a probability model to guide GUI testing. The crucial step is deciding which UI event to select on the current page to quickly increase activity coverage. Two strategies are combined:

4.1 Event Selection Based on Probability Model

If some hyper‑events on the current page are not yet in the model, Fastbot expands the model by randomly selecting an unseen hyper‑event. This handles cases where previous runs missed events or new features were added.

4.2 Event Selection Based on Reinforcement Learning

Probabilistic models provide only one‑step guidance, while reinforcement learning can extend guidance over multiple steps. Fastbot uses the SARSA N‑Step algorithm as a reward function to compute and update Q‑values.

4.3 Case Explanation

The following example uses the Toutiao app to illustrate decision making. By initializing the probability model M with historical data, Fastbot selects events based on their probabilities, updates the model after each execution, and adjusts Q‑values to favor deeper activity coverage.

When the model lacks certain events, Fastbot explores them randomly, updating probabilities as events are executed.

5. Design Implementation

Fastbot’s open‑source version consists of a client and a local server. The client, written in Java, captures GUI information, receives decisions from the server, and injects actions. The server, implemented in C/C++ as a shared library (.so) accessed via JNI, reads user preferences, learns the model, makes decisions, and returns JSON‑formatted actions.

Fastbot extends the Monkey framework. The Java layer adds a MonkeySourceApeNative class to receive events from the Fastbot algorithm, adapters for different Android versions, and wrappers for custom actions.

6. Common Configuration

6.1 Configuring Custom Events

Fastbot supports custom event sequences to cover scenarios the automatic explorer cannot reach. Users create a fixed‑name file max.xpath.actions and specify entries with fields such as prob, activity, times, and actions (including xpath, action, throttle, and optional text for input).

[
    {
        "prob":1,
        "activity":"com.amaze.filemanager.ui.activities.MainActivity",
        "times":1,
        "actions":[
            {"xpath":"//*[@content-desc='Navigate up']","action":"CLICK","throttle":2000},
            {"xpath":"//*[@resource-id='com.amaze.filemanager:id/design_menu_item_text' and @text='Recent files']","action":"CLICK","throttle":2000},
            {"xpath":"//*[@resource-id='com.amaze.filemanager:id/sd_main_fab']","action":"CLICK","throttle":2000},
            {"xpath":"//*[@resource-id='com.amaze.filemanager:id/menu_new_file']","action":"CLICK","throttle":2000}
        ]
    }
]

When events involve activity switches, separate objects are created for each activity.

[
    {
        "prob":1,
        "activity":"com.amaze.filemanager.ui.activities.MainActivity",
        "times":1,
        "actions":[
            {"xpath":"//*[@content-desc='Navigate up']","action":"CLICK","throttle":2000},
            {"xpath":"//*[@resource-id='com.amaze.filemanager:id/design_navigation_view']","action":"SCROLL_BOTTOM_UP","throttle":2000},
            {"xpath":"//*[@text='Settings' and @resource-id='com.amaze.filemanager:id/design_menu_item_text']","action":"CLICK","throttle":2000}
        ]
    },
    {
        "prob":1,
        "activity":"com.amaze.filemanager.ui.activities.PreferencesActivity",
        "times":1,
        "actions":[
            {"xpath":"//*[@resource-id='android:id/title' and @text='Appearance']","action":"CLICK","throttle":2000}
        ]
    }
]

6.2 Widget Blocking

Fastbot allows manual blocking of widgets or regions to prevent unwanted interactions. Blocking can be specified by bounds, xpath, or a combination of both.

Example of blocking specific widgets:

[
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","xpath":"//*[@content-desc='Navigate up']"},
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","xpath":"//*[@content-desc='More options']"}
]

Example of blocking a screen region:

[
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","bounds":"[0,18],[240,60]"}
]

Tree‑pruning blocking disables widgets by setting their enabled attribute to false in the GUI tree.

[
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","xpath":"//*[@content-desc='Navigate up']","enabled":"false"},
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","xpath":"//*[@content-desc='More options']","enabled":"false"},
    {"activity":"com.ss.android.ugc.aweme.main.MainActivity","xpath":"//*[@resource-id='com.amaze.filemanager:id/search'"}
]

7. More Information

Fastbot open‑source repository:

Fastbot user group (QR code):

For detailed technical insights, refer to the paper “Fastbot2: Reusable Automated Model‑based GUI Testing for Android Enhanced by Reinforcement Learning” presented at ASE 2022.

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.

reinforcement learningandroid testingmodel-based testingGUI automationfastbot
ByteDance SE Lab
Written by

ByteDance SE Lab

Official account of ByteDance SE Lab, sharing research and practical experience in software engineering. Our lab unites researchers and engineers from various domains to accelerate the fusion of software engineering and AI, driving technological progress in every phase of software development.

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.