Kea2-python 0.0.1a2__py3-none-any.whl → 0.0.1a4__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/absDriver.py CHANGED
@@ -2,12 +2,24 @@ import abc
2
2
 
3
3
 
4
4
  class AbstractScriptDriver(abc.ABC):
5
+ _instances = {}
6
+ def __new__(cls, *args, **kwargs):
7
+ if cls not in cls._instances:
8
+ cls._instances[cls] = super().__new__(cls)
9
+ return cls._instances[cls]
10
+
5
11
  @abc.abstractmethod
6
12
  def getInstance(self):
7
13
  pass
8
14
 
9
15
 
10
16
  class AbstractStaticChecker(abc.ABC):
17
+ _instances = {}
18
+ def __new__(cls, *args, **kwargs):
19
+ if cls not in cls._instances:
20
+ cls._instances[cls] = super().__new__(cls)
21
+ return cls._instances[cls]
22
+
11
23
  @abc.abstractmethod
12
24
  def getInstance(self):
13
25
  pass
@@ -18,6 +30,12 @@ class AbstractStaticChecker(abc.ABC):
18
30
 
19
31
 
20
32
  class AbstractDriver(abc.ABC):
33
+ _instances = {}
34
+ def __new__(cls, *args, **kwargs):
35
+ if cls not in cls._instances:
36
+ cls._instances[cls] = super().__new__(cls)
37
+ return cls._instances[cls]
38
+
21
39
  @classmethod
22
40
  @abc.abstractmethod
23
41
  def setDeviceSerial(self):
kea2/assets/quickstart.py CHANGED
@@ -76,7 +76,9 @@ def check_installation():
76
76
  def _get_agent():
77
77
  import sys
78
78
  if len(sys.argv) == 0 or sys.argv[1] == "u2":
79
+ sys.argv=sys.argv[:1]
79
80
  return "u2"
81
+ sys.argv=sys.argv[:1]
80
82
  return "native"
81
83
 
82
84
  if __name__ == "__main__":
kea2/cli.py CHANGED
@@ -156,16 +156,14 @@ def main():
156
156
  kwargs.pop('args', None)
157
157
  sp.add_argument(*args, **kwargs)
158
158
 
159
- from .kea_launcher import _set_driver_parser
160
- _set_driver_parser(subparser)
159
+ from .kea_launcher import _set_runner_parser
160
+ _set_runner_parser(subparser)
161
161
  actions["run"] = cmd_run
162
162
  if sys.argv[1:] == ["run"]:
163
163
  sys.argv.append("-h")
164
164
  args = parser.parse_args()
165
165
 
166
166
  import logging
167
- logging.getLogger("urllib3").setLevel(logging.INFO)
168
- logging.getLogger("uiautomator2").setLevel(logging.INFO)
169
167
  if args.debug:
170
168
  logging.basicConfig(level=logging.DEBUG)
171
169
  logger.debug("args: %s", args)
kea2/keaUtils.py CHANGED
@@ -3,6 +3,7 @@ import os
3
3
  from pathlib import Path
4
4
  import subprocess
5
5
  import threading
6
+ import traceback
6
7
  from typing import IO, Callable, Any, Dict, List, Literal, NewType, Optional, Union
7
8
  from unittest import TextTestRunner, registerResult, TestSuite, TestCase, TextTestResult
8
9
  import random
@@ -93,6 +94,8 @@ class Options:
93
94
  running_mins: int = 10
94
95
  # time(ms) to wait when exploring the app
95
96
  throttle: int = 200
97
+ # the output_dir for saving logs and results
98
+ output_dir: str = "output"
96
99
 
97
100
 
98
101
  @dataclass
@@ -260,6 +263,13 @@ class KeaTestRunner(TextTestRunner):
260
263
  options.Driver = None
261
264
  cls.options = options
262
265
 
266
+ def _setOuputDir(self):
267
+ output_dir = Path(self.options.output_dir).absolute()
268
+ os.mkdir(output_dir, parents=True, exist_ok=True)
269
+ global LOGFILE, RESFILE
270
+ LOGFILE = output_dir / Path(LOGFILE)
271
+ RESFILE = output_dir / Path(RESFILE)
272
+
263
273
  def run(self, test):
264
274
 
265
275
  self.allProperties = dict()
@@ -268,6 +278,8 @@ class KeaTestRunner(TextTestRunner):
268
278
  if len(self.allProperties) == 0:
269
279
  print("[Warning] No property has been found.", flush=True)
270
280
 
281
+ self._setOuputDir()
282
+
271
283
  JsonResult.setProperties(self.allProperties)
272
284
  self.resultclass = JsonResult
