-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.py
36 lines (29 loc) · 1.01 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import subprocess
from sys import argv
import uiautomator2 as u2
def print_info(d):
restart_times = 10
while restart_times >= 0:
try:
# self.d.shell(['pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator.apk'])
print(f"Android emulator info: {d.info}")
return
except (OSError, u2.exceptions.GatewayError, u2.GatewayError) as e:
print("Trying to reinit uiautomator")
p = subprocess.Popen(["python", "-m", "uiautomator2", "init"])
p.wait(60)
restart_times -= 1
print("Unable to start UIAutomator...")
raise Exception("ConnectionRefusedError: Unable to connect to UIAutomator")
def run(my_device: u2.Device, pkg_name):
pass
if __name__ == '__main__':
if len(argv)<3:
print("Please input: (1) emulator id (2) package name")
emulator_id = argv[1]
pkg_name = argv[2]
d = u2.connect(emulator_id)
print_info(d)
d.app_start(pkg_name)
d.app_wait(pkg_name)
run(d, pkg_name)