Kea2-python 0.0.1a4__tar.gz → 0.0.1a6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Kea2-python might be problematic. Click here for more details.
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/PKG-INFO +91 -31
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/SOURCES.txt +1 -1
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/PKG-INFO +91 -31
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/README.md +90 -30
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/widget.block.py +1 -1
- kea2_python-0.0.1a4/kea2/assets/quickstart.py → kea2_python-0.0.1a6/kea2/assets/quicktest.py +1 -11
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/cli.py +12 -77
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/keaUtils.py +3 -2
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/pyproject.toml +1 -1
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/dependency_links.txt +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/entry_points.txt +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/requires.txt +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/Kea2_python.egg-info/top_level.txt +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/LICENSE +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/__init__.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/absDriver.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/adbUtils.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot-thirdpart.jar +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/ADBKeyBoard.apk +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/abl.strings +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/awl.strings +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/max.config +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/max.fuzzing.strings +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/max.schema.strings +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/max.strings +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_configs/max.tree.pruning +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/armeabi-v7a/libfastbot_native.so +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/x86/libfastbot_native.so +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/x86_64/libfastbot_native.so +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/framework.jar +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/monkeyq.jar +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/u2.jar +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/kea_launcher.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/logWatcher.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/u2Driver.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/utils.py +0 -0
- {kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Kea2-python
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.1a6
|
|
4
4
|
Summary: A python library for supporting and customizing automated UI testing for mobile apps
|
|
5
5
|
Author-email: Xixian Liang <xixian@stu.ecnu.edu.cn>
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -16,10 +16,10 @@ Kea2 is an easy-to-use Python library for supporting, customizing and improving
|
|
|
16
16
|
|
|
17
17
|
### Kea2 has three important features:
|
|
18
18
|
- **Feature 1**(查找稳定性问题): coming with the full capability of [Fastbot](https://github.com/bytedance/Fastbot_Android) for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
19
|
-
- **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) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
19
|
+
- **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 UI widgets) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
20
20
|
- **Feature 3**(支持断言机制[^2]): supporting auto-assertions when running Fastbot, based on the idea of [property-based testing](https://en.wikipedia.org/wiki/Software_testing#Property_testing) inheritted from [Kea](https://github.com/ecnusse/Kea), for finding *logic bugs* (i.e., *non-crashing bugs*)
|
|
21
21
|
|
|
22
|
-
These three features can be combined to customize and improve automated UI testing.
|
|
22
|
+
These three features can be combined to support, customize and improve automated UI testing.
|
|
23
23
|
|
|
24
24
|
<div align="center">
|
|
25
25
|
<div style="max-width:80%; max-height:80%">
|
|
@@ -46,7 +46,7 @@ In the future, Kea2 will be extended to support
|
|
|
46
46
|
- [Appium](https://github.com/appium/appium), [Hypium]() (for HarmonyOS)
|
|
47
47
|
- other automated UI testing tools (not limited to Fastbot)
|
|
48
48
|
|
|
49
|
-
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu), Huawei, Xiaomi and etc. Kudos!
|
|
49
|
+
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu, Yuetang Deng), Huawei, Xiaomi and etc. Kudos!
|
|
50
50
|
|
|
51
51
|
## Installation
|
|
52
52
|
|
|
@@ -56,24 +56,33 @@ Running requirements/environment:
|
|
|
56
56
|
- Android SDK installed
|
|
57
57
|
- **VPN closed** (Features 2 and 3 required)
|
|
58
58
|
|
|
59
|
+
|
|
60
|
+
Install Kea2 by `pip`:
|
|
59
61
|
```bash
|
|
60
62
|
python3 -m pip install Kea2-python
|
|
63
|
+
```
|
|
61
64
|
|
|
65
|
+
Find Kea2's additional options by running
|
|
66
|
+
```bash
|
|
62
67
|
kea2 -h
|
|
63
68
|
```
|
|
64
69
|
|
|
65
|
-
|
|
66
70
|
## Quick Test
|
|
67
71
|
|
|
68
72
|
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.
|
|
69
73
|
|
|
70
74
|
1. Connect to an Android device and make sure you can see the connected device by running `adb devices`.
|
|
71
75
|
|
|
72
|
-
2. Run `
|
|
76
|
+
2. Run `quicktest.py` to test a sample app `omninotes` (released as `omninotes.apk` in Kea2's repository). The script `quicktest.py` will automatically install and test this sample app for a short time.
|
|
73
77
|
|
|
78
|
+
Initialize Kea2 under your preferred working directory:
|
|
74
79
|
```python
|
|
75
80
|
kea2 init
|
|
76
|
-
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run the quick test:
|
|
84
|
+
```python
|
|
85
|
+
python3 quicktest.py
|
|
77
86
|
```
|
|
78
87
|
|
|
79
88
|
If you can see the app `omninotes` is successfully running and tested, Kea2 works. Otherwise, please help [file a bug report](https://github.com/ecnusse/Kea2/issues) with the error message to us. Thank you!
|
|
@@ -87,20 +96,23 @@ avdmanager create avd --force --name Android12 --package 'system-images;android-
|
|
|
87
96
|
emulator -avd Android12 -port 5554 &
|
|
88
97
|
```
|
|
89
98
|
|
|
90
|
-
> [
|
|
99
|
+
> [quicktest.py](https://github.com/ecnusse/Kea2/blob/main/kea2/assets/quicktest.py) is a dead simple script which is ready-to-go with Fastbot. You can customize this script for testing your own apps.
|
|
91
100
|
|
|
92
101
|
## Feature 1(查找稳定性问题): running Fastbot
|
|
93
102
|
|
|
94
|
-
Test your app with the full capability of
|
|
103
|
+
Test your app with the full capability of Fastbot for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
95
104
|
|
|
96
105
|
|
|
97
106
|
```bash
|
|
98
107
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
|
|
99
108
|
```
|
|
100
109
|
|
|
101
|
-
The usage is similar to the the original [
|
|
102
|
-
See more options by `kea2 run -h`
|
|
110
|
+
The usage is similar to the the original Fastbot's [shell commands](https://github.com/bytedance/Fastbot_Android?tab=readme-ov-file#run-fastbot-with-shell-command).
|
|
103
111
|
|
|
112
|
+
See more options by
|
|
113
|
+
```bash
|
|
114
|
+
kea2 run -h
|
|
115
|
+
```
|
|
104
116
|
|
|
105
117
|
## Feature 2(自定义测试场景或事件序列): customizing testing scenarios by scripts
|
|
106
118
|
|
|
@@ -116,13 +128,13 @@ When running any automated UI testing tools like Fastbot to test your apps, you
|
|
|
116
128
|
<img src="docs/stage2.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
117
129
|
</div>
|
|
118
130
|
|
|
119
|
-
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app
|
|
131
|
+
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app, blacklisting specific UI widgets) with the full capability and flexibility powered by `python` language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
120
132
|
|
|
121
133
|
In Kea2, a script is composed of two elements:
|
|
122
134
|
- **Precondition:** When to execute the script.
|
|
123
135
|
- **Interaction scenario:** The interaction logic (specified in the script's test method) to reach where we want.
|
|
124
136
|
|
|
125
|
-
### Example
|
|
137
|
+
### Example 1: reaching specific UI pages
|
|
126
138
|
|
|
127
139
|
Assuming `Privacy` is a hard-to-reach UI page during automated UI testing. Kea2 can easily guide Fastbot to reach this page.
|
|
128
140
|
|
|
@@ -147,17 +159,48 @@ In this case, the `Home` page is the entry page of the `Privacy` page and the `H
|
|
|
147
159
|
- In script's test method `test_goToPrivacy`, we specify the interaction logic (i.e., opening `Drawer`, clicking the option `Setting` and clicking `Privacy`) to guide Fastbot to reach the `Privacy` page.
|
|
148
160
|
- By the decorator `@prob`, we specify the probability (50% in this example) to do the guidance when we are at the `Home` page. As a result, Kea2 still allows Fastbot to explore other pages.
|
|
149
161
|
|
|
150
|
-
You can find the full example in script `
|
|
162
|
+
You can find the full example in script `quicktest.py`, and run this script with Fastbot by the command `kea2 run`:
|
|
151
163
|
|
|
152
|
-
```
|
|
153
|
-
|
|
164
|
+
```bash
|
|
165
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
166
|
+
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
|
|
154
167
|
```
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
### Example 2: blacklisting specific UI widgets
|
|
157
170
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
We support blacklisting specific widgets so that Fastbot can avoid interacting with these widgets during fuzzing. We support (1) `Global Block List` (always taking effective), and (2) `Conditional Block List` (only taking effective when some conditions are met).
|
|
172
|
+
|
|
173
|
+
The list of blocked widgets are specified in Kea2's config file `configs/widget.block.py` (generated when running `kea2 init`).
|
|
174
|
+
The widgets needed to be blocked can be flexibly specified by u2 selector (e.g., `text`, `description`) or `xpath`, etc.
|
|
175
|
+
|
|
176
|
+
#### Global Block List
|
|
177
|
+
We can define the function `global_block_widgets` to specify which UI widgets should be blocked globally. The blocking always takes effect.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# file: configs/widget.block.py
|
|
181
|
+
|
|
182
|
+
def global_block_widgets(d: "Device"):
|
|
183
|
+
"""
|
|
184
|
+
global block list.
|
|
185
|
+
return the widgets which should be blocked globally
|
|
186
|
+
"""
|
|
187
|
+
return [d(text="widgets to block"),
|
|
188
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
189
|
+
d(description="widgets to block")]
|
|
190
|
+
```
|
|
191
|
+
#### Conditional Block List
|
|
192
|
+
We can define any reserved function whose name starts with "block_" and decorate such function by `@precondition` to allow conditional block list.
|
|
193
|
+
In this case, the blocking only takes effect when the precondition is satisfied.
|
|
194
|
+
```python
|
|
195
|
+
# file: configs/widget.block.py
|
|
196
|
+
|
|
197
|
+
# conditional block list
|
|
198
|
+
@precondition(lambda d: d(text="In the home page").exists)
|
|
199
|
+
def block_sth(d: "Device"):
|
|
200
|
+
# Important: the function name should start with "block_"
|
|
201
|
+
return [d(text="widgets to block"),
|
|
202
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
203
|
+
d(description="widgets to block")]
|
|
161
204
|
```
|
|
162
205
|
|
|
163
206
|
## Feature 3(支持断言机制): Supporting auto-assertions by scripts.
|
|
@@ -205,9 +248,16 @@ For the preceding always-holding property, we can write the following script to
|
|
|
205
248
|
```
|
|
206
249
|
> We use [hypothesis](https://github.com/HypothesisWorks/hypothesis), a property-based testing library for Python, to generate random texts according to the given rules.
|
|
207
250
|
|
|
251
|
+
You can run this example by using the similar command line in Feature 2.
|
|
252
|
+
|
|
208
253
|
# Documentation
|
|
209
254
|
|
|
210
|
-
##
|
|
255
|
+
## Kea2's tutorials
|
|
256
|
+
|
|
257
|
+
1. A small tutorial of applying Kea2's Feature 2 and 3 on [WeChat](docs/Scenario_Examples_zh.md).
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
## Kea2's scripts
|
|
211
261
|
|
|
212
262
|
Kea2 uses [Unittest](https://docs.python.org/3/library/unittest.html) to manage scripts. All the Kea2's scripts can be found in unittest's rules (i.e., the test methods should start with `test_`, the test classes should extend `unittest.TestCase`).
|
|
213
263
|
|
|
@@ -246,8 +296,19 @@ class MyFirstTest(unittest.TestCase):
|
|
|
246
296
|
|
|
247
297
|
You can read [Kea - Write your fisrt property](https://kea-docs.readthedocs.io/en/latest/part-keaUserManuel/first_property.html) for more details.
|
|
248
298
|
|
|
299
|
+
### Notes
|
|
300
|
+
Currently, in `@precondition` decorator and `widgets.block.py`. We only support basic selector (No parent-child relationship) and basic xpath (No chain call like `.xpath().xpath()`) in uiautomator2. The Script body in the function fully support uiautomator2.
|
|
249
301
|
|
|
250
|
-
|
|
302
|
+
|
|
303
|
+
| | **Support** | **Not support** |
|
|
304
|
+
| -- | -- | -- |
|
|
305
|
+
| **Selctor** | `d(text="1").exist` | `d(text="1").child(text="2").exist` |
|
|
306
|
+
| **XPath** | `d.xpath(".//[@text='1']")` | `d.xpath(".//[@text='1']").xpath(".//[@text]='2'")` |
|
|
307
|
+
|
|
308
|
+
If you need to specify `parent-child` relation ship in `@precondition`, specify it in xpath.
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
## Launching Kea2
|
|
251
312
|
|
|
252
313
|
We offer two ways to launch Kea2.
|
|
253
314
|
|
|
@@ -263,8 +324,8 @@ kea2 run <Kea2 cmds> unittest <unittest cmds>
|
|
|
263
324
|
Sample shell commands:
|
|
264
325
|
|
|
265
326
|
```bash
|
|
266
|
-
# Launch Kea2 and load one single script
|
|
267
|
-
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest
|
|
327
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
328
|
+
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
|
|
268
329
|
|
|
269
330
|
# Launch Kea2 and load multiple scripts from the directory mytests/omni_notes
|
|
270
331
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest discover -s mytests/omni_notes
|
|
@@ -274,6 +335,7 @@ kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --runn
|
|
|
274
335
|
| --- | --- |
|
|
275
336
|
| -s | The serial of your device, which can be found by `adb devices` |
|
|
276
337
|
| -p | The tested app's package name (e.g., com.example.app) |
|
|
338
|
+
| -o | The ouput directory for logs and results |
|
|
277
339
|
| --agent | {native, u2}. By default, `u2` is used and supports all the three important features of Kea2. If you hope to run the orignal Fastbot, please use `native`.|
|
|
278
340
|
| --running-minutes | The time (m) to run Kea2 |
|
|
279
341
|
| --max-step | The maxium number of monkey events to send (only available in `--agent u2`) |
|
|
@@ -339,9 +401,10 @@ maxStep: int # default "inf"
|
|
|
339
401
|
running_mins: int = 10
|
|
340
402
|
# time(ms) to wait when exploring the app
|
|
341
403
|
throttle: int = 200
|
|
404
|
+
# the output_dir for saving logs and results
|
|
405
|
+
output_dir: str = "output"
|
|
342
406
|
```
|
|
343
407
|
|
|
344
|
-
|
|
345
408
|
## Examining the running statistics of scripts .
|
|
346
409
|
|
|
347
410
|
If you want to examine whether your scripts have been executed or how many times they have been executed during testing. Open the file `result.json` after the testing is finished.
|
|
@@ -369,13 +432,10 @@ executed | During UI testing, how many times the test method has been executed?
|
|
|
369
432
|
fail | How many times did the test method fail the assertions during UI testing? | When failed, the test method found a likely functional bug.
|
|
370
433
|
error | How many times does the test method abort during UI tsting due to some unexpected errors (e.g. some UI widgets used in the test method cannot be found) | When some error happens, the script needs to be updated/fixed because the script leads to some unexpected errors.
|
|
371
434
|
|
|
372
|
-
|
|
435
|
+
## Configuration File
|
|
373
436
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
python3 -m pip install --upgrade pip
|
|
377
|
-
python3 -m pip install .
|
|
378
|
-
```
|
|
437
|
+
After executing `Kea2 init`, some configuration files will be generated in the `configs` directory.
|
|
438
|
+
These configuration files belong to `Fastbot`, and their specific introductions are provided in [Introduction to configuration files](https://github.com/bytedance/Fastbot_Android/blob/main/handbook-cn.md#%E4%B8%93%E5%AE%B6%E7%B3%BB%E7%BB%9F).
|
|
379
439
|
|
|
380
440
|
## Contributors/Maintainers
|
|
381
441
|
|
|
@@ -19,7 +19,7 @@ kea2/utils.py
|
|
|
19
19
|
kea2/assets/fastbot-thirdpart.jar
|
|
20
20
|
kea2/assets/framework.jar
|
|
21
21
|
kea2/assets/monkeyq.jar
|
|
22
|
-
kea2/assets/
|
|
22
|
+
kea2/assets/quicktest.py
|
|
23
23
|
kea2/assets/u2.jar
|
|
24
24
|
kea2/assets/fastbot_configs/ADBKeyBoard.apk
|
|
25
25
|
kea2/assets/fastbot_configs/abl.strings
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Kea2-python
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.1a6
|
|
4
4
|
Summary: A python library for supporting and customizing automated UI testing for mobile apps
|
|
5
5
|
Author-email: Xixian Liang <xixian@stu.ecnu.edu.cn>
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -16,10 +16,10 @@ Kea2 is an easy-to-use Python library for supporting, customizing and improving
|
|
|
16
16
|
|
|
17
17
|
### Kea2 has three important features:
|
|
18
18
|
- **Feature 1**(查找稳定性问题): coming with the full capability of [Fastbot](https://github.com/bytedance/Fastbot_Android) for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
19
|
-
- **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) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
19
|
+
- **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 UI widgets) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
20
20
|
- **Feature 3**(支持断言机制[^2]): supporting auto-assertions when running Fastbot, based on the idea of [property-based testing](https://en.wikipedia.org/wiki/Software_testing#Property_testing) inheritted from [Kea](https://github.com/ecnusse/Kea), for finding *logic bugs* (i.e., *non-crashing bugs*)
|
|
21
21
|
|
|
22
|
-
These three features can be combined to customize and improve automated UI testing.
|
|
22
|
+
These three features can be combined to support, customize and improve automated UI testing.
|
|
23
23
|
|
|
24
24
|
<div align="center">
|
|
25
25
|
<div style="max-width:80%; max-height:80%">
|
|
@@ -46,7 +46,7 @@ In the future, Kea2 will be extended to support
|
|
|
46
46
|
- [Appium](https://github.com/appium/appium), [Hypium]() (for HarmonyOS)
|
|
47
47
|
- other automated UI testing tools (not limited to Fastbot)
|
|
48
48
|
|
|
49
|
-
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu), Huawei, Xiaomi and etc. Kudos!
|
|
49
|
+
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu, Yuetang Deng), Huawei, Xiaomi and etc. Kudos!
|
|
50
50
|
|
|
51
51
|
## Installation
|
|
52
52
|
|
|
@@ -56,24 +56,33 @@ Running requirements/environment:
|
|
|
56
56
|
- Android SDK installed
|
|
57
57
|
- **VPN closed** (Features 2 and 3 required)
|
|
58
58
|
|
|
59
|
+
|
|
60
|
+
Install Kea2 by `pip`:
|
|
59
61
|
```bash
|
|
60
62
|
python3 -m pip install Kea2-python
|
|
63
|
+
```
|
|
61
64
|
|
|
65
|
+
Find Kea2's additional options by running
|
|
66
|
+
```bash
|
|
62
67
|
kea2 -h
|
|
63
68
|
```
|
|
64
69
|
|
|
65
|
-
|
|
66
70
|
## Quick Test
|
|
67
71
|
|
|
68
72
|
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.
|
|
69
73
|
|
|
70
74
|
1. Connect to an Android device and make sure you can see the connected device by running `adb devices`.
|
|
71
75
|
|
|
72
|
-
2. Run `
|
|
76
|
+
2. Run `quicktest.py` to test a sample app `omninotes` (released as `omninotes.apk` in Kea2's repository). The script `quicktest.py` will automatically install and test this sample app for a short time.
|
|
73
77
|
|
|
78
|
+
Initialize Kea2 under your preferred working directory:
|
|
74
79
|
```python
|
|
75
80
|
kea2 init
|
|
76
|
-
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run the quick test:
|
|
84
|
+
```python
|
|
85
|
+
python3 quicktest.py
|
|
77
86
|
```
|
|
78
87
|
|
|
79
88
|
If you can see the app `omninotes` is successfully running and tested, Kea2 works. Otherwise, please help [file a bug report](https://github.com/ecnusse/Kea2/issues) with the error message to us. Thank you!
|
|
@@ -87,20 +96,23 @@ avdmanager create avd --force --name Android12 --package 'system-images;android-
|
|
|
87
96
|
emulator -avd Android12 -port 5554 &
|
|
88
97
|
```
|
|
89
98
|
|
|
90
|
-
> [
|
|
99
|
+
> [quicktest.py](https://github.com/ecnusse/Kea2/blob/main/kea2/assets/quicktest.py) is a dead simple script which is ready-to-go with Fastbot. You can customize this script for testing your own apps.
|
|
91
100
|
|
|
92
101
|
## Feature 1(查找稳定性问题): running Fastbot
|
|
93
102
|
|
|
94
|
-
Test your app with the full capability of
|
|
103
|
+
Test your app with the full capability of Fastbot for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
95
104
|
|
|
96
105
|
|
|
97
106
|
```bash
|
|
98
107
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
|
|
99
108
|
```
|
|
100
109
|
|
|
101
|
-
The usage is similar to the the original [
|
|
102
|
-
See more options by `kea2 run -h`
|
|
110
|
+
The usage is similar to the the original Fastbot's [shell commands](https://github.com/bytedance/Fastbot_Android?tab=readme-ov-file#run-fastbot-with-shell-command).
|
|
103
111
|
|
|
112
|
+
See more options by
|
|
113
|
+
```bash
|
|
114
|
+
kea2 run -h
|
|
115
|
+
```
|
|
104
116
|
|
|
105
117
|
## Feature 2(自定义测试场景或事件序列): customizing testing scenarios by scripts
|
|
106
118
|
|
|
@@ -116,13 +128,13 @@ When running any automated UI testing tools like Fastbot to test your apps, you
|
|
|
116
128
|
<img src="docs/stage2.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
117
129
|
</div>
|
|
118
130
|
|
|
119
|
-
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app
|
|
131
|
+
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app, blacklisting specific UI widgets) with the full capability and flexibility powered by `python` language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
120
132
|
|
|
121
133
|
In Kea2, a script is composed of two elements:
|
|
122
134
|
- **Precondition:** When to execute the script.
|
|
123
135
|
- **Interaction scenario:** The interaction logic (specified in the script's test method) to reach where we want.
|
|
124
136
|
|
|
125
|
-
### Example
|
|
137
|
+
### Example 1: reaching specific UI pages
|
|
126
138
|
|
|
127
139
|
Assuming `Privacy` is a hard-to-reach UI page during automated UI testing. Kea2 can easily guide Fastbot to reach this page.
|
|
128
140
|
|
|
@@ -147,17 +159,48 @@ In this case, the `Home` page is the entry page of the `Privacy` page and the `H
|
|
|
147
159
|
- In script's test method `test_goToPrivacy`, we specify the interaction logic (i.e., opening `Drawer`, clicking the option `Setting` and clicking `Privacy`) to guide Fastbot to reach the `Privacy` page.
|
|
148
160
|
- By the decorator `@prob`, we specify the probability (50% in this example) to do the guidance when we are at the `Home` page. As a result, Kea2 still allows Fastbot to explore other pages.
|
|
149
161
|
|
|
150
|
-
You can find the full example in script `
|
|
162
|
+
You can find the full example in script `quicktest.py`, and run this script with Fastbot by the command `kea2 run`:
|
|
151
163
|
|
|
152
|
-
```
|
|
153
|
-
|
|
164
|
+
```bash
|
|
165
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
166
|
+
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
|
|
154
167
|
```
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
### Example 2: blacklisting specific UI widgets
|
|
157
170
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
We support blacklisting specific widgets so that Fastbot can avoid interacting with these widgets during fuzzing. We support (1) `Global Block List` (always taking effective), and (2) `Conditional Block List` (only taking effective when some conditions are met).
|
|
172
|
+
|
|
173
|
+
The list of blocked widgets are specified in Kea2's config file `configs/widget.block.py` (generated when running `kea2 init`).
|
|
174
|
+
The widgets needed to be blocked can be flexibly specified by u2 selector (e.g., `text`, `description`) or `xpath`, etc.
|
|
175
|
+
|
|
176
|
+
#### Global Block List
|
|
177
|
+
We can define the function `global_block_widgets` to specify which UI widgets should be blocked globally. The blocking always takes effect.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# file: configs/widget.block.py
|
|
181
|
+
|
|
182
|
+
def global_block_widgets(d: "Device"):
|
|
183
|
+
"""
|
|
184
|
+
global block list.
|
|
185
|
+
return the widgets which should be blocked globally
|
|
186
|
+
"""
|
|
187
|
+
return [d(text="widgets to block"),
|
|
188
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
189
|
+
d(description="widgets to block")]
|
|
190
|
+
```
|
|
191
|
+
#### Conditional Block List
|
|
192
|
+
We can define any reserved function whose name starts with "block_" and decorate such function by `@precondition` to allow conditional block list.
|
|
193
|
+
In this case, the blocking only takes effect when the precondition is satisfied.
|
|
194
|
+
```python
|
|
195
|
+
# file: configs/widget.block.py
|
|
196
|
+
|
|
197
|
+
# conditional block list
|
|
198
|
+
@precondition(lambda d: d(text="In the home page").exists)
|
|
199
|
+
def block_sth(d: "Device"):
|
|
200
|
+
# Important: the function name should start with "block_"
|
|
201
|
+
return [d(text="widgets to block"),
|
|
202
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
203
|
+
d(description="widgets to block")]
|
|
161
204
|
```
|
|
162
205
|
|
|
163
206
|
## Feature 3(支持断言机制): Supporting auto-assertions by scripts.
|
|
@@ -205,9 +248,16 @@ For the preceding always-holding property, we can write the following script to
|
|
|
205
248
|
```
|
|
206
249
|
> We use [hypothesis](https://github.com/HypothesisWorks/hypothesis), a property-based testing library for Python, to generate random texts according to the given rules.
|
|
207
250
|
|
|
251
|
+
You can run this example by using the similar command line in Feature 2.
|
|
252
|
+
|
|
208
253
|
# Documentation
|
|
209
254
|
|
|
210
|
-
##
|
|
255
|
+
## Kea2's tutorials
|
|
256
|
+
|
|
257
|
+
1. A small tutorial of applying Kea2's Feature 2 and 3 on [WeChat](docs/Scenario_Examples_zh.md).
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
## Kea2's scripts
|
|
211
261
|
|
|
212
262
|
Kea2 uses [Unittest](https://docs.python.org/3/library/unittest.html) to manage scripts. All the Kea2's scripts can be found in unittest's rules (i.e., the test methods should start with `test_`, the test classes should extend `unittest.TestCase`).
|
|
213
263
|
|
|
@@ -246,8 +296,19 @@ class MyFirstTest(unittest.TestCase):
|
|
|
246
296
|
|
|
247
297
|
You can read [Kea - Write your fisrt property](https://kea-docs.readthedocs.io/en/latest/part-keaUserManuel/first_property.html) for more details.
|
|
248
298
|
|
|
299
|
+
### Notes
|
|
300
|
+
Currently, in `@precondition` decorator and `widgets.block.py`. We only support basic selector (No parent-child relationship) and basic xpath (No chain call like `.xpath().xpath()`) in uiautomator2. The Script body in the function fully support uiautomator2.
|
|
249
301
|
|
|
250
|
-
|
|
302
|
+
|
|
303
|
+
| | **Support** | **Not support** |
|
|
304
|
+
| -- | -- | -- |
|
|
305
|
+
| **Selctor** | `d(text="1").exist` | `d(text="1").child(text="2").exist` |
|
|
306
|
+
| **XPath** | `d.xpath(".//[@text='1']")` | `d.xpath(".//[@text='1']").xpath(".//[@text]='2'")` |
|
|
307
|
+
|
|
308
|
+
If you need to specify `parent-child` relation ship in `@precondition`, specify it in xpath.
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
## Launching Kea2
|
|
251
312
|
|
|
252
313
|
We offer two ways to launch Kea2.
|
|
253
314
|
|
|
@@ -263,8 +324,8 @@ kea2 run <Kea2 cmds> unittest <unittest cmds>
|
|
|
263
324
|
Sample shell commands:
|
|
264
325
|
|
|
265
326
|
```bash
|
|
266
|
-
# Launch Kea2 and load one single script
|
|
267
|
-
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest
|
|
327
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
328
|
+
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
|
|
268
329
|
|
|
269
330
|
# Launch Kea2 and load multiple scripts from the directory mytests/omni_notes
|
|
270
331
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest discover -s mytests/omni_notes
|
|
@@ -274,6 +335,7 @@ kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --runn
|
|
|
274
335
|
| --- | --- |
|
|
275
336
|
| -s | The serial of your device, which can be found by `adb devices` |
|
|
276
337
|
| -p | The tested app's package name (e.g., com.example.app) |
|
|
338
|
+
| -o | The ouput directory for logs and results |
|
|
277
339
|
| --agent | {native, u2}. By default, `u2` is used and supports all the three important features of Kea2. If you hope to run the orignal Fastbot, please use `native`.|
|
|
278
340
|
| --running-minutes | The time (m) to run Kea2 |
|
|
279
341
|
| --max-step | The maxium number of monkey events to send (only available in `--agent u2`) |
|
|
@@ -339,9 +401,10 @@ maxStep: int # default "inf"
|
|
|
339
401
|
running_mins: int = 10
|
|
340
402
|
# time(ms) to wait when exploring the app
|
|
341
403
|
throttle: int = 200
|
|
404
|
+
# the output_dir for saving logs and results
|
|
405
|
+
output_dir: str = "output"
|
|
342
406
|
```
|
|
343
407
|
|
|
344
|
-
|
|
345
408
|
## Examining the running statistics of scripts .
|
|
346
409
|
|
|
347
410
|
If you want to examine whether your scripts have been executed or how many times they have been executed during testing. Open the file `result.json` after the testing is finished.
|
|
@@ -369,13 +432,10 @@ executed | During UI testing, how many times the test method has been executed?
|
|
|
369
432
|
fail | How many times did the test method fail the assertions during UI testing? | When failed, the test method found a likely functional bug.
|
|
370
433
|
error | How many times does the test method abort during UI tsting due to some unexpected errors (e.g. some UI widgets used in the test method cannot be found) | When some error happens, the script needs to be updated/fixed because the script leads to some unexpected errors.
|
|
371
434
|
|
|
372
|
-
|
|
435
|
+
## Configuration File
|
|
373
436
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
python3 -m pip install --upgrade pip
|
|
377
|
-
python3 -m pip install .
|
|
378
|
-
```
|
|
437
|
+
After executing `Kea2 init`, some configuration files will be generated in the `configs` directory.
|
|
438
|
+
These configuration files belong to `Fastbot`, and their specific introductions are provided in [Introduction to configuration files](https://github.com/bytedance/Fastbot_Android/blob/main/handbook-cn.md#%E4%B8%93%E5%AE%B6%E7%B3%BB%E7%BB%9F).
|
|
379
439
|
|
|
380
440
|
## Contributors/Maintainers
|
|
381
441
|
|
|
@@ -4,10 +4,10 @@ Kea2 is an easy-to-use Python library for supporting, customizing and improving
|
|
|
4
4
|
|
|
5
5
|
### Kea2 has three important features:
|
|
6
6
|
- **Feature 1**(查找稳定性问题): coming with the full capability of [Fastbot](https://github.com/bytedance/Fastbot_Android) for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
7
|
-
- **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) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
7
|
+
- **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 UI widgets) with the full capability and flexibility powered by *python* language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
8
8
|
- **Feature 3**(支持断言机制[^2]): supporting auto-assertions when running Fastbot, based on the idea of [property-based testing](https://en.wikipedia.org/wiki/Software_testing#Property_testing) inheritted from [Kea](https://github.com/ecnusse/Kea), for finding *logic bugs* (i.e., *non-crashing bugs*)
|
|
9
9
|
|
|
10
|
-
These three features can be combined to customize and improve automated UI testing.
|
|
10
|
+
These three features can be combined to support, customize and improve automated UI testing.
|
|
11
11
|
|
|
12
12
|
<div align="center">
|
|
13
13
|
<div style="max-width:80%; max-height:80%">
|
|
@@ -34,7 +34,7 @@ In the future, Kea2 will be extended to support
|
|
|
34
34
|
- [Appium](https://github.com/appium/appium), [Hypium]() (for HarmonyOS)
|
|
35
35
|
- other automated UI testing tools (not limited to Fastbot)
|
|
36
36
|
|
|
37
|
-
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu), Huawei, Xiaomi and etc. Kudos!
|
|
37
|
+
> Kea2 is inspired by many valuable insights, advices and lessons shared by experienced industrial practitioners from Bytedance (Zhao Zhang, Yuhui Su from the Fastbot team), OPay (Tiesong Liu), WeChat (Haochuan Lu, Yuetang Deng), Huawei, Xiaomi and etc. Kudos!
|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
@@ -44,24 +44,33 @@ Running requirements/environment:
|
|
|
44
44
|
- Android SDK installed
|
|
45
45
|
- **VPN closed** (Features 2 and 3 required)
|
|
46
46
|
|
|
47
|
+
|
|
48
|
+
Install Kea2 by `pip`:
|
|
47
49
|
```bash
|
|
48
50
|
python3 -m pip install Kea2-python
|
|
51
|
+
```
|
|
49
52
|
|
|
53
|
+
Find Kea2's additional options by running
|
|
54
|
+
```bash
|
|
50
55
|
kea2 -h
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
|
|
54
58
|
## Quick Test
|
|
55
59
|
|
|
56
60
|
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.
|
|
57
61
|
|
|
58
62
|
1. Connect to an Android device and make sure you can see the connected device by running `adb devices`.
|
|
59
63
|
|
|
60
|
-
2. Run `
|
|
64
|
+
2. Run `quicktest.py` to test a sample app `omninotes` (released as `omninotes.apk` in Kea2's repository). The script `quicktest.py` will automatically install and test this sample app for a short time.
|
|
61
65
|
|
|
66
|
+
Initialize Kea2 under your preferred working directory:
|
|
62
67
|
```python
|
|
63
68
|
kea2 init
|
|
64
|
-
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Run the quick test:
|
|
72
|
+
```python
|
|
73
|
+
python3 quicktest.py
|
|
65
74
|
```
|
|
66
75
|
|
|
67
76
|
If you can see the app `omninotes` is successfully running and tested, Kea2 works. Otherwise, please help [file a bug report](https://github.com/ecnusse/Kea2/issues) with the error message to us. Thank you!
|
|
@@ -75,20 +84,23 @@ avdmanager create avd --force --name Android12 --package 'system-images;android-
|
|
|
75
84
|
emulator -avd Android12 -port 5554 &
|
|
76
85
|
```
|
|
77
86
|
|
|
78
|
-
> [
|
|
87
|
+
> [quicktest.py](https://github.com/ecnusse/Kea2/blob/main/kea2/assets/quicktest.py) is a dead simple script which is ready-to-go with Fastbot. You can customize this script for testing your own apps.
|
|
79
88
|
|
|
80
89
|
## Feature 1(查找稳定性问题): running Fastbot
|
|
81
90
|
|
|
82
|
-
Test your app with the full capability of
|
|
91
|
+
Test your app with the full capability of Fastbot for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
83
92
|
|
|
84
93
|
|
|
85
94
|
```bash
|
|
86
95
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
|
|
87
96
|
```
|
|
88
97
|
|
|
89
|
-
The usage is similar to the the original [
|
|
90
|
-
See more options by `kea2 run -h`
|
|
98
|
+
The usage is similar to the the original Fastbot's [shell commands](https://github.com/bytedance/Fastbot_Android?tab=readme-ov-file#run-fastbot-with-shell-command).
|
|
91
99
|
|
|
100
|
+
See more options by
|
|
101
|
+
```bash
|
|
102
|
+
kea2 run -h
|
|
103
|
+
```
|
|
92
104
|
|
|
93
105
|
## Feature 2(自定义测试场景或事件序列): customizing testing scenarios by scripts
|
|
94
106
|
|
|
@@ -104,13 +116,13 @@ When running any automated UI testing tools like Fastbot to test your apps, you
|
|
|
104
116
|
<img src="docs/stage2.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
105
117
|
</div>
|
|
106
118
|
|
|
107
|
-
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app
|
|
119
|
+
Kea2 can support you to test your app by customizing testing scenarios (e.g., testing specific app functionalities, executing specific event traces, entering specifc UI pages, reaching specific app, blacklisting specific UI widgets) with the full capability and flexibility powered by `python` language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
108
120
|
|
|
109
121
|
In Kea2, a script is composed of two elements:
|
|
110
122
|
- **Precondition:** When to execute the script.
|
|
111
123
|
- **Interaction scenario:** The interaction logic (specified in the script's test method) to reach where we want.
|
|
112
124
|
|
|
113
|
-
### Example
|
|
125
|
+
### Example 1: reaching specific UI pages
|
|
114
126
|
|
|
115
127
|
Assuming `Privacy` is a hard-to-reach UI page during automated UI testing. Kea2 can easily guide Fastbot to reach this page.
|
|
116
128
|
|
|
@@ -135,17 +147,48 @@ In this case, the `Home` page is the entry page of the `Privacy` page and the `H
|
|
|
135
147
|
- In script's test method `test_goToPrivacy`, we specify the interaction logic (i.e., opening `Drawer`, clicking the option `Setting` and clicking `Privacy`) to guide Fastbot to reach the `Privacy` page.
|
|
136
148
|
- By the decorator `@prob`, we specify the probability (50% in this example) to do the guidance when we are at the `Home` page. As a result, Kea2 still allows Fastbot to explore other pages.
|
|
137
149
|
|
|
138
|
-
You can find the full example in script `
|
|
150
|
+
You can find the full example in script `quicktest.py`, and run this script with Fastbot by the command `kea2 run`:
|
|
139
151
|
|
|
140
|
-
```
|
|
141
|
-
|
|
152
|
+
```bash
|
|
153
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
154
|
+
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
|
|
142
155
|
```
|
|
143
156
|
|
|
144
|
-
|
|
157
|
+
### Example 2: blacklisting specific UI widgets
|
|
145
158
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
159
|
+
We support blacklisting specific widgets so that Fastbot can avoid interacting with these widgets during fuzzing. We support (1) `Global Block List` (always taking effective), and (2) `Conditional Block List` (only taking effective when some conditions are met).
|
|
160
|
+
|
|
161
|
+
The list of blocked widgets are specified in Kea2's config file `configs/widget.block.py` (generated when running `kea2 init`).
|
|
162
|
+
The widgets needed to be blocked can be flexibly specified by u2 selector (e.g., `text`, `description`) or `xpath`, etc.
|
|
163
|
+
|
|
164
|
+
#### Global Block List
|
|
165
|
+
We can define the function `global_block_widgets` to specify which UI widgets should be blocked globally. The blocking always takes effect.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# file: configs/widget.block.py
|
|
169
|
+
|
|
170
|
+
def global_block_widgets(d: "Device"):
|
|
171
|
+
"""
|
|
172
|
+
global block list.
|
|
173
|
+
return the widgets which should be blocked globally
|
|
174
|
+
"""
|
|
175
|
+
return [d(text="widgets to block"),
|
|
176
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
177
|
+
d(description="widgets to block")]
|
|
178
|
+
```
|
|
179
|
+
#### Conditional Block List
|
|
180
|
+
We can define any reserved function whose name starts with "block_" and decorate such function by `@precondition` to allow conditional block list.
|
|
181
|
+
In this case, the blocking only takes effect when the precondition is satisfied.
|
|
182
|
+
```python
|
|
183
|
+
# file: configs/widget.block.py
|
|
184
|
+
|
|
185
|
+
# conditional block list
|
|
186
|
+
@precondition(lambda d: d(text="In the home page").exists)
|
|
187
|
+
def block_sth(d: "Device"):
|
|
188
|
+
# Important: the function name should start with "block_"
|
|
189
|
+
return [d(text="widgets to block"),
|
|
190
|
+
d.xpath(".//node[@text='widget to block']"),
|
|
191
|
+
d(description="widgets to block")]
|
|
149
192
|
```
|
|
150
193
|
|
|
151
194
|
## Feature 3(支持断言机制): Supporting auto-assertions by scripts.
|
|
@@ -193,9 +236,16 @@ For the preceding always-holding property, we can write the following script to
|
|
|
193
236
|
```
|
|
194
237
|
> We use [hypothesis](https://github.com/HypothesisWorks/hypothesis), a property-based testing library for Python, to generate random texts according to the given rules.
|
|
195
238
|
|
|
239
|
+
You can run this example by using the similar command line in Feature 2.
|
|
240
|
+
|
|
196
241
|
# Documentation
|
|
197
242
|
|
|
198
|
-
##
|
|
243
|
+
## Kea2's tutorials
|
|
244
|
+
|
|
245
|
+
1. A small tutorial of applying Kea2's Feature 2 and 3 on [WeChat](docs/Scenario_Examples_zh.md).
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## Kea2's scripts
|
|
199
249
|
|
|
200
250
|
Kea2 uses [Unittest](https://docs.python.org/3/library/unittest.html) to manage scripts. All the Kea2's scripts can be found in unittest's rules (i.e., the test methods should start with `test_`, the test classes should extend `unittest.TestCase`).
|
|
201
251
|
|
|
@@ -234,8 +284,19 @@ class MyFirstTest(unittest.TestCase):
|
|
|
234
284
|
|
|
235
285
|
You can read [Kea - Write your fisrt property](https://kea-docs.readthedocs.io/en/latest/part-keaUserManuel/first_property.html) for more details.
|
|
236
286
|
|
|
287
|
+
### Notes
|
|
288
|
+
Currently, in `@precondition` decorator and `widgets.block.py`. We only support basic selector (No parent-child relationship) and basic xpath (No chain call like `.xpath().xpath()`) in uiautomator2. The Script body in the function fully support uiautomator2.
|
|
237
289
|
|
|
238
|
-
|
|
290
|
+
|
|
291
|
+
| | **Support** | **Not support** |
|
|
292
|
+
| -- | -- | -- |
|
|
293
|
+
| **Selctor** | `d(text="1").exist` | `d(text="1").child(text="2").exist` |
|
|
294
|
+
| **XPath** | `d.xpath(".//[@text='1']")` | `d.xpath(".//[@text='1']").xpath(".//[@text]='2'")` |
|
|
295
|
+
|
|
296
|
+
If you need to specify `parent-child` relation ship in `@precondition`, specify it in xpath.
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
## Launching Kea2
|
|
239
300
|
|
|
240
301
|
We offer two ways to launch Kea2.
|
|
241
302
|
|
|
@@ -251,8 +312,8 @@ kea2 run <Kea2 cmds> unittest <unittest cmds>
|
|
|
251
312
|
Sample shell commands:
|
|
252
313
|
|
|
253
314
|
```bash
|
|
254
|
-
# Launch Kea2 and load one single script
|
|
255
|
-
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest
|
|
315
|
+
# Launch Kea2 and load one single script quicktest.py.
|
|
316
|
+
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
|
|
256
317
|
|
|
257
318
|
# Launch Kea2 and load multiple scripts from the directory mytests/omni_notes
|
|
258
319
|
kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest discover -s mytests/omni_notes
|
|
@@ -262,6 +323,7 @@ kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --runn
|
|
|
262
323
|
| --- | --- |
|
|
263
324
|
| -s | The serial of your device, which can be found by `adb devices` |
|
|
264
325
|
| -p | The tested app's package name (e.g., com.example.app) |
|
|
326
|
+
| -o | The ouput directory for logs and results |
|
|
265
327
|
| --agent | {native, u2}. By default, `u2` is used and supports all the three important features of Kea2. If you hope to run the orignal Fastbot, please use `native`.|
|
|
266
328
|
| --running-minutes | The time (m) to run Kea2 |
|
|
267
329
|
| --max-step | The maxium number of monkey events to send (only available in `--agent u2`) |
|
|
@@ -327,9 +389,10 @@ maxStep: int # default "inf"
|
|
|
327
389
|
running_mins: int = 10
|
|
328
390
|
# time(ms) to wait when exploring the app
|
|
329
391
|
throttle: int = 200
|
|
392
|
+
# the output_dir for saving logs and results
|
|
393
|
+
output_dir: str = "output"
|
|
330
394
|
```
|
|
331
395
|
|
|
332
|
-
|
|
333
396
|
## Examining the running statistics of scripts .
|
|
334
397
|
|
|
335
398
|
If you want to examine whether your scripts have been executed or how many times they have been executed during testing. Open the file `result.json` after the testing is finished.
|
|
@@ -357,13 +420,10 @@ executed | During UI testing, how many times the test method has been executed?
|
|
|
357
420
|
fail | How many times did the test method fail the assertions during UI testing? | When failed, the test method found a likely functional bug.
|
|
358
421
|
error | How many times does the test method abort during UI tsting due to some unexpected errors (e.g. some UI widgets used in the test method cannot be found) | When some error happens, the script needs to be updated/fixed because the script leads to some unexpected errors.
|
|
359
422
|
|
|
360
|
-
|
|
423
|
+
## Configuration File
|
|
361
424
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
python3 -m pip install --upgrade pip
|
|
365
|
-
python3 -m pip install .
|
|
366
|
-
```
|
|
425
|
+
After executing `Kea2 init`, some configuration files will be generated in the `configs` directory.
|
|
426
|
+
These configuration files belong to `Fastbot`, and their specific introductions are provided in [Introduction to configuration files](https://github.com/bytedance/Fastbot_Android/blob/main/handbook-cn.md#%E4%B8%93%E5%AE%B6%E7%B3%BB%E7%BB%9F).
|
|
367
427
|
|
|
368
428
|
## Contributors/Maintainers
|
|
369
429
|
|
|
@@ -14,5 +14,5 @@ def global_block_widgets(d: "Device"):
|
|
|
14
14
|
# conditional block list
|
|
15
15
|
@precondition(lambda d: d(text="In the home page").exists)
|
|
16
16
|
def block_sth(d: "Device"):
|
|
17
|
-
# Important: function shold starts with "
|
|
17
|
+
# Important: function shold starts with "block_"
|
|
18
18
|
return [d(text="widgets to block"), d.xpath(".//node[@text='widget to block']")]
|
kea2_python-0.0.1a4/kea2/assets/quickstart.py → kea2_python-0.0.1a6/kea2/assets/quicktest.py
RENAMED
|
@@ -73,17 +73,7 @@ def check_installation():
|
|
|
73
73
|
d.stop_uiautomator()
|
|
74
74
|
|
|
75
75
|
|
|
76
|
-
def _get_agent():
|
|
77
|
-
import sys
|
|
78
|
-
if len(sys.argv) == 0 or sys.argv[1] == "u2":
|
|
79
|
-
sys.argv=sys.argv[:1]
|
|
80
|
-
return "u2"
|
|
81
|
-
sys.argv=sys.argv[:1]
|
|
82
|
-
return "native"
|
|
83
|
-
|
|
84
76
|
if __name__ == "__main__":
|
|
85
|
-
|
|
86
|
-
AGENT=_get_agent()
|
|
87
77
|
check_installation()
|
|
88
78
|
KeaTestRunner.setOptions(
|
|
89
79
|
Options(
|
|
@@ -94,7 +84,7 @@ if __name__ == "__main__":
|
|
|
94
84
|
maxStep=5000,
|
|
95
85
|
# running_mins=10, # specify the maximal running time in minutes, default value is 10m
|
|
96
86
|
# throttle=200, # specify the throttle in milliseconds, default value is 200ms
|
|
97
|
-
agent=
|
|
87
|
+
agent="u2" # 'native' for running the vanilla Fastbot, 'u2' for running Kea2
|
|
98
88
|
)
|
|
99
89
|
)
|
|
100
90
|
unittest.main(testRunner=KeaTestRunner)
|
|
@@ -13,6 +13,12 @@ from pathlib import Path
|
|
|
13
13
|
|
|
14
14
|
logger = getLogger(__name__)
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
def cmd_version(args):
|
|
18
|
+
from importlib.metadata import version
|
|
19
|
+
print(version("Kea2-python"), flush=True)
|
|
20
|
+
|
|
21
|
+
|
|
16
22
|
def cmd_init(args):
|
|
17
23
|
cwd = Path(os.getcwd())
|
|
18
24
|
configs_dir = cwd / "configs"
|
|
@@ -27,8 +33,8 @@ def cmd_init(args):
|
|
|
27
33
|
shutil.copytree(src, dst)
|
|
28
34
|
|
|
29
35
|
def copy_samples():
|
|
30
|
-
src = Path(__file__).parent / "assets" / "
|
|
31
|
-
dst = cwd / "
|
|
36
|
+
src = Path(__file__).parent / "assets" / "quicktest.py"
|
|
37
|
+
dst = cwd / "quicktest.py"
|
|
32
38
|
shutil.copyfile(src, dst)
|
|
33
39
|
|
|
34
40
|
copy_configs()
|
|
@@ -39,6 +45,7 @@ def cmd_init(args):
|
|
|
39
45
|
def cmd_load_configs(args):
|
|
40
46
|
pass
|
|
41
47
|
|
|
48
|
+
|
|
42
49
|
def cmd_run(args):
|
|
43
50
|
base_dir = getProjectRoot()
|
|
44
51
|
if base_dir is None:
|
|
@@ -47,83 +54,13 @@ def cmd_run(args):
|
|
|
47
54
|
run(args)
|
|
48
55
|
|
|
49
56
|
|
|
50
|
-
def cmd_install(args):
|
|
51
|
-
pass
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def cmd_uninstall(args):
|
|
55
|
-
pass
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def cmd_start(args):
|
|
59
|
-
pass
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def cmd_stop(args):
|
|
63
|
-
pass
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def cmd_current(args):
|
|
67
|
-
pass
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def cmd_doctor(args):
|
|
71
|
-
pass
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# def cmd_version(args):
|
|
75
|
-
# print(__version__)
|
|
76
|
-
|
|
77
|
-
|
|
78
57
|
_commands = [
|
|
79
|
-
|
|
58
|
+
dict(action=cmd_version, command="version", help="show version"),
|
|
80
59
|
dict(
|
|
81
60
|
action=cmd_init,
|
|
82
61
|
command="init",
|
|
83
62
|
help="init the Kea2 project in current directory",
|
|
84
|
-
)
|
|
85
|
-
# dict(
|
|
86
|
-
# action=cmd_run,
|
|
87
|
-
# command="run",
|
|
88
|
-
# help="run kea2",
|
|
89
|
-
# flags=[
|
|
90
|
-
# dict(args=["args"], nargs=argparse.REMAINDER),
|
|
91
|
-
# ],
|
|
92
|
-
# ),
|
|
93
|
-
# dict(
|
|
94
|
-
# action=cmd_install,
|
|
95
|
-
# command="",
|
|
96
|
-
# help="install packages",
|
|
97
|
-
# flags=[
|
|
98
|
-
# dict(args=["url"], help="package url"),
|
|
99
|
-
# ],
|
|
100
|
-
# ),
|
|
101
|
-
# dict(
|
|
102
|
-
# action=cmd_uninstall,
|
|
103
|
-
# command="uninstall",
|
|
104
|
-
# help="uninstall packages",
|
|
105
|
-
# flags=[
|
|
106
|
-
# dict(args=["--all"], action="store_true", help="uninstall all packages"),
|
|
107
|
-
# dict(args=["package_name"], nargs="*", help="package name"),
|
|
108
|
-
# ],
|
|
109
|
-
# ),
|
|
110
|
-
# dict(
|
|
111
|
-
# action=cmd_start,
|
|
112
|
-
# command="start",
|
|
113
|
-
# help="start application",
|
|
114
|
-
# flags=[dict(args=["package_name"], type=str, nargs=None, help="package name")],
|
|
115
|
-
# ),
|
|
116
|
-
# dict(
|
|
117
|
-
# action=cmd_stop,
|
|
118
|
-
# command="stop",
|
|
119
|
-
# help="stop application",
|
|
120
|
-
# flags=[
|
|
121
|
-
# dict(args=["--all"], action="store_true", help="stop all"),
|
|
122
|
-
# dict(args=["package_name"], nargs="*", help="package name"),
|
|
123
|
-
# ],
|
|
124
|
-
# ),
|
|
125
|
-
# dict(action=cmd_current, command="current", help="show current application"),
|
|
126
|
-
# dict(action=cmd_doctor, command="doctor", help="detect connect problem"),
|
|
63
|
+
)
|
|
127
64
|
]
|
|
128
65
|
|
|
129
66
|
|
|
@@ -132,9 +69,7 @@ def main():
|
|
|
132
69
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
|
133
70
|
)
|
|
134
71
|
parser.add_argument("-d", "--debug", action="store_true",
|
|
135
|
-
help="show log")
|
|
136
|
-
parser.add_argument('-s', '--serial', type=str,
|
|
137
|
-
help='device serial number')
|
|
72
|
+
help="show detail log")
|
|
138
73
|
|
|
139
74
|
subparser = parser.add_subparsers(dest='subparser')
|
|
140
75
|
|
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
import subprocess
|
|
5
5
|
import threading
|
|
6
6
|
import traceback
|
|
7
|
-
from typing import IO, Callable, Any, Dict, List, Literal, NewType,
|
|
7
|
+
from typing import IO, Callable, Any, Dict, List, Literal, NewType, Union
|
|
8
8
|
from unittest import TextTestRunner, registerResult, TestSuite, TestCase, TextTestResult
|
|
9
9
|
import random
|
|
10
10
|
import warnings
|
|
@@ -223,6 +223,7 @@ def startFastbotService(options: Options) -> threading.Thread:
|
|
|
223
223
|
"reuseq",
|
|
224
224
|
"--running-minutes", f"{options.running_mins}",
|
|
225
225
|
"--throttle", f"{options.throttle}",
|
|
226
|
+
"--bugreport", "--output-directory", "/sdcard/fastbot_report"
|
|
226
227
|
"-v", "-v", "-v"
|
|
227
228
|
]
|
|
228
229
|
|
|
@@ -265,7 +266,7 @@ class KeaTestRunner(TextTestRunner):
|
|
|
265
266
|
|
|
266
267
|
def _setOuputDir(self):
|
|
267
268
|
output_dir = Path(self.options.output_dir).absolute()
|
|
268
|
-
|
|
269
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
269
270
|
global LOGFILE, RESFILE
|
|
270
271
|
LOGFILE = output_dir / Path(LOGFILE)
|
|
271
272
|
RESFILE = output_dir / Path(RESFILE)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so
RENAMED
|
File without changes
|
|
File without changes
|
{kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/x86/libfastbot_native.so
RENAMED
|
File without changes
|
{kea2_python-0.0.1a4 → kea2_python-0.0.1a6}/kea2/assets/fastbot_libs/x86_64/libfastbot_native.so
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|