273
285
 
@@ -442,7 +454,13 @@ class KeaTestRunner(TextTestRunner):
442
454
  # Dependency injection. Static driver checker for precond
443
455
  setattr(test, self.options.driverName, staticCheckerDriver)
444
456
  # excecute the precond
445
- if not precond(test):
457
+ try:
458
+ if not precond(test):
459
+ valid = False
460
+ break
461
+ except Exception as e:
462
+ print(f"[ERROR] Error when checking precond: {getFullPropName(test)}", flush=True)
463
+ traceback.print_exc()
446
464
  valid = False
447
465
  break
448
466
  # if all the precond passed. make it the candidate prop.
kea2/kea_launcher.py CHANGED
@@ -1,9 +1,11 @@
1
+ import os
1
2
  import sys
2
3
  import argparse
3
4
  import unittest
5
+ from pathlib import Path
4
6
  from typing import List
5
7
 
6
- def _set_driver_parser(subparsers: "argparse._SubParsersAction[argparse.ArgumentParser]"):
8
+ def _set_runner_parser(subparsers: "argparse._SubParsersAction[argparse.ArgumentParser]"):
7
9
  parser = subparsers.add_parser("run", help="run kea2")
8
10
  parser.add_argument(
9
11
  "-s",
@@ -23,6 +25,16 @@ def _set_driver_parser(subparsers: "argparse._SubParsersAction[argparse.Argument
23
25
  help="The target package names com.example.app",
24
26
  )
25
27
 
28
+ parser.add_argument(
29
+ "-o",
30
+ "--output-dir",
31
+ dest="output_dir",
32
+ type=str,
33
+ required=False,
34
+ default="output",
35
+ help="The output dir for saving logs and results."
36
+ )
37
+
26
38
  parser.add_argument(
27
39
  "--agent",
28
40
  dest="agent",
@@ -96,7 +108,7 @@ def parse_args(argv: List):
96
108
  parser = argparse.ArgumentParser(description="Kea2")
97
109
  subparsers = parser.add_subparsers(dest="command", required=True)
98
110
 
99
- _set_driver_parser(subparsers)
111
+ _set_runner_parser(subparsers)
100
112
  args = parser.parse_args(argv)
101
113
  return args
102
114
 
kea2/u2Driver.py CHANGED
@@ -12,6 +12,10 @@ from .utils import TimeStamp
12
12
 
13
13
  TIME_STAMP = TimeStamp().getTimeStamp()
14
14
 
15
+ import logging
16
+ logging.getLogger("urllib3").setLevel(logging.INFO)
17
+ logging.getLogger("uiautomator2").setLevel(logging.INFO)
18
+
15
19
  """
16
20
  The definition of U2ScriptDriver
17
21
  """
@@ -29,13 +33,11 @@ class U2ScriptDriver(AbstractScriptDriver):
29
33
  """
30
34
 
31
35
  deviceSerial: str = None
32
-
36
+ d = None
37
+
33
38
  @classmethod
34
39
  def setDeviceSerial(cls, deviceSerial):
35
40
  cls.deviceSerial = deviceSerial
36
-
37
- def __init__(self):
38
- self.d = None
39
41
 
40
42
  def getInstance(self):
41
43
  if self.d is None:
@@ -117,7 +119,7 @@ class StaticU2UiObject(u2.UiObject):
117
119
 
118
120
  @property
119
121
  def exists(self):
120
- dict.update(self.selector, {"covered": "true"})
122
+ dict.update(self.selector, {"covered": "false"})
121
123
  xpath = self._getXPath(self.selector)
122
124
  matched_widgets = self.session.xml.xpath(xpath)
123
125
  return bool(matched_widgets)
@@ -205,9 +207,11 @@ class _HindenWidgetFilter:
205
207
  )
206
208
  self._nodes.append(e)
207
209
 
210
+
208
211
  class U2StaticDevice(u2.Device):
209
- def __init__(self):
212
+ def __init__(self, script_driver):
210
213
  self.xml: etree._Element = None
214
+ self._script_driver = script_driver
211
215
 
212
216
  def __call__(self, **kwargs):
213
217
  return StaticU2UiObject(session=self, selector=u2.Selector(**kwargs))
@@ -222,6 +226,10 @@ class U2StaticDevice(u2.Device):
222
226
  get_page_source, xpathEntry
223
227
  )
224
228
  return xpathEntry
229
+
230
+ def __getattr__(self, attr):
231
+ """Proxy other methods to script_driver"""
232
+ return getattr(self._script_driver, attr)
225
233
 
226
234
  class _XPathEntry(u2.xpath.XPathEntry):
227
235
  def __init__(self, d):
@@ -246,7 +254,7 @@ class U2StaticChecker(AbstractStaticChecker):
246
254
  ```
247
255
  """
248
256
  def __init__(self):
249
- self.d = U2StaticDevice()
257
+ self.d = U2StaticDevice(U2ScriptDriver().getInstance())
250
258
 
251
259
  def setHierarchy(self, hierarchy: str):
252
260
  if hierarchy is None:
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Kea2-python
3
- Version: 0.0.1a2
3
+ Version: 0.0.1a4
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
- Requires-Python: >=3.9
6
+ Requires-Python: >=3.8
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
- Requires-Dist: rtree>=1.4.0
9
+ Requires-Dist: rtree>=1.3.0
10
10
  Requires-Dist: uiautomator2>=3.2.9
11
11
  Dynamic: license-file
12
12
 
13
13
  # Introduction
14
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.
15
+ Kea2 is an easy-to-use Python library for supporting, customizing and improving 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
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*);
@@ -27,7 +27,7 @@ These three features can be combined to customize and improve automated UI testi
27
27
  </div>
28
28
  </div>
29
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.
30
+ > Kea2 is designed to be capable of fusing the (property-based) *scripts* (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
31
 
32
32
  **The ability of the three features in Kea2**
33
33
  | | **Feature 1** | **Feature 2** | **Feature 3** |
@@ -52,7 +52,7 @@ In the future, Kea2 will be extended to support
52
52
 
53
53
  Running requirements/environment:
54
54
  - support Windows, MacOS and Linux
55
- - python 3.9+
55
+ - python 3.8+
56
56
  - Android SDK installed
57
57
  - **VPN closed** (Features 2 and 3 required)
58
58
 
@@ -99,7 +99,7 @@ kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent native --
99
99
  ```
100
100
 
101
101
  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.
102
- See more options by `python kea_launcher.py driver -h`
102
+ See more options by `kea2 run -h`
103
103
 
104
104
 
105
105
  ## Feature 2(自定义测试场景或事件序列): customizing testing scenarios by scripts
@@ -153,14 +153,13 @@ You can find the full example in script `quickstart.py` and run it by executing:
153
153
  python3 quickstart.py u2
154
154
  ```
155
155
 
156
+ In real use, you can use `kea2 run` to launch the customizing script.
157
+
156
158
  ```bash
157
159
  # Launch Kea2 and load one single script quickstart.py.
158
- kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest quickstart.py
160
+ kea2 run -s "emulator-5554" -p it.feio.android.omninotes.alpha --agent u2 --running-minutes 10 --throttle 200 --driver-name d unittest discover -p quickstart.py
159
161
  ```
160
162
 
161
-
162
-
163
-
164
163
  ## Feature 3(支持断言机制): Supporting auto-assertions by scripts.
165
164
 
166
165
  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).
@@ -1,16 +1,16 @@
1
1
  kea2/__init__.py,sha256=_IFDiyzb6OLyhjldBXrAol6OpOijTnJ2LYWMK4TqSno,121
2
- kea2/absDriver.py,sha256=1vXTkPqhhIosT8KpS6pwi7XKjNZTOuSb7mczhS_tMoQ,648
2
+ kea2/absDriver.py,sha256=M08ba0kpIer20ApMhX7yCmcLrfPb6a3udZxR_4FhriI,1224
3
3
  kea2/adbUtils.py,sha256=IV-5G_3mc89YP1NJZJIWUrgxb13QECGGXTTANkGH_Rk,8986
4
- kea2/cli.py,sha256=yTBmWUKi0onIWATV5uccwnItySwxFFUtewOiBEjQZAs,4466
5
- kea2/keaUtils.py,sha256=KF00-qf_R8-hk221uKJJi64TdOOKnSINeQrVWKzCN3Y,19452
6
- kea2/kea_launcher.py,sha256=pBjV3Hxv3Sh9MXiV50Afahcb3ebgoY0JQhRTCekOMRU,3916
4
+ kea2/cli.py,sha256=V_TOe-weqc-LvYmf3hGnm5W3_-aa1_swo3rKhOEib4o,4349
5
+ kea2/keaUtils.py,sha256=6ZQIrjhH6rBi9mFUO3qJqRJD42i39nkqlq7D-Z4b5vQ,20126
6
+ kea2/kea_launcher.py,sha256=m58wi1_L4TrvSjIhkYDNVHljBixXoRe7oUvu59rjBtM,4175
7
7
  kea2/logWatcher.py,sha256=hd8banPiCa6aCQ6d_MznWKOdzK_A2X_dPbrx-usjxgE,1927
8
- kea2/u2Driver.py,sha256=dfvSapHL9LMyiSlFUCZMNI-G5usapqzGvaFu_lWv-s0,10193
8
+ kea2/u2Driver.py,sha256=NE7Q6OUB9DtoLueZO7ruZoRE3Wp0dp_-R4QHRDLaBvE,10507
9
9
  kea2/utils.py,sha256=zjuoVwts2qVX9GnTaPoiqarfcSvyfW6cAD3ESf_dmrQ,1284
10
10
  kea2/assets/fastbot-thirdpart.jar,sha256=0SZ_OoZFWDGMnazgXKceHgKvXdUDoIa3Gb2bcifaikk,85664
11
11
  kea2/assets/framework.jar,sha256=rTluOJJKj2DFwh7ascXso1udYdWv00BxBwSQ3Vmv-fw,1149240
12
12
  kea2/assets/monkeyq.jar,sha256=TjszvflvE59ev9RhVhkfS_0L46VYZbL2wvpKRyA8ZMk,460366
13
- kea2/assets/quickstart.py,sha256=UeX_SIi_iEN9lzqit7dR1vSxA57fQ9ioCsBOSfzmkCY,3012
13
+ kea2/assets/quickstart.py,sha256=pHFMEki0XZ05ZI056sXS2LMJ3fuzJHS8UGz1NBQ4AVQ,3068
14
14
  kea2/assets/u2.jar,sha256=G9fFf-AZ0CdaZrk27V1-pfJE2Y5eO6PRzPShTnIe-U8,3746525
15
15
  kea2/assets/fastbot_configs/ADBKeyBoard.apk,sha256=L3Kva4gCQALo10EzinCvHrIbffGE3p94qSNbnS8CxP0,163634
16
16
  kea2/assets/fastbot_configs/abl.strings,sha256=Rn8_YEbVGOJqndIY_-kWnR5NaoFI-cuB-ij10Ddhl90,75
@@ -25,9 +25,9 @@ kea2/assets/fastbot_libs/arm64-v8a/libfastbot_native.so,sha256=dA2Tf74-gDrCFdeCl
25
25
  kea2/assets/fastbot_libs/armeabi-v7a/libfastbot_native.so,sha256=GWcL8M8WfQAd9CfOM6pRYbOnxeycN-LiL7Mf59YIadE,1334420
26
26
  kea2/assets/fastbot_libs/x86/libfastbot_native.so,sha256=k-aw1gEXRWMKZRNHIggKNuZy0wC1y2BnveJGEIO6rbo,2036856
27
27
  kea2/assets/fastbot_libs/x86_64/libfastbot_native.so,sha256=tiofhlf4uMQcU5WAvrdLgTBME0lb83hVUoGtTwxmE8A,2121416
28
- kea2_python-0.0.1a2.dist-info/licenses/LICENSE,sha256=nM9PPjcsXVo5SzNsjRqWgA-gdJlwqZZcRDSC6Qf6bVE,2034
29
- kea2_python-0.0.1a2.dist-info/METADATA,sha256=q4kT2cBZftSN2DmR966S-YvswbBuwJq6yX9j_ELrK2c,19032
30
- kea2_python-0.0.1a2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
31
- kea2_python-0.0.1a2.dist-info/entry_points.txt,sha256=mFX06TyxXiUAJQ6JZn8QHzfn8n5R8_KJ5W-pTm_fRCA,39
32
- kea2_python-0.0.1a2.dist-info/top_level.txt,sha256=TsgNH4PQoNOVhegpO7AcjutMVWp6Z4KDL1pBH9FnMmk,5
33
- kea2_python-0.0.1a2.dist-info/RECORD,,
28
+ kea2_python-0.0.1a4.dist-info/licenses/LICENSE,sha256=nM9PPjcsXVo5SzNsjRqWgA-gdJlwqZZcRDSC6Qf6bVE,2034
29
+ kea2_python-0.0.1a4.dist-info/METADATA,sha256=jPLHS0mfjMj1RxQY1dKuvGnm7dsc7Z2fTunhz3WLwsk,19100
30
+ kea2_python-0.0.1a4.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
31
+ kea2_python-0.0.1a4.dist-info/entry_points.txt,sha256=mFX06TyxXiUAJQ6JZn8QHzfn8n5R8_KJ5W-pTm_fRCA,39
32
+ kea2_python-0.0.1a4.dist-info/top_level.txt,sha256=TsgNH4PQoNOVhegpO7AcjutMVWp6Z4KDL1pBH9FnMmk,5
33
+ kea2_python-0.0.1a4.dist-info/RECORD,,