Kea2-python 0.1.3__py3-none-any.whl → 0.2.0__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/u2Driver.py CHANGED
@@ -1,10 +1,13 @@
1
1
  import random
2
2
  import socket
3
+ from time import sleep
3
4
  import uiautomator2 as u2
5
+ import adbutils
4
6
  import types
5
7
  import rtree
6
8
  import re
7
- from typing import Dict, List, Union
9
+ from typing import Any, Dict, List, Union
10
+ from http.client import HTTPResponse
8
11
  from lxml import etree
9
12
  from .absDriver import AbstractScriptDriver, AbstractStaticChecker, AbstractDriver
10
13
  from .adbUtils import list_forwards, remove_forward, create_forward
@@ -16,7 +19,7 @@ import logging
16
19
  logging.getLogger("urllib3").setLevel(logging.INFO)
17
20
  logging.getLogger("uiautomator2").setLevel(logging.INFO)
18
21
 
19
- logger = getLogger(__name__)
22
+ logger = getLogger(__name__)
20
23
 
21
24
  """
22
25
  The definition of U2ScriptDriver
@@ -35,34 +38,24 @@ class U2ScriptDriver(AbstractScriptDriver):
35
38
  """
36
39
 
37
40
  deviceSerial: str = None
41
+ transportId: str = None
38
42
  d = None
39
43
 
44
+ @classmethod
45
+ def setTransportId(cls, transportId):
46
+ cls.transportId = transportId
47
+
40
48
  @classmethod
41
49
  def setDeviceSerial(cls, deviceSerial):
42
50
  cls.deviceSerial = deviceSerial
43
51
 
44
52
  def getInstance(self):
45
53
  if self.d is None:
46
- self.d = (
47
- u2.connect() if self.deviceSerial is None
48
- else u2.connect(self.deviceSerial)
49
- )
50
-
51
- def get_u2_forward_port() -> int:
52
- """rewrite forward_port mothod to avoid the relocation of port
53
- :return: the new forward port
54
- """
55
- print("Rewriting forward_port method", flush=True)
56
- self.d._dev.forward_port = types.MethodType(
57
- forward_port, self.d._dev)
58
- lport = self.d._dev.forward_port(8090)
59
- setattr(self.d._dev, "msg", "meta")
60
- print(f"[U2] local port: {lport}", flush=True)
61
- return lport
62
-
63
- self._remove_remote_port(8090)
64
- self.d.lport = get_u2_forward_port()
65
- self._remove_remote_port(9008)
54
+ adb = adbutils.device(serial=self.deviceSerial, transport_id=self.transportId)
55
+ print("[INFO] Connecting to uiautomator2. Please wait ...")
56
+ self.d = u2.connect(adb)
57
+ sleep(5)
58
+ self.d._device_server_port = 8090
66
59
 
67
60
  return self.d
68
61
 
@@ -76,10 +69,11 @@ class U2ScriptDriver(AbstractScriptDriver):
76
69
  remove_forward(local_spec=forward_local, device=self.deviceSerial)
77
70
 
78
71
  def tearDown(self):
79
- logger.debug("U2Driver tearDown: stop_uiautomator")
80
- self.d.stop_uiautomator()
81
- logger.debug("U2Driver tearDown: remove forward")
82
- self._remove_remote_port(8090)
72
+ # logger.debug("U2Driver tearDown: stop_uiautomator")
73
+ # self.d.stop_uiautomator()
74
+ # logger.debug("U2Driver tearDown: remove forward")
75
+ # self._remove_remote_port(8090)
76
+ pass
83
77
 
