-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstart.py
executable file
·94 lines (74 loc) · 2.8 KB
/
start.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python -u
# -*- coding: utf-8 -*-
'''
start the test with a role
'''
import os
import time
from device_tools import getDeviceList
from tester import Tester
def _walk():
'''
walk the current folder, when has unique apk and android test apk file, get it
'''
targetApk = None
testApk = None
curPath = os.path.realpath(".")
for fname in os.listdir(curPath):
if fname.endswith(".apk"):
if targetApk is not None and testApk is not None:
raise Exception("have many apk files in this folder: <" + curPath + ">")
if fname.endswith("-androidTest.apk"):
testApk = fname
else:
targetApk = fname
if targetApk is None or testApk is None:
raise Exception("can't found the target apk file(end with .apk) and test apk file(end with -andoridTest.apk) in this folder: <" + curPath + ">")
return [targetApk, testApk]
if __name__ == "__main__":
enters = {
# publish stream
"anchor": "com.zego.livedemo5.startWithAnchor",
# join live or watch only
"audience": "com.zego.livedemo5.startWithPlay",
# test setting combinations
"setting": "com.zego.livedemo5.testSettings",
# run all test case
"test": None
}
import argparse
parse = argparse.ArgumentParser()
parse.add_argument('-a', '--target', action = 'store', type = str, help = "the apk file that will be test")
parse.add_argument('-t', '--test', action = 'store', type = str, help = "android test apk file path")
parse.add_argument('-r', '--role', action = 'store', type = str, choices = enters.keys(), help = "special the start role")
args = parse.parse_args()
enterPkg = enters[args.role]
if args.target and args.test:
targetApk, testApk = args.target, args.test
else:
targetApk, testApk = _walk()
beginTime = time.strftime("%Y%m%d_%H%M%S", time.localtime())
scriptRoot = os.path.split(os.path.realpath(__file__))[0]
resultPath = scriptRoot
try:
resultPath = os.path.join(scriptRoot, beginTime)
os.mkdir(resultPath)
except Exception, e:
resultPath = scriptRoot
print (e)
devices = getDeviceList()
print ("===" * 5 + " device list " + "===" * 5)
print (os.linesep.join(['->'.join(device) for device in devices]))
print ("===" * 14)
threads = []
local_port = 5555
for device in devices:
tester = Tester(targetApk, testApk, enterPkg)
tester.setDevice(device[0], local_port).setOutputPath(resultPath)
t = tester.doRun()
threads.append(t)
local_port += 1
for t in threads:
print ("call %s's join" % t.getName())
t.join()
print ("finish.")