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 ADDED
@@ -0,0 +1,4 @@
1
+ from .keaUtils import KeaTestRunner, precondition, prob, Options
2
+
3
+ import logging
4
+ logging.basicConfig(level=logging.DEBUG)
kea2/absDriver.py ADDED
@@ -0,0 +1,34 @@
1
+ import abc
2
+
3
+
4
+ class AbstractScriptDriver(abc.ABC):
5
+ @abc.abstractmethod
6
+ def getInstance(self):
7
+ pass
8
+
9
+
10
+ class AbstractStaticChecker(abc.ABC):
11
+ @abc.abstractmethod
12
+ def getInstance(self):
13
+ pass
14
+
15
+ @abc.abstractmethod
16
+ def setHierarchy(hierarchy):
17
+ pass
18
+
19
+
20
+ class AbstractDriver(abc.ABC):
21
+ @classmethod
22
+ @abc.abstractmethod
23
+ def setDeviceSerial(self):
24
+ pass
25
+
26
+ @classmethod
27
+ @abc.abstractmethod
28
+ def getScriptDriver(self) -> AbstractScriptDriver:
29
+ pass
30
+
31
+ @classmethod
32
+ @abc.abstractmethod
33
+ def getStaticChecker(self, hierarchy) -> AbstractStaticChecker:
34
+ pass
kea2/adbUtils.py ADDED
@@ -0,0 +1,258 @@
1
+ import subprocess
2
+ from typing import List, Optional
3
+
4
+ def run_adb_command(cmd: List[str], timeout=10):
5
+ """
6
+ Runs an adb command and returns its output.
7
+
8
+ Parameters:
9
+ cmd (list): List of adb command arguments, e.g., ["devices"].
10
+ timeout (int): Timeout in seconds.
11
+
12
+ Returns:
13
+ str: The standard output from the command. If an error occurs, returns None.
14
+ """
15
+ full_cmd = ["adb"] + cmd
16
+ try:
17
+ result = subprocess.run(full_cmd, capture_output=True, text=True, timeout=timeout)
18
+ if result.returncode != 0:
19
+ print(f"Command failed: {' '.join(full_cmd)}\nError: {result.stderr}", flush=True)
20
+ return "\n".join([
21
+ result.stdout.strip(),
22
+ result.stderr.strip()
23
+ ])
24
+ except subprocess.TimeoutExpired:
25
+ print(f"Command timed out: {' '.join(full_cmd)}", flush=True)
26
+ return None
27
+
28
+ def get_devices():
29
+ """
30
+ Retrieves the list of connected Android devices.
31
+
32
+ Returns:
33
+ list: A list of device serial numbers.
34
+ """
35
+ output = run_adb_command(["devices"])
36
+ devices = []
37
+ if output:
38
+ lines = output.splitlines()
39
+ # The first line is usually "List of devices attached". The following lines list individual devices.
40
+ for line in lines[1:]:
41
+ if line.strip():
42
+ parts = line.split()
43
+ if len(parts) >= 2 and parts[1] == "device":
44
+ devices.append(parts[0])
45
+ return devices
46
+
47
+ def ensure_device(func):
48
+ """
49
+ A decorator that resolves the device parameter automatically if it's not provided.
50
+
51
+ If 'device' is None or not present in the keyword arguments and only one device is connected,
52
+ that device will be automatically used. If no devices are connected or multiple devices are
53
+ connected, it raises a RuntimeError.
54
+ """
55
+ def wrapper(*args, **kwargs):
56
+ devices = get_devices()
57
+ if kwargs.get("device") is None:
58
+ if not devices:
59
+ raise RuntimeError("No connected devices.")
60
+ if len(devices) > 1:
61
+ raise RuntimeError("Multiple connected devices detected. Please specify a device.")
62
+ kwargs["device"] = devices[0]
63
+ if kwargs["device"] not in devices:
64
+ output = run_adb_command(["-s", kwargs["device"], "get-state"])
65
+ if output.strip() != "device":
66
+ raise RuntimeError(f"[ERROR] {kwargs['device']} not connected. Please check.\n{output}")
67
+ return func(*args, **kwargs)
68
+ return wrapper
69
+
70
+ @ensure_device
71
+ def adb_shell(cmd: List[str], device:Optional[str]=None):
72
+ """
73
+ run adb shell commands
74
+
75
+ Parameters:
76
+ cmd (List[str])
77
+ device (str, optional): The device serial number. If None, it's resolved automatically when only one device is connected.
78
+ """
79
+ return run_adb_command(["-s", device, "shell"] + cmd)
80
+
81
+
82
+ @ensure_device
83
+ def install_app(apk_path: str, device: Optional[str]=None):
84
+ """
85
+ Installs an APK application on the specified device.
86
+
87
+ Parameters:
88
+ apk_path (str): The local path to the APK file.
89
+ device (str, optional): The device serial number. If None, it's resolved automatically when only one device is connected.
90
+
91
+ Returns:
92
+ str: The output from the install command.
93
+ """
94
+ return run_adb_command(["-s", device, "install", apk_path])
95
+
96
+
97
+ @ensure_device
98
+ def uninstall_app(package_name: str, device: Optional[str] = None):
99
+ """
100
+ Uninstalls an app from the specified device.
101
+
102
+ Parameters:
103
+ package_name (str): The package name of the app.
104
+ device (str, optional): The device serial number. If None, it's resolved automatically when only one device is connected.
105
+
106
+ Returns:
107
+ str: The output from the uninstall command.
108
+ """
109
+ return run_adb_command(["-s", device, "uninstall", package_name])
110
+
111
+
112
+ @ensure_device
113
+ def push_file(local_path: str, remote_path: str, device: Optional[str] = None):
114
+ """
115
+ Pushes a file to the specified device.
116
+
117
+ Parameters:
118
+ local_path (str): The local file path.
119
+ remote_path (str): The destination path on the device.
120
+ device (str, optional): The device serial number. If None, it's resolved automatically when only one device is connected.
121
+
122
+ Returns:
123
+ str: The output from the push command.
124
+ """
125
+ local_path = str(local_path)
126
+ remote_path = str(remote_path)
127
+ return run_adb_command(["-s", device, "push", local_path, remote_path])
128
+
129
+
130
+ @ensure_device
131
+ def pull_file(remote_path: str, local_path: str, device: Optional[str] = None):
132
+ """
133
+ Pulls a file from the device to a local path.
134
+
135
+ Parameters:
136
+ remote_path (str): The file path on the device.
137
+ local_path (str): The local destination path.
138
+ device (str, optional): The device serial number. If None, it's resolved automatically when only one device is connected.
139
+
140
+ Returns:
141
+ str: The output from the pull command.
142
+ """
143
+ return run_adb_command(["-s", device, "pull", remote_path, local_path])
144
+
145
+
146
+ # Forward-related functions
147
+
148
+
149
+ @ensure_device
150
+ def list_forwards(device: Optional[str] = None):
151
+ """
152
+ Lists current port forwarding rules on the specified device.
153
+
154
+ Parameters:
155
+ device (str, optional): The device serial number. If None, it is resolved automatically.
156
+
157
+ Returns:
158
+ list: A list of forwarding rules. Each rule is a dictionary with keys: device, local, remote.
159
+ """
160
+ output = run_adb_command(["-s", device, "forward", "--list"])
161
+ forwards = []
162
+ if output:
163
+ lines = output.splitlines()
164
+ for line in lines:
165
+ parts = line.split()
166
+ if len(parts) == 3:
167
+ # Each line is expected to be: <device> <local> <remote>
168
+ rule = {"device": parts[0], "local": parts[1], "remote": parts[2]}
169
+ if rule["device"] == device:
170
+ forwards.append(rule)
171
+ else:
172
+ forwards.append(line)
173
+ return forwards
174
+
175
+
176
+ @ensure_device
177
+ def create_forward(local_spec: str, remote_spec: str, device: Optional[str] = None):
178
+ """
179
+ Creates a port forwarding rule on the specified device.
180
+
181
+ Parameters:
182
+ local_spec (str): The local forward specification (e.g., "tcp:8000").
183
+ remote_spec (str): The remote target specification (e.g., "tcp:9000").
184
+ device (str, optional): The device serial number. If None, it is resolved automatically.
185
+
186
+ Returns:
187
+ str: The output from the forward creation command.
188
+ """
189
+ return run_adb_command(["-s", device, "forward", local_spec, remote_spec])
190
+
191
+
192
+ @ensure_device
193
+ def remove_forward(local_spec, device: Optional[str] = None):
194
+ """
195
+ Removes a specific port forwarding rule on the specified device.
196
+
197
+ Parameters:
198
+ local_spec (str): The local forward specification to remove (e.g., "tcp:8000").
199
+ device (str, optional): The device serial number. If None, it is resolved automatically.
200
+
201
+ Returns:
202
+ str: The output from the forward removal command.
203
+ """
204
+ return run_adb_command(["-s", device, "forward", "--remove", local_spec])
205
+
206
+
207
+ @ensure_device
208
+ def remove_all_forwards(device: Optional[str] = None):
209
+ """
210
+ Removes all port forwarding rules on the specified device.
211
+
212
+ Parameters:
213
+ device (str, optional): The device serial number. If None, it is resolved automatically.
214
+
215
+ Returns:
216
+ str: The output from the command to remove all forwards.
217
+ """
218
+ return run_adb_command(["-s", device, "forward", "--remove-all"])
219
+
220
+
221
+ if __name__ == '__main__':
222
+ # For testing: print the list of currently connected devices.
223
+ devices = get_devices()
224
+ if devices:
225
+ print("Connected devices:", flush=True)
226
+ for dev in devices:
227
+ print(f" - {dev}", flush=True)
228
+ else:
229
+ print("No devices connected.", flush=True)
230
+
231
+ # Example usage of forward-related functionalities:
232
+ try:
233
+ # List current forwards
234
+ forwards = list_forwards()
235
+ print("Current forward rules:", flush=True)
236
+ for rule in forwards:
237
+ print(rule, flush=True)
238
+
239
+ # Create a forward rule (example: forward local tcp 8000 to remote tcp 9000)
240
+ output = create_forward("tcp:8000", "tcp:9000")
241
+ print("Create forward output:", output, flush=True)
242
+
243
+ # List forwards again
244
+ forwards = list_forwards()
245
+ print("Forward rules after creation:", flush=True)
246
+ for rule in forwards:
247
+ print(rule, flush=True)
248
+
249
+ # Remove the forward rule
250
+ output = remove_forward("tcp:8000")
251
+ print("Remove forward output:", output, flush=True)
252
+
253
+ # Remove all forwards (if needed)
254
+ # output = remove_all_forwards()
255
+ # print("Remove all forwards output:", output)
256
+
257
+ except RuntimeError as e:
258
+ print("Error:", e, flush=True)
Binary file
@@ -0,0 +1,2 @@
1
+ com.ss.android.xxx.DManageActivity
2
+ com.bytedance.xxxx.DebuggerPanelActivity
@@ -0,0 +1,3 @@
1
+ com.ss.android.xxx.NewActivity
2
+ com.ss.android.xxx.MusicActivity
3
+ com.ss.android.xxx.DetailListActivity
@@ -0,0 +1,7 @@
1
+ max.randomPickFromStringList = false
2
+ max.takeScreenshot = false
3
+ max.takeScreenshotForEveryStep = false
4
+ max.saveGUITreeToXmlEveryStep =false
5
+ max.execSchema = true
6
+ max.execSchemaEveryStartup = true
7
+ max.grantAllPermission = true