A python library for supporting and customizing automated UI testing for mobile apps
Project description
About
Kea2 is an easy-to-use Python library for supporting, customizing and improving automated UI testing for mobile apps. Kea2's novelty is able to fuse the scripts (usually written by human) with automated UI testing tools, thus allowing many interesting and powerful features.
Kea2 is currently built on top of Fastbot and uiautomator2 and targets Android apps.
Important features
-
Feature 1(查找稳定性问题): coming with the full capability of Fastbot for stress testing and finding stability problems (i.e., crashing bugs);
-
Feature 2(自定义测试场景\事件序列\黑白名单\黑白控件[^1]): customizing testing scenarios when running Fastbot (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app states, blacklisting specific activities/UI widgets/UI regions) with the full capability and flexibility powered by python language and uiautomator2;
-
Feature 3(支持断言机制^2): supporting auto-assertions when running Fastbot, based on the idea of property-based testing inheritted from Kea, for finding logic bugs (i.e., non-crashing bugs)
The ability of the three features in Kea2
| Feature 1 | Feature 2 | Feature 3 | |
|---|---|---|---|
| Finding crashes | :+1: | :+1: | :+1: |
| Finding crashes in deep states | :+1: | :+1: | |
| Finding non-crashing functional (logic) bugs | :+1: |
Design & Roadmap
Kea2, released as a Python library, currently works with:
- unittest as the testing framework;
- uiautomator2 as the UI test driver;
- Fastbot as the backend automated UI testing tool.
In the future, Kea2 will be extended to support
- pytest
- Appium, Hypium (for HarmonyOS/Open Harmony)
- other automated UI testing tools (not limited to Fastbot)
Installation
Running environment:
- support Windows, MacOS and Linux
- python 3.8+, Android 5.0+ (Android SDK installed)
- VPN closed (Features 2 and 3 required)
Install Kea2 by pip:
python3 -m pip install kea2-python
Find Kea2's options by running
kea2 -h
Quick Test
Kea2 connects to and runs on Android devices. We recommend you to do a quick test to ensure that Kea2 is compatible with your devices.
-
Connect to a real Android device or an Android emulator (only one device is enough) and make sure you can see the connected device by running
adb devices. -
Run
quicktest.pyto test a sample appomninotes(released asomninotes.apkin Kea2's repository). The scriptquicktest.pywill automatically install and test this sample app for a short time.
Initialize Kea2 under your preferred working directory:
kea2 init
This step is always needed if it is your first time to run Kea2.
Run the quick test:
python3 quicktest.py
If you can see the app omninotes is successfully running and tested, Kea2 works!
Otherwise, please help file a bug report with the error message to us. Thank you!
Feature 1(运行基础版Fastbot:查找稳定性错误)
Test your app with the full capability of Fastbot for stress testing and finding stability problems (i.e., crashing bugs);
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
理解上述选项含义请查看文档
The usage is similar to the the original Fastbot's shell commands.
See more options by
kea2 run -h
Feature 2(运行增强版Fastbot:自定义测试场景\事件序列\黑白控件)
When running any automated UI testing tools like Fastbot to test your apps, you may find that some specifc UI pages or functionalities are difficult to reach or cover. The reason is that Fastbot lacks knowledge of your apps. Fortunately, this is the strength of script testing. In Feature 2, Kea2 can support writing small scripts to guide Fastbot to explore wherever we want. You can also use such small scripts to block specific widgets during UI testing.
In Kea2, a script is composed of two elements:
- Precondition: When to execute the script.
- Interaction scenario: The interaction logic (specified in the script's test method) to reach where we want.
Simple Example
Assuming Privacy is a hard-to-reach UI page during automated UI testing. Kea2 can easily guide Fastbot to reach this page.
@prob(0.5)
# precondition: when we are at the page `Home`
@precondition(lambda self:
self.d(text="Home").exists
)
def test_goToPrivacy(self):
"""
Guide Fastbot to the page `Privacy` by opening `Drawer`,
clicking the option `Setting` and clicking `Privacy`.
"""
self.d(description="Drawer").click()
self.d(text="Settings").click()
self.d(text="Privacy").click()
- By the decorator
@precondition, we specify the precondition --- when we are at theHomepage. In this case, theHomepage is the entry page of thePrivacypage and theHomepage can be easily reached by Fastbot. Thus, the script will be activated when we are atHomepage by checking whether a unique widgetHomeexists. - In script's test method
test_goToPrivacy, we specify the interaction logic (i.e., openingDrawer, clicking the optionSettingand clickingPrivacy) to guide Fastbot to reach thePrivacypage. - By the decorator
@prob, we specify the probability (50% in this example) to do the guidance when we are at theHomepage. As a result, Kea2 still allows Fastbot to explore other pages.
You can find the full example in script quicktest.py, and run this script with Fastbot by the command kea2 run:
# Launch Kea2 and load one single script quicktest.py.
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest discover -p quicktest.py
Feature 3(运行增强版Fastbot:加入自动断言)
Kea2 supports auto-assertions when running Fastbot for finding logic bugs (i.e., non-crashing bugs). To achieve this, you can add assertions in the scripts. When an assertion fails during automated UI testing, we find a likely functional bug.
In Feature 3, a script is composed of three elements:
- Precondition: When to execute the script.
- Interaction scenario: The interaction logic (specified in the script's test method).
- Assertion: The expected app behaviour.
Example
In a social media app, message sending is a common feature. On the message sending page, the send button should always appears when the input box is not empty (i.e., has some message).
The expected behavior (the upper figure) and the buggy behavior (the lower figure).
For the preceding always-holding property, we can write the following script to validate the functional correctness: when there is an input_box widget on the message sending page, we can type any non-empty string text into the input box and assert send_button should always exists.
@precondition(
lambda self: self.d(description="input_box").exists
)
def test_input_box(self):
from hypothesis.strategies import text, ascii_letters
random_str = text(alphabet=ascii_letters).example()
self.d(description="input_box").set_text(random_str)
assert self.d(description="send_button").exist
# we can even do more assertions, e.g.,
# the input string should exist on the message sending page
assert self.d(text=random_str).exist
We use hypothesis to generate random texts.
You can run this example by using the similar command line in Feature 2.
Documentations(更多文档)
更多文档,包括了:
- Kea2的案例教程(基于微信介绍)、
- Kea2脚本的定义方法,支持的脚本装饰器(如
@precondition、@prob、@max_tries)、 - Kea2的启动方式、命令行选项
- 查看/理解Kea2的运行结果(如界面截图、测试覆盖率、脚本执行成功与否)。
- 如何黑白控件/区域
Open-source projects used by Kea2
Relevant papers of Kea2
General and Practical Property-based Testing for Android Apps. ASE 2024. pdf
An Empirical Study of Functional Bugs in Android Apps. ISSTA 2023. pdf
Fastbot2: Reusable Automated Model-based GUI Testing for Android Enhanced by Reinforcement Learning. ASE 2022. pdf
Guided, Stochastic Model-Based GUI Testing of Android Apps. ESEC/FSE 2017. pdf
Maintainers/Contributors
Kea2 has been actively developed and maintained by the people in ecnusse:
- Xixian Liang (@XixianLiang)
- Bo Ma (@majuzi123)
- Chen Peng (@Drifterpc)
- Ting Su (@tingsu)
Zhendong Su, Yiheng Xiong, Xiangchen Shen, Mengqian Xu, Haiying Sun, Jingling Sun, Jue Wang have also been actively participated in this project and contributed a lot!
Kea2 has also received many valuable insights, advices, feedbacks and lessons shared by several industrial people from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu, Yuetang Deng), Huawei, Xiaomi and etc. Kudos!
[^1]: 不少UI自动化测试工具提供了“自定义事件序列”能力(如Fastbot 和AppCrawler),但在实际使用中存在不少问题,如自定义能力有限、使用不灵活等。此前不少Fastbot用户抱怨过其“自定义事件序列”在使用中的问题,如#209, #225, #286等。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kea2_python-0.1.2.tar.gz.
File metadata
- Download URL: kea2_python-0.1.2.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f024fdf7eeefe6a710c76886ccb9e70019ef181ef9a59c71e5bd3d456fa1886
|
|
| MD5 |
f2e24d0693dda5270e7ff6061ed98d58
|
|
| BLAKE2b-256 |
0c84836881014923ca243067593bb28fdfa25b2b258892669630d0877ba47136
|
Provenance
The following attestation bundles were made for kea2_python-0.1.2.tar.gz:
Publisher:
python-publish.yml on ecnusse/Kea2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kea2_python-0.1.2.tar.gz -
Subject digest:
4f024fdf7eeefe6a710c76886ccb9e70019ef181ef9a59c71e5bd3d456fa1886 - Sigstore transparency entry: 243090429
- Sigstore integration time:
-
Permalink:
ecnusse/Kea2@b9c21637ae8452b961a8cdde6b6ba3b9de65f8c5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ecnusse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b9c21637ae8452b961a8cdde6b6ba3b9de65f8c5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kea2_python-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kea2_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82236d4d09ae8eb8ef692d4de60d8d36484819f2214bd8e7ee137f30244df826
|
|
| MD5 |
948f0fa37965db7f6b81f77583e7af52
|
|
| BLAKE2b-256 |
dbc891113cb9f54e7aed3a5cd0466d4e13d340d2bac093863e06032eaf7a1c82
|
Provenance
The following attestation bundles were made for kea2_python-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on ecnusse/Kea2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kea2_python-0.1.2-py3-none-any.whl -
Subject digest:
82236d4d09ae8eb8ef692d4de60d8d36484819f2214bd8e7ee137f30244df826 - Sigstore transparency entry: 243090436
- Sigstore integration time:
-
Permalink:
ecnusse/Kea2@b9c21637ae8452b961a8cdde6b6ba3b9de65f8c5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ecnusse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b9c21637ae8452b961a8cdde6b6ba3b9de65f8c5 -
Trigger Event:
release
-
Statement type: