Kea2-python 0.0.1a0__py3-none-any.whl
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/__init__.py +4 -0
- kea2/absDriver.py +34 -0
- kea2/adbUtils.py +258 -0
- kea2/assets/fastbot-thirdpart.jar +0 -0
- kea2/assets/fastbot_configs/ADBKeyBoard.apk +0 -0
- kea2/assets/fastbot_configs/abl.strings +2 -0
- kea2/assets/fastbot_configs/awl.strings +3 -0
- kea2/assets/fastbot_configs/max.config +7 -0
- kea2/assets/fastbot_configs/max.fuzzing.strings +699 -0
- kea2/assets/fastbot_configs/max.schema.strings +1 -0
- kea2/assets/fastbot_configs/max.strings +3 -0
- kea2/assets/fastbot_configs/max.tree.pruning +27 -0
- kea2/assets/fastbot_configs/widget.block.py +22 -0
- kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so +0 -0
- kea2/assets/fastbot_libs/armeabi-v7a/libfastbot_native.so +0 -0
- kea2/assets/fastbot_libs/x86/libfastbot_native.so +0 -0
- kea2/assets/fastbot_libs/x86_64/libfastbot_native.so +0 -0
- kea2/assets/framework.jar +0 -0
- kea2/assets/monkeyq.jar +0 -0
- kea2/assets/quickstart.py +90 -0
- kea2/assets/u2.jar +0 -0
- kea2/cli.py +176 -0
- kea2/keaUtils.py +535 -0
- kea2/kea_launcher.py +135 -0
- kea2/logWatcher.py +71 -0
- kea2/u2Driver.py +316 -0
- kea2/utils.py +53 -0
- kea2_python-0.0.1a0.dist-info/METADATA +433 -0
- kea2_python-0.0.1a0.dist-info/RECORD +33 -0
- kea2_python-0.0.1a0.dist-info/WHEEL +5 -0
- kea2_python-0.0.1a0.dist-info/entry_points.txt +2 -0
- kea2_python-0.0.1a0.dist-info/licenses/LICENSE +16 -0
- kea2_python-0.0.1a0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Kea2-python
|
|
3
|
+
Version: 0.0.1a0
|
|
4
|
+
Summary: A python library for supporting and customizing automated UI testing for mobile apps
|
|
5
|
+
Author-email: Xixian Liang <xixian@stu.ecnu.edu.cn>
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: rtree>=1.4.0
|
|
10
|
+
Requires-Dist: uiautomator2>=3.2.9
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Introduction
|
|
14
|
+
|
|
15
|
+
Kea2 is an easy-to-use Python library for supporting and customizing automated UI testing for mobile apps. The library is currently built on top of [Fastbot](https://github.com/bytedance/Fastbot_Android) and [uiautomator2](https://github.com/openatx/uiautomator2), and targeting [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) apps.
|
|
16
|
+
|
|
17
|
+
### Kea2 has three important features:
|
|
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);
|
|
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
|
+
|
|
22
|
+
These three features can be combined to customize and improve automated UI testing.
|
|
23
|
+
|
|
24
|
+
<div align="center">
|
|
25
|
+
<div style="max-width:80%; max-height:80%">
|
|
26
|
+
<img src="docs/intro.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
> Kea2 is designed to be capable of fusing the (property-based) *scripteds* (e.g., written in uiautomator2) with automated UI testing tools (e.g., Fastbot), thus combining the strengths of human knowledge on app's business logics (empowered by the scripts) and random fuzzing. Many useful features (e.g., mimicing exploratory testing) can be implemented based on such a capability.
|
|
31
|
+
|
|
32
|
+
**The ability of the three features in Kea2**
|
|
33
|
+
| | **Feature 1** | **Feature 2** | **Feature 3** |
|
|
34
|
+
| --- | --- | --- | ---- |
|
|
35
|
+
| **Finding crashes** | :+1: | :+1: | :+1: |
|
|
36
|
+
| **Finding crashes in deep states** | | :+1: | :+1: |
|
|
37
|
+
| **Finding non-crashing functional bugs** | | | :+1: |
|
|
38
|
+
|
|
39
|
+
Kea2, released as a Python library, currently works with:
|
|
40
|
+
- [unittest](https://docs.python.org/3/library/unittest.html) as the testing framework;
|
|
41
|
+
- [uiautomator2](https://github.com/openatx/uiautomator2) as the UI test driver;
|
|
42
|
+
- [Fastbot](https://github.com/bytedance/Fastbot_Android) as the backend automated UI testing tool.
|
|
43
|
+
|
|
44
|
+
In the future, Kea2 will be extended to support
|
|
45
|
+
- [pytest](https://docs.pytest.org/en/stable/)
|
|
46
|
+
- [Appium](https://github.com/appium/appium), [Hypium]() (for HarmonyOS)
|
|
47
|
+
- other automated UI testing tools (not limited to Fastbot)
|
|
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!
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# Deploy Kea2
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
Running requirements/environment:
|
|
57
|
+
- support Windows, MacOS and Linux
|
|
58
|
+
- python 3.8+
|
|
59
|
+
- Android SDK installed
|
|
60
|
+
- **VPN closed** (Features 2 and 3 required)
|
|
61
|
+
|
|
62
|
+
1. Clone `Kea2` into your workspace.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone git@github.com:ecnusse/Kea2.git
|
|
66
|
+
cd Kea2
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. Setup the python virtual environment with `uv`.
|
|
70
|
+
|
|
71
|
+
> [uv](https://github.com/astral-sh/uv) is a extremely fast python package and project manager. We use `uv` to create a python virtual environment for Kea2 to avoid any dependency issues or conflicts with your existing python environment.
|
|
72
|
+
`uv` is similar to `virtualenv` but much more powerful.
|
|
73
|
+
Of course, you can also setup Kea2 in your [global environment](https://github.com/ecnusse/Kea2/tree/dev?tab=readme-ov-file#appendix-install-kea2-in-a-global-environment).
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install --upgrade pip
|
|
77
|
+
pip install uv
|
|
78
|
+
uv sync
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> MacOS users may have trouble with global pip install. In such cases, they can use `brew`.
|
|
82
|
+
```bash
|
|
83
|
+
# For macOS users
|
|
84
|
+
brew install uv
|
|
85
|
+
uv sync
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
3. Activate virtual environment
|
|
89
|
+
|
|
90
|
+
- Linux and macOS
|
|
91
|
+
```bash
|
|
92
|
+
source .venv/bin/activate
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- Windows cmd
|
|
96
|
+
```cmd
|
|
97
|
+
\.venv\Scripts\activate.bat
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- Windows powershell
|
|
101
|
+
```powershell
|
|
102
|
+
\.venv\Scripts\activate.ps1
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Quick Test
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
1. Connect to an Android device and make sure you can see the connected device by running `adb devices`.
|
|
110
|
+
|
|
111
|
+
2. Run `quickstart.py` to test a sample app `omninotes` (released as `omninotes.apk` in Kea2's repository). The script `quickstart.py` will automatically install and test this sample app for a short time.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
python3 quickstart.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
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!
|
|
118
|
+
|
|
119
|
+
If you do not have an Android device at hand, you can use an Android emulator to run Kea2. The following commands can help create and start an Android emulator (Android version 12, API level 31) on a x86 machine (of course, you can create emulators by Android Studio):
|
|
120
|
+
```bash
|
|
121
|
+
sdkmanager "system-images;android-31;google_apis;x86_64"
|
|
122
|
+
|
|
123
|
+
avdmanager create avd --force --name Android12 --package 'system-images;android-31;google_apis;x86_64' --abi google_apis/x86_64 --sdcard 1024M --device 'Nexus 7'
|
|
124
|
+
|
|
125
|
+
emulator -avd Android12 -port 5554 &
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
> [quickstart.py](https://github.com/XixianLiang/KeaPlus/blob/main/quickstart.py) is a dead simple script which is ready-to-go with Fastbot. You can customize this script for testing your apps.
|
|
129
|
+
|
|
130
|
+
## Feature 1(查找稳定性问题): running Fastbot
|
|
131
|
+
|
|
132
|
+
Test your app with the full capability of [Fastbot](https://github.com/bytedance/Fastbot_Android) for stress testing and finding *stability problems* (i.e., *crashing bugs*);
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python3 kea_launcher.py driver -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The usage is similar to the the original [Fastbot](https://github.com/bytedance/Fastbot_Android?tab=readme-ov-file#run-fastbot-with-shell-command)'s shell commands.
|
|
140
|
+
See more options by `python kea_launcher.py driver -h`
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
## Feature 2(自定义测试场景或事件序列): customizing testing scenarios by scripts
|
|
144
|
+
|
|
145
|
+
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.
|
|
146
|
+
|
|
147
|
+
<div align="center">
|
|
148
|
+
<div>
|
|
149
|
+
<img src="docs/stage1.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<div align="center">
|
|
154
|
+
<img src="docs/stage2.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
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 states) with the full capability and flexibility powered by `python` language and [uiautomator2](https://github.com/openatx/uiautomator2);
|
|
158
|
+
|
|
159
|
+
In Kea2, a script is composed of two elements:
|
|
160
|
+
- **Precondition:** When to execute the script.
|
|
161
|
+
- **Interaction scenario:** The interaction logic (specified in the script's test method) to reach where we want.
|
|
162
|
+
|
|
163
|
+
### Example
|
|
164
|
+
|
|
165
|
+
Assuming `Privacy` is a hard-to-reach UI page during automated UI testing. Kea2 can easily guide Fastbot to reach this page.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
@prob(0.5)
|
|
169
|
+
# precondition: when we are at the page `Home`
|
|
170
|
+
@precondition(lambda self:
|
|
171
|
+
self.d(text="Home").exists
|
|
172
|
+
)
|
|
173
|
+
def test_goToPrivacy(self):
|
|
174
|
+
"""
|
|
175
|
+
Guide Fastbot to the page `Privacy` by opening `Drawer`,
|
|
176
|
+
clicking the option `Setting` and clicking `Privacy`.
|
|
177
|
+
"""
|
|
178
|
+
self.d(description="Drawer").click()
|
|
179
|
+
self.d(text="Settings").click()
|
|
180
|
+
self.d(text="Privacy").click()
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- By the decorator `@precondition`, we specify the precondition --- when we are at the `Home` page.
|
|
184
|
+
In this case, the `Home` page is the entry page of the `Privacy` page and the `Home` page can be easily reached by Fastbot. Thus, the script will be activated when we are at `Home` page by checking whether a unique widget `Home` exists.
|
|
185
|
+
- 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.
|
|
186
|
+
- 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.
|
|
187
|
+
|
|
188
|
+
You can find the full example in script `quickstart2.py` and run it by executing:
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Launch Kea2 and load one single script quickstart2.py.
|
|
193
|
+
python3 kea_launcher.py driver -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest quickstart2.py
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
or simply run:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
python3 quickstart2.py
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
## Feature 3(支持断言机制): Supporting auto-assertions by scripts.
|
|
205
|
+
|
|
206
|
+
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. This idea is inspired by [property-based testing](https://en.wikipedia.org/wiki/Software_testing#Property_testing) inheritted from [Kea](https://github.com/ecnusse/Kea).
|
|
207
|
+
|
|
208
|
+
<div align="center">
|
|
209
|
+
<img src="docs/stage3.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
In Feature 3, a script is composed of three elements:
|
|
213
|
+
|
|
214
|
+
- **Precondition:** When to execute the script.
|
|
215
|
+
- **Interaction scenario:** The interaction logic (specified in the script's test method).
|
|
216
|
+
- **Assertion:** The expected app behaviour.
|
|
217
|
+
|
|
218
|
+
### Example
|
|
219
|
+
|
|
220
|
+
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).
|
|
221
|
+
|
|
222
|
+
<div align="center" >
|
|
223
|
+
<div >
|
|
224
|
+
<img src="docs/socialAppBug.png" style="border-radius: 14px; width:60%; height:70%;"/>
|
|
225
|
+
</div>
|
|
226
|
+
<p>The expected behavior (the upper figure) and the buggy behavior (the lower figure).
|
|
227
|
+
<p/>
|
|
228
|
+
</div>
|
|
229
|
+
|
|
230
|
+
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.
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
@precondition(
|
|
235
|
+
lambda self: self.d(description="input_box").exists
|
|
236
|
+
)
|
|
237
|
+
def test_input_box(self):
|
|
238
|
+
from hypothesis.strategies import text, ascii_letters
|
|
239
|
+
random_str = text(alphabet=ascii_letters).example()
|
|
240
|
+
self.d(description="input_box").set_text(random_str)
|
|
241
|
+
assert self.d(description="send_button").exist
|
|
242
|
+
|
|
243
|
+
# we can even do more assertions, e.g.,
|
|
244
|
+
# the input string should exist on the message sending page
|
|
245
|
+
assert self.d(text=random_str).exist
|
|
246
|
+
```
|
|
247
|
+
> We use [hypothesis](https://github.com/HypothesisWorks/hypothesis), a property-based testing library for Python, to generate random texts according to the given rules.
|
|
248
|
+
|
|
249
|
+
# Documentation
|
|
250
|
+
|
|
251
|
+
## Write scripts
|
|
252
|
+
|
|
253
|
+
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`).
|
|
254
|
+
|
|
255
|
+
Kea2 uses [Uiautomator2](https://github.com/openatx/uiautomator2) to manipulate android devices. Refer to [Uiautomator2's docs](https://github.com/openatx/uiautomator2?tab=readme-ov-file#quick-start) for more details.
|
|
256
|
+
|
|
257
|
+
Basically, you can write Kea2's scripts by following two steps:
|
|
258
|
+
|
|
259
|
+
1. Create a test class which extends `unittest.TestCase`.
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
import unittest
|
|
263
|
+
|
|
264
|
+
class MyFirstTest(unittest.TestCase):
|
|
265
|
+
...
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
2. Write your own script by defining test methods
|
|
269
|
+
|
|
270
|
+
By default, only the test method starts with `test_` will be found by unittest. You can decorate the function with `@precondition`. The decorator `@precondition` takes a function which returns boolean as an arugment. When the function returns `True`, the precondition is satisified and the script will be activated, and Kea2 will run the script based on certain probability defined by the decorator `@prob`.
|
|
271
|
+
|
|
272
|
+
Note that if a test method is not decorated with `@precondition`.
|
|
273
|
+
This test method will never be activated during automated UI testing, and will be treated as a normal `unittset` test method.
|
|
274
|
+
Thus, you need to explicitly specify `@precondition(lambda self: True)` when the test method should be always executed. When a test method is not decorated with `@prob`, the default probability is 1 (always execute when precondition satisfied).
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
import unittest
|
|
278
|
+
from kea2 import precondition
|
|
279
|
+
|
|
280
|
+
class MyFirstTest(unittest.TestCase):
|
|
281
|
+
|
|
282
|
+
@prob(0.7)
|
|
283
|
+
@precondition(lambda self: ...)
|
|
284
|
+
def test_func1(self):
|
|
285
|
+
...
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
You can read [Kea - Write your fisrt property](https://kea-docs.readthedocs.io/en/latest/part-keaUserManuel/first_property.html) for more details.
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
## Launch Kea2
|
|
292
|
+
|
|
293
|
+
We offer two ways to launch Kea2.
|
|
294
|
+
|
|
295
|
+
### 1. Launch by shell commands
|
|
296
|
+
|
|
297
|
+
Kea2 is compatible with `unittest` framework. You can manage your test cases in unittest style. You can launch Kea2 with `kea_launcher.py` with two sub-commands `driver` (for Kea2 options) and `unittest` (for unittest options).
|
|
298
|
+
|
|
299
|
+
The shell command:
|
|
300
|
+
```
|
|
301
|
+
python3 kea_launcher.py driver <Kea2 cmds> unittest <unittest cmds>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Sample shell commands:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
# Launch Kea2 and load one single script quickstart.py.
|
|
308
|
+
python3 kea_launcher.py driver -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest quickstart.py
|
|
309
|
+
|
|
310
|
+
# Launch Kea2 and load multiple scripts from the directory mytests/omni_notes
|
|
311
|
+
python3 kea_launcher.py driver -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
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
| arg | meaning |
|
|
315
|
+
| --- | --- |
|
|
316
|
+
| -s | The serial of your device, which can be found by `adb devices` |
|
|
317
|
+
| -p | The tested app's package name (e.g., com.example.app) |
|
|
318
|
+
| --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`.|
|
|
319
|
+
| --running-minutes | The time (m) to run Kea2 |
|
|
320
|
+
| --max-step | The maxium number of monkey events to send (only available in `--agent u2`) |
|
|
321
|
+
| --throttle | The delay time (ms) between two monkey events |
|
|
322
|
+
| --driver-name | The name of driver used in the script. If `--driver-name d` is specified, you should use `d` to interact with a device, e..g, `self.d(..).click()`. |
|
|
323
|
+
| unittest | Specify to load which scripts. This sub-command `unittest` is fully compatible with unittest. See `python3 -m unittest -h` for more options of unittest. This option is only available in `--agent u2`.
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
### 2. Launch by `unittest.main`
|
|
327
|
+
|
|
328
|
+
Like unittest, we can launch Kea2 through the method `unittest.main`.
|
|
329
|
+
|
|
330
|
+
Here is an example (named as `mytest.py`). You can see that the options are directly defined in the script.
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
import unittest
|
|
334
|
+
|
|
335
|
+
from kea2 import KeaTestRunner, Options
|
|
336
|
+
from kea2.u2Driver import U2Driver
|
|
337
|
+
|
|
338
|
+
class MyTest(unittest.TestCase):
|
|
339
|
+
...
|
|
340
|
+
# <your test methods here>
|
|
341
|
+
|
|
342
|
+
if __name__ == "__main__":
|
|
343
|
+
KeaTestRunner.setOptions(
|
|
344
|
+
Options(
|
|
345
|
+
driverName="d",
|
|
346
|
+
Driver=U2Driver,
|
|
347
|
+
packageNames=[PACKAGE_NAME],
|
|
348
|
+
# serial="emulator-5554", # specify the serial
|
|
349
|
+
maxStep=100,
|
|
350
|
+
# running_mins=10, # specify the maximal running time in minutes, default value is 10m
|
|
351
|
+
# throttle=200, # specify the throttle in milliseconds, default value is 200ms
|
|
352
|
+
# agent='native' # 'native' for running the vanilla Fastbot
|
|
353
|
+
)
|
|
354
|
+
)
|
|
355
|
+
# Declare the KeaTestRunner
|
|
356
|
+
unittest.main(testRunner=KeaTestRunner)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
We can directly run the script `mytest.py` to launch Kea2, e.g.,
|
|
360
|
+
```python
|
|
361
|
+
python3 mytest.py
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Here's all the available options in `Options`.
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
# the driver_name in script (if self.d, then d.)
|
|
368
|
+
driverName: str
|
|
369
|
+
# the driver (only U2Driver available now)
|
|
370
|
+
Driver: U2Driver
|
|
371
|
+
# list of package names. Specify the apps under test
|
|
372
|
+
packageNames: List[str]
|
|
373
|
+
# target device
|
|
374
|
+
serial: str = None
|
|
375
|
+
# test agent. "u2" is the default agent
|
|
376
|
+
agent: "u2" | "native" = "u2"
|
|
377
|
+
# max step in exploration (availble in stage 2~3)
|
|
378
|
+
maxStep: int # default "inf"
|
|
379
|
+
# time(mins) for exploration
|
|
380
|
+
running_mins: int = 10
|
|
381
|
+
# time(ms) to wait when exploring the app
|
|
382
|
+
throttle: int = 200
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
## Examining the running statistics of scripts .
|
|
387
|
+
|
|
388
|
+
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.
|
|
389
|
+
|
|
390
|
+
Here's an example.
|
|
391
|
+
|
|
392
|
+
```json
|
|
393
|
+
{
|
|
394
|
+
"test_goToPrivacy": {
|
|
395
|
+
"precond_satisfied": 8,
|
|
396
|
+
"executed": 2,
|
|
397
|
+
"fail": 0,
|
|
398
|
+
"error": 1
|
|
399
|
+
},
|
|
400
|
+
...
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**How to read `result.json`**
|
|
405
|
+
|
|
406
|
+
Field | Description | Meaning
|
|
407
|
+
--- | --- | --- |
|
|
408
|
+
precond_satisfied | During exploration, how many times has the test method's precondition been satisfied? | Does we reach the state during exploration?
|
|
409
|
+
executed | During UI testing, how many times the test method has been executed? | Has the test method ever been executed?
|
|
410
|
+
fail | How many times did the test method fail the assertions during UI testing? | When failed, the test method found a likely functional bug.
|
|
411
|
+
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.
|
|
412
|
+
|
|
413
|
+
### Appendix: Install Kea2 in global environment
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
# In the working directory of Kea2
|
|
417
|
+
python3 -m pip install --upgrade pip
|
|
418
|
+
python3 -m pip install .
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Contributors/Maintainers
|
|
422
|
+
|
|
423
|
+
Kea2 has been actively developed and maintained by the people in [ecnusse](https://github.com/ecnusse).
|
|
424
|
+
|
|
425
|
+
### Open-source projects used by Kea2
|
|
426
|
+
|
|
427
|
+
- [Fastbot](https://github.com/bytedance/Fastbot_Android)
|
|
428
|
+
- [uiautomator2](https://github.com/openatx/uiautomator2)
|
|
429
|
+
- [hypothesis](https://github.com/HypothesisWorks/hypothesis)
|
|
430
|
+
|
|
431
|
+
[^1]: 不少UI自动化测试工具提供了“自定义事件序列”能力(如[Fastbot](https://github.com/bytedance/Fastbot_Android/blob/main/handbook-cn.md#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BA%8B%E4%BB%B6%E5%BA%8F%E5%88%97) 和[AppCrawler](https://github.com/seveniruby/AppCrawler)),但在实际使用中存在不少问题,如自定义能力有限、使用不灵活等。此前不少Fastbot用户抱怨过其“自定义事件序列”在使用中的问题,如[#209](https://github.com/bytedance/Fastbot_Android/issues/209), [#225](https://github.com/bytedance/Fastbot_Android/issues/225), [#286](https://github.com/bytedance/Fastbot_Android/issues/286)等。
|
|
432
|
+
|
|
433
|
+
[^2]: 在UI自动化测试过程中支持自动断言是一个很重要的能力,但几乎没有测试工具提供这样的能力。我们注意到[AppCrawler](https://ceshiren.com/t/topic/15801/5)的开发者曾经希望提供一种断言机制,得到了用户的热切响应,不少用户从21年就开始催更,但始终未能实现。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
kea2/__init__.py,sha256=_IFDiyzb6OLyhjldBXrAol6OpOijTnJ2LYWMK4TqSno,121
|
|
2
|
+
kea2/absDriver.py,sha256=1vXTkPqhhIosT8KpS6pwi7XKjNZTOuSb7mczhS_tMoQ,648
|
|
3
|
+
kea2/adbUtils.py,sha256=IV-5G_3mc89YP1NJZJIWUrgxb13QECGGXTTANkGH_Rk,8986
|
|
4
|
+
kea2/cli.py,sha256=MBNvw7utLfkAwFtoF3zbh7o44TBOrsWS0RF6EY0c9Do,4232
|
|
5
|
+
kea2/keaUtils.py,sha256=pg6wsPaUf8BL91503bXm672DdYFoyi6NvgGNIASsblA,18718
|
|
6
|
+
kea2/kea_launcher.py,sha256=phBIrtO8RIKhIXiaffIkoHMlU4QIt-pIEVxJ2Pn3nrk,3665
|
|
7
|
+
kea2/logWatcher.py,sha256=hd8banPiCa6aCQ6d_MznWKOdzK_A2X_dPbrx-usjxgE,1927
|
|
8
|
+
kea2/u2Driver.py,sha256=Uyj0C2DFUCI1LB07YJHtLfvTsU_aaMtjhiweAVZ3uAw,9896
|
|
9
|
+
kea2/utils.py,sha256=zjuoVwts2qVX9GnTaPoiqarfcSvyfW6cAD3ESf_dmrQ,1284
|
|
10
|
+
kea2/assets/fastbot-thirdpart.jar,sha256=0SZ_OoZFWDGMnazgXKceHgKvXdUDoIa3Gb2bcifaikk,85664
|
|
11
|
+
kea2/assets/framework.jar,sha256=rTluOJJKj2DFwh7ascXso1udYdWv00BxBwSQ3Vmv-fw,1149240
|
|
12
|
+
kea2/assets/monkeyq.jar,sha256=k1r0Rf4UPgA1tndCx0YEFL_5d6jY3W8hgi-rn8FdFVw,459851
|
|
13
|
+
kea2/assets/quickstart.py,sha256=YsZCqLCwb5Mg8m0ybdyL-_TJ8FX2oKLyHZFJrk7fvkQ,2865
|
|
14
|
+
kea2/assets/u2.jar,sha256=G9fFf-AZ0CdaZrk27V1-pfJE2Y5eO6PRzPShTnIe-U8,3746525
|
|
15
|
+
kea2/assets/fastbot_configs/ADBKeyBoard.apk,sha256=L3Kva4gCQALo10EzinCvHrIbffGE3p94qSNbnS8CxP0,163634
|
|
16
|
+
kea2/assets/fastbot_configs/abl.strings,sha256=Rn8_YEbVGOJqndIY_-kWnR5NaoFI-cuB-ij10Ddhl90,75
|
|
17
|
+
kea2/assets/fastbot_configs/awl.strings,sha256=-j4980GoWQxGOM9ijAwXPQmziCwFBZJFmuiv2tOEaYI,101
|
|
18
|
+
kea2/assets/fastbot_configs/max.config,sha256=rBgR4mdgBzqVPQ2lZaXqx2WN6tDzhe-FNizm4Y7tyA8,226
|
|
19
|
+
kea2/assets/fastbot_configs/max.fuzzing.strings,sha256=_3bNHwgzlISgxB7RmMury5X3qIo2jhVhEn8jow8jfbk,27554
|
|
20
|
+
kea2/assets/fastbot_configs/max.schema.strings,sha256=zYupzvmTtnbPYomI2UCPk0s6PE97t94myZU_j3HutRM,40
|
|
21
|
+
kea2/assets/fastbot_configs/max.strings,sha256=k82GAAZZG7KbDI7bk7DUklp41WJJO7j-j8Ss1BcybUw,32
|
|
22
|
+
kea2/assets/fastbot_configs/max.tree.pruning,sha256=dm0oesN75FFbVSkV7STDUmrNMpQUBEuO7Uymt6nEkBc,629
|
|
23
|
+
kea2/assets/fastbot_configs/widget.block.py,sha256=hj5xT1SpIqwVv-Dtww8Povrxi5MY0gD9kX_orQrWSjc,647
|
|
24
|
+
kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so,sha256=dA2Tf74-gDrCFdeClsf7qZAy0RqDZQOLlBZ-FViuorw,2005832
|
|
25
|
+
kea2/assets/fastbot_libs/armeabi-v7a/libfastbot_native.so,sha256=GWcL8M8WfQAd9CfOM6pRYbOnxeycN-LiL7Mf59YIadE,1334420
|
|
26
|
+
kea2/assets/fastbot_libs/x86/libfastbot_native.so,sha256=k-aw1gEXRWMKZRNHIggKNuZy0wC1y2BnveJGEIO6rbo,2036856
|
|
27
|
+
kea2/assets/fastbot_libs/x86_64/libfastbot_native.so,sha256=tiofhlf4uMQcU5WAvrdLgTBME0lb83hVUoGtTwxmE8A,2121416
|
|
28
|
+
kea2_python-0.0.1a0.dist-info/licenses/LICENSE,sha256=nM9PPjcsXVo5SzNsjRqWgA-gdJlwqZZcRDSC6Qf6bVE,2034
|
|
29
|
+
kea2_python-0.0.1a0.dist-info/METADATA,sha256=Z6AWldJv7WwDnR3ybfaIhRFnYZedbP8Yd8u5KGLAyLo,20168
|
|
30
|
+
kea2_python-0.0.1a0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
31
|
+
kea2_python-0.0.1a0.dist-info/entry_points.txt,sha256=mFX06TyxXiUAJQ6JZn8QHzfn8n5R8_KJ5W-pTm_fRCA,39
|
|
32
|
+
kea2_python-0.0.1a0.dist-info/top_level.txt,sha256=TsgNH4PQoNOVhegpO7AcjutMVWp6Z4KDL1pBH9FnMmk,5
|
|
33
|
+
kea2_python-0.0.1a0.dist-info/RECORD,,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Kea2 Revised License
|
|
2
|
+
|
|
3
|
+
Effective from May 1st, 2025, The Kea2 SDK is hereby licensed as follows:
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2024-2025 ECNU Smart Software Lab. (The “Licensor”)
|
|
6
|
+
The Licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below (“Rights and Limitations”):
|
|
7
|
+
|
|
8
|
+
You may not provide or distribute the software to third parties. You may use it solely for your own internal use. “Internal use” permits distribution to your affiliates and to contractors where those contractors are permitted to exercise the Rights and Limitations solely on your and your affiliates’
|
|
9
|
+
behalf. An “affiliate” is an entity that controls, is controlled by, or is under common control with you. For the purposes of this definition "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty
|
|
10
|
+
percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
11
|
+
|
|
12
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the Licensor in the software. Any use of the Licensor's trademarks is prohibited unless otherwise permitted by applicable law.
|
|
13
|
+
|
|
14
|
+
This License will terminate immediately without notice should you breach any term.
|
|
15
|
+
|
|
16
|
+
TO THE EXTENT THAT SUCH EXCLUSION IS PERMITTED BY LAW, (1)THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF SATISFACTORY QUALITY, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, AND (2) IN NO EVENT SHALL THE LICENSOR, AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kea2
|