-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrobot_mutil_test.py
206 lines (180 loc) · 7.75 KB
/
robot_mutil_test.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#coding=utf-8
import multiprocessing
from time import ctime,sleep
import os
import sys
from run_server import get_info,mange_server
reload(sys)
sys.setdefaultencoding('utf-8')
def run(arg):
os.system(str(arg))
lprocess = []
ipaddr=get_info.get_ip()
wdhost="http://{0}:".format(ipaddr)
osplat=get_info.get_plat()
arglist=sys.argv
if "-h" in arglist:
outstr='''
how to use it
-h help
-s the testsuite or testcase path
-t taglist,likes "tag1,tag2", split by ,
-o the device os.likes ios,android
-r the remoteurl,use for gird
-p server port
-sp second server port
'''
print outstr
sys.exit(0)
if "-s" in arglist:
testsuite=arglist[arglist.index('-s')+1]
else:
print "you should select the testsuite!"
sys.exit(0)
if "-t" in arglist:
tags=arglist[arglist.index('-t')+1]
else:
print "if you want to run test by mutil,you can input like this : -t node1,node2"
tags=[]
if "-o" in arglist:
testos=arglist[arglist.index('-o')+1]
else:
print "you should input the true args likes: -o ios"
sys.exit(0)
if "-d" in arglist:
startd=arglist[arglist.index('-d')+1]
else:
startd=1
if "-p" in arglist:
aport=int(arglist[arglist.index('-p')+1])
iport=int(arglist[arglist.index('-p')+1])
else:
aport=4723
iport=14723
if "-sp" in arglist:
bport=int(arglist[arglist.index('-sp')+1])
wport=int(arglist[arglist.index('-sp')+1])
else:
bport=5723
wport=8101
if "-r" in arglist:
remoteurl=arglist[arglist.index('-r')+1]
else:
remoteurl='None'
taglist=tags.split(',')
#if len(tags)==0:
# cmd='pybot -o .\\resultDir\\output.xml -l .\\resultDir\\log.html -r .\\resultDir\\report.html --variable remote_url:{1} {0}'.format(testsuite,remoteurl)
# p=multiprocessing.Process(target=run,args=(cmd,))
# lprocess.append(p)
if testos in ["iOS","ios"]:
i=0
sd=int(startd)-1
divtmp=get_info.get_devices("iOS")
divlist=divtmp[sd:]
for tag in taglist:
wdport=wdhost+str(iport)+"/wd/hub"
#print wdport
booll=mange_server.check(ipaddr,iport)
if booll==0:
print "the appium server by {0} is not start,please check it".format(wdport)
sys.exit(0)
cmd='pybot -i {0} -o ./resultDir_ios/output-{0}.xml -l ./resultDir_ios/log-{0}.html -r ./resultDir_ios/report-{0}.html --variable remote_url:{2} --variable udid:{3} {1}'.format(tag,testsuite,wdport,divlist[i])
p=multiprocessing.Process(target=run,args=(cmd,))
lprocess.append(p)
iport=iport+1
i=i+1
elif testos in ["Android","android"]:
i=0
sd=int(startd)-1
divtmp=get_info.get_devices("Android")
divlist=divtmp[sd:]
for tag in taglist:
wdport=wdhost+str(aport)+"/wd/hub"
#print wdport
booll = mange_server.check(ipaddr, aport)
if booll == 0:
print "the appium server by {0} is not start,please check it".format(wdport)
sys.exit(0)
if osplat!="Windows":
cmd='pybot -i {0} -o ./resultDir_ad/output-{0}.xml -l ./resultDir_ad/log-{0}.html -r ./resultDir_ad/report-{0}.html --variable remote_url:{2} --variable udid:{3} {1}'.format(tag,testsuite,wdport,divlist[i])
else:
cmd='pybot -i {0} -o .\\resultDir_ad\\output-{0}.xml -l .\\resultDir_ad\\log-{0}.html -r .\\resultDir_ad\\report-{0}.html --variable remote_url:{2} --variable udid:{3} {1}'.format(tag,testsuite,wdport,divlist[i])
p=multiprocessing.Process(target=run,args=(cmd,))
lprocess.append(p)
aport=aport+1
i=i+1
elif testos in ["Web","web"]:
if remoteurl=='None':
print "if you want to run web mutil test by the tool,print input the sele-grid url!"
sys.exit(0)
elif mange_server.check_grid(remoteurl)==0:
print "the sele-grid url is not work,please check it!"
sys.exit(0)
else:
remoteurl=remoteurl+'/wd/hub'
for tag in taglist:
if osplat!="Windows":
if tag in ['Local','local']:
cmd='pybot -i {0} -o ./resultDir_web/output-{0}.xml -l ./resultDir_web/log-{0}.html -r ./resultDir_web/report-{0}.html --variable remote_url:{2} {1}'.format(tag,testsuite,'None')
else:
cmd='pybot -i {0} -o ./resultDir_web/output-{0}.xml -l ./resultDir_web/log-{0}.html -r ./resultDir_web/report-{0}.html --variable remote_url:{2} {1}'.format(tag,testsuite,remoteurl)
else:
if tag in ['Local','local']:
cmd='pybot -i {0} -o .\\resultDir_web\\output-{0}.xml -l .\\resultDir_web\\log-{0}.html -r .\\resultDir_web\\report-{0}.html --variable remote_url:{2} {1}'.format(tag,testsuite,'None')
else:
cmd='pybot -i {0} -o .\\resultDir_web\\output-{0}.xml -l .\\resultDir_web\\log-{0}.html -r .\\resultDir_web\\report-{0}.html --variable remote_url:{2} {1}'.format(tag,testsuite,remoteurl)
p=multiprocessing.Process(target=run,args=(cmd,))
lprocess.append(p)
elif testos in ["Api","api"]:
for tag in taglist:
if osplat!="Windows":
cmd='pybot -i {0} -o ./resultDir_api/output-{0}.xml -l ./resultDir_web/log-{0}.html -r ./resultDir_web/report-{0}.html {1}'.format(tag,testsuite)
else:
cmd='pybot -i {0} -o .\\resultDir_api\\output-{0}.xml -l .\\resultDir_api\\log-{0}.html -r .\\resultDir_api\\report-{0}.html --variable {1}'.format(tag,testsuite)
p=multiprocessing.Process(target=run,args=(cmd,))
lprocess.append(p)
else:
print "please input true args!"
sys.exit(0)
if __name__ == '__main__':
if osplat!="Windows":
if testos in ["iOS","ios"]:
os.system('rm -rf resultDir_ios/*')
elif testos in ["Android","android"]:
os.system('rm -rf resultDir_ad/*')
elif testos in ["Api","api"]:
os.system('rm -rf resultDir_api/*')
else:
os.system('rm -rf resultDir_web/*')
else:
if testos in ["Android","android"]:
os.system('del /f/s/q/a .\\resultDir_ad\\*')
elif testos in ["Api","api"]:
os.system('del /f/s/q/a .\\resultDir_api\\*')
else:
os.system('del /f/s/q/a .\\resultDir_web\\*')
for p in lprocess:
p.daemon = True
p.start()
for p in lprocess:
p.join()
if osplat!="Windows":
sleep(2)
if testos in ["iOS","ios"]:
os.system(u"rebot --output ./resultDir_ios/output.xml -l ./resultDir_ios/log.html -r ./resultDir_ios/report.html --merge ./resultDir_ios/output-*.xml")
elif testos in ["Android","android"]:
os.system(u"rebot --output ./resultDir_ad/output.xml -l ./resultDir_ad/log.html -r ./resultDir_ad/report.html --merge ./resultDir_ad/output-*.xml")
elif testos in ["Api","api"]:
os.system(u"rebot --output ./resultDir_api/output.xml -l ./resultDir_api/log.html -r ./resultDir_api/report.html --merge ./resultDir_ad\pi/output-*.xml")
else:
os.system(u"rebot --output ./resultDir_web/output.xml -l ./resultDir_web/log.html -r ./resultDir_web/report.html --merge ./resultDir_web/output-*.xml")
else:
sleep(2)
if testos in ["Android","android"]:
os.system(u"rebot --output .\\resultDir_ad\\output.xml -l .\\resultDir_ad\\log.html -r .\\resultDir_ad\\report.html --merge .\\resultDir_ad\\output-*.xml")
elif testos in ["Api","api"]:
os.system(u"rebot --output .\\resultDir_api\\output.xml -l .\\resultDir_api\\log.html -r .\\resultDir_api\\report.html --merge .\\resultDir_api\\output-*.xml")
else:
os.system(u"rebot --output .\\resultDir_web\\output.xml -l .\\resultDir_web\\log.html -r .\\resultDir_web\\report.html --merge .\\resultDir_web\\output-*.xml")
sleep(2)
print "Test Finish"