84
78
  """
85
79
  The definition of U2StaticChecker
@@ -207,7 +201,7 @@ class StaticU2UiObject(u2.UiObject):
207
201
 
208
202
  def sibling(self, **kwargs):
209
203
  return StaticU2UiObject(self.session, self.selector.clone().sibling(**kwargs))
210
-
204
+
211
205
  def __getattr__(self, attr):
212
206
  return getattr(super(), attr)
213
207
 
@@ -366,8 +360,11 @@ class U2Driver(AbstractDriver):
366
360
  staticChecker = None
367
361
 
368
362
  @classmethod
369
- def setDeviceSerial(cls, deviceSerial):
370
- U2ScriptDriver.setDeviceSerial(deviceSerial)
363
+ def setDevice(cls, kwarg):
364
+ if kwarg.get("serial"):
365
+ U2ScriptDriver.setDeviceSerial(kwarg["serial"])
366
+ if kwarg.get("transport_id"):
367
+ U2ScriptDriver.setTransportId(kwarg["transport_id"])
371
368
 
372
369
  @classmethod
373
370
  def getScriptDriver(self):
@@ -400,7 +397,7 @@ def forward_port(self, remote: Union[int, str]) -> int:
400
397
  and f.remote == remote
401
398
  and f.local.startswith("tcp:")
402
399
  ): # yapf: disable
403
- return int(f.local[len("tcp:") :])
400
+ return int(f.local[len("tcp:"):])
404
401
  local_port = get_free_port()
405
402
  self.forward("tcp:" + str(local_port), remote)
406
403
  logger.debug(f"forwading port: tcp:{local_port} -> {remote}")
kea2/utils.py CHANGED
@@ -13,6 +13,7 @@ def getLogger(name: str) -> logging.Logger:
13
13
  if not logger.handlers:
14
14
  # Configure handler
15
15
  handler = logging.StreamHandler()
16
+ handler.flush = lambda: handler.stream.flush() # 确保每次都flush
16
17
  formatter = logging.Formatter('[%(levelname)1s][%(asctime)s %(module)s:%(lineno)d pid:%(process)d] %(message)s')
17
18
  handler.setFormatter(formatter)
18
19
  logger.addHandler(handler)
@@ -1,14 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Kea2-python
3
- Version: 0.1.3
3
+ Version: 0.2.0
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
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
9
  Requires-Dist: rtree>=1.3.0
10
- Requires-Dist: uiautomator2>=3.2.9
11
10
  Requires-Dist: jinja2>=3.0.0
11
+ Requires-Dist: uiautomator2>=3.3.3
12
+ Requires-Dist: adbutils>=2.9.3
12
13
  Dynamic: license-file
13
14
 
14
15
 
@@ -22,21 +23,36 @@ Dynamic: license-file
22
23
  <img src="https://github.com/user-attachments/assets/aa5839fc-4542-46f6-918b-c9f891356c84" style="border-radius: 14px; width: 20%; height: 20%;"/>
23
24
  </div>
24
25
 
25
- ## About
26
+ ### Github repo link
27
+ [https://github.com/ecnusse/Kea2](https://github.com/ecnusse/Kea2)
26
28
 
27
- 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.
29
+ ### [点击此处:查看中文文档](README_cn.md)
28
30
 
29
- Kea2 is currently built on top of [Fastbot](https://github.com/bytedance/Fastbot_Android) and [uiautomator2](https://github.com/openatx/uiautomator2) and targets [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) apps.
31
+ ## About
32
+
33
+ Kea2 is an easy-to-use tool for fuzzing mobile apps. Its key *novelty* is able to fuse automated UI testing with scripts (usually written by human), thus empowering automated UI testing with human intelligence for effectively finding *crashing bugs* as well as *non-crashing functional (logic) bugs*.
34
+
35
+ Kea2 is currently built on top of [Fastbot](https://github.com/bytedance/Fastbot_Android), *an industrial-strength automated UI testing tool*, and [uiautomator2](https://github.com/openatx/uiautomator2), *an easy-to-use and stable Android automation library*.
36
+ Kea2 currently targets [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) apps.
37
+
38
+ ## Novelty & Important features
39
+
40
+ <div align="center">
41
+ <div style="max-width:80%; max-height:80%">
42
+ <img src="docs/intro.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
43
+ </div>
44
+ </div>
30
45
 
31
- ## Important features
32
46
  - **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*);
33
47
 
34
48
  - **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](https://github.com/openatx/uiautomator2);
35
49
 
36
- - **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*)
50
+ - **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 functional bugs*).
37
51
 
52
+ For **Feature 2 and 3**, Kea2 allows you to focus on what app functionalities to be tested. You do not need to worry about how to reach these app functionalities. Just let Fastbot help. As a result, your scripts are usually short, robust and easy to maintain, and the corresponding app functionalities are much more stress-tested!
38
53
 
39
54
  **The ability of the three features in Kea2**
55
+
40
56
  | | **Feature 1** | **Feature 2** | **Feature 3** |
41
57
  | --- | --- | --- | ---- |
42
58
  | **Finding crashes** | :+1: | :+1: | :+1: |
@@ -44,24 +60,17 @@ Kea2 is currently built on top of [Fastbot](https://github.com/bytedance/Fastbot
44
60
  | **Finding non-crashing functional (logic) bugs** | | | :+1: |
45
61
 
46
62
 
47
- <div align="center">
48
- <div style="max-width:80%; max-height:80%">
49
- <img src="docs/intro.png" style="border-radius: 14px; width: 80%; height: 80%;"/>
50
- </div>
51
- </div>
52
-
53
-
54
63
 
55
64
  ## Design & Roadmap
56
- Kea2, released as a Python library, currently works with:
57
- - [unittest](https://docs.python.org/3/library/unittest.html) as the testing framework;
65
+ Kea2 currently works with:
66
+ - [unittest](https://docs.python.org/3/library/unittest.html) as the testing framework to manage the scripts;
58
67
  - [uiautomator2](https://github.com/openatx/uiautomator2) as the UI test driver;
59
68
  - [Fastbot](https://github.com/bytedance/Fastbot_Android) as the backend automated UI testing tool.
60
69
 
61
70
  In the future, Kea2 will be extended to support
62
- - [pytest](https://docs.pytest.org/en/stable/)
63
- - [Appium](https://github.com/appium/appium), [Hypium](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/hypium-python-guidelines) (for HarmonyOS/Open Harmony)
64
- - other automated UI testing tools (not limited to Fastbot)
71
+ - [pytest](https://docs.pytest.org/en/stable/), another popular python testing framework;
72
+ - [Appium](https://github.com/appium/appium), [Hypium](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/hypium-python-guidelines) (for HarmonyOS/Open Harmony);
73
+ - any other automated UI testing tools (not limited to Fastbot)
65
74
 
66
75
 
67
76
  ## Installation
@@ -115,7 +124,7 @@ Test your app with the full capability of Fastbot for stress testing and finding
115
124
  kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --running-minutes 10 --throttle 200
116
125
  ```
117
126
 
118
- 理解上述选项含义请查看[文档](docs/manual_en.md#launching-kea2)
127
+ To understand the meanings of the options, you can see our [manual](docs/manual_en.md#launching-kea2).
119
128
 
120
129
  > 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).
121
130
 
@@ -178,13 +187,14 @@ In Feature 3, a script is composed of three elements:
178
187
 
179
188
  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).
180
189
 
181
- <div align="center" >
182
- <div >
183
- <img src="docs/socialAppBug.png" style="border-radius: 14px; width:30%; height:40%;"/>
184
- </div>
185
- <p>The expected behavior (the upper figure) and the buggy behavior (the lower figure).
186
- <p/>
190
+ <div align="center">
191
+ <img src="docs/socialAppBug.png" style="border-radius: 14px; width:30%; height:40%;"/>
192
+ </div>
193
+
194
+ <div align="center">
195
+ The expected behavior (the upper figure) and the buggy behavior (the lower figure).
187
196
  </div>
197
+
188
198
 
189
199
  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.
190
200
 
@@ -209,12 +219,12 @@ You can run this example by using the similar command line in Feature 2.
209
219
 
210
220
  ## Documentations(更多文档)
211
221
 
212
- [更多文档](docs/manual_en.md),包括了:
213
- - Kea2的案例教程(基于微信介绍)、
214
- - Kea2脚本的定义方法,支持的脚本装饰器(如`@precondition`、`@prob`、`@max_tries`)
215
- - Kea2的启动方式、命令行选项
216
- - 查看/理解Kea2的运行结果(如界面截图、测试覆盖率、脚本执行成功与否)。
217
- - [如何黑白控件/区域](docs/blacklisting.md)
222
+ You can find the [user manual](docs/manual_en.md), which includes:
223
+ - Examples of using Kea2 on WeChat (in Chinese);
224
+ - How to define Kea2's scripts and use the decorators (e.g., `@precondition`、`@prob`、`@max_tries`);
225
+ - How to run Kea2 and Kea2's command line options
226
+ - How to find and understand Kea2's testing results
227
+ - How to [whitelist or blacklist](docs/blacklisting.md) specific activities, UI widgets and UI regions during fuzzing
218
228
 
219
229
  ## Open-source projects used by Kea2
220
230
 
@@ -1,15 +1,15 @@
1
1
  kea2/__init__.py,sha256=JFJjqgf5KB4bXUFQ3upkEug0cFMFIk9p3OHV9vzulHw,75
2
- kea2/absDriver.py,sha256=X99d-OP77EIiDwTLvWVkgDUtqscoxmWeOb-EcaOPWGI,1294
3
- kea2/adbUtils.py,sha256=j6goAAzV1Ikmv26DZEE0Oi8S1PrejcV1Io3u_Xw4ws4,9910
4
- kea2/bug_report_generator.py,sha256=G5h9nI1w1UaksjF3gkMC8UrXgiNmtU1D5VIuPiciOak,22792
2
+ kea2/absDriver.py,sha256=NzmsLs1Ojz-yEXctGAqj7aKBwAQW19zd83l65RABCe8,1288
3
+ kea2/adbUtils.py,sha256=1t5oxr3CVen2kn4ilPy7lZolnEDawVXAjfDwXJMjBIk,19532
4
+ kea2/bug_report_generator.py,sha256=avpZgUywmUePO1_2dDXBgUkxAAa0gpiTpaDtyjInw7Q,20245
5
5
  kea2/cli.py,sha256=YgWOe5JB0_WBTKyBShBEymhLIqj6K5gNR4Aaj6Pbtn0,2796
6
- kea2/fastbotManager.py,sha256=Ru7Aitcjlem52npJJLg-3KX5ctCoflaaLG4N0IgQ2QU,4828
7
- kea2/keaUtils.py,sha256=XylgzSS4_DcQn3SjbJJ2bA82v0LQV1qmbgZPRjBh-ZE,25932
8
- kea2/kea_launcher.py,sha256=xDMHAzD2Ig2Dug9K4MzkTPwieKvLASmjUahEst8aaVU,5291
6
+ kea2/fastbotManager.py,sha256=DI5jtUEf2ro9I2MNKxw6Oh42nmEjcpLecEMj0IhKZGs,6974
7
+ kea2/keaUtils.py,sha256=yNuEIIWfxTBfApiasKy9eMD-iKeLLH0LKunZbuxL_j8,25595
8
+ kea2/kea_launcher.py,sha256=eV8MvWWRwbhXJ2IaxjSIRL9ZyZF6OKlEeWzAfwkoXLg,5712
9
9
  kea2/logWatcher.py,sha256=qpIsflbP37eX5b4EaWnrqyPbGP9lzQhRr3ainGFfZeI,2211
10
- kea2/resultSyncer.py,sha256=f3qfne8WQCo1AA3cwx9IZzLdenjjMWbEpAqPdvddAqk,1984
11
- kea2/u2Driver.py,sha256=__rP_d5uY029_eAxPNUiNw3lq8PVLf8QZRe3uwZEmb4,15779
12
- kea2/utils.py,sha256=8b4y-_B7knKRN_HqpWZM900IdRiZXwmzQnduVVN0GxQ,1384
10
+ kea2/resultSyncer.py,sha256=9kb3H0Innwj7oPboDDTf97nbjam7EP6HYxywR9B8SvM,2437
11
+ kea2/u2Driver.py,sha256=nRleo-NmKuqgY-_4aiPREDQ2Yw-9yawd9hdslD1RmE4,15539
12
+ kea2/utils.py,sha256=ErMUCwKddA6xETE8xKFI281N6iiVzpDBEhfSZ_JFNGQ,1467
13
13
  kea2/assets/fastbot-thirdpart.jar,sha256=0SZ_OoZFWDGMnazgXKceHgKvXdUDoIa3Gb2bcifaikk,85664
14
14
  kea2/assets/framework.jar,sha256=rTluOJJKj2DFwh7ascXso1udYdWv00BxBwSQ3Vmv-fw,1149240
15
15
  kea2/assets/kea2-thirdpart.jar,sha256=HYdtG2gqDLuLb72dpK3lX-Y6QUNTrJ-bfQopU5aWpfo,359346
@@ -27,10 +27,10 @@ kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so,sha256=tAFrG73pJi7XakRxS
27
27
  kea2/assets/fastbot_libs/armeabi-v7a/libfastbot_native.so,sha256=UV8bhaiPoPKdd3q0vj3kSZqPR9anllai_tz_2QkMMbQ,1335372
28
28
  kea2/assets/fastbot_libs/x86/libfastbot_native.so,sha256=k-aw1gEXRWMKZRNHIggKNuZy0wC1y2BnveJGEIO6rbo,2036856
29
29
  kea2/assets/fastbot_libs/x86_64/libfastbot_native.so,sha256=tiofhlf4uMQcU5WAvrdLgTBME0lb83hVUoGtTwxmE8A,2121416
30
- kea2/templates/bug_report_template.html,sha256=sQ0Uu8SPeOIiyX5vPPTZPVKxh9-9raAZcCjSRS8YFe0,40624
31
- kea2_python-0.1.3.dist-info/licenses/LICENSE,sha256=nM9PPjcsXVo5SzNsjRqWgA-gdJlwqZZcRDSC6Qf6bVE,2034
32
- kea2_python-0.1.3.dist-info/METADATA,sha256=Y2ICVucbBO8JybwZMNKtTQSl_rJdndmKkD4PAVPwQWk,13234
33
- kea2_python-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- kea2_python-0.1.3.dist-info/entry_points.txt,sha256=mFX06TyxXiUAJQ6JZn8QHzfn8n5R8_KJ5W-pTm_fRCA,39
35
- kea2_python-0.1.3.dist-info/top_level.txt,sha256=TsgNH4PQoNOVhegpO7AcjutMVWp6Z4KDL1pBH9FnMmk,5
36
- kea2_python-0.1.3.dist-info/RECORD,,
30
+ kea2/templates/bug_report_template.html,sha256=59KL5rRwGwKs7mNgtiWSSUD_NG_5Cu5Agq4QfydCLt8,37935
31
+ kea2_python-0.2.0.dist-info/licenses/LICENSE,sha256=nM9PPjcsXVo5SzNsjRqWgA-gdJlwqZZcRDSC6Qf6bVE,2034
32
+ kea2_python-0.2.0.dist-info/METADATA,sha256=zszS6ye6p4gYZLscTZdxah8GI3-dowxlEJNKAuRxijg,14023
33
+ kea2_python-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
+ kea2_python-0.2.0.dist-info/entry_points.txt,sha256=mFX06TyxXiUAJQ6JZn8QHzfn8n5R8_KJ5W-pTm_fRCA,39
35
+ kea2_python-0.2.0.dist-info/top_level.txt,sha256=TsgNH4PQoNOVhegpO7AcjutMVWp6Z4KDL1pBH9FnMmk,5
36
+ kea2_python-0.2.0.dist-info/RECORD,,