Airtest多设备跑
一. 一个脚本对应一台设备
核心点:组织运行命令;将组织好的命令传到pool进程池(注意:是进程池,不是线程池,python的线程池不是同步执行,是按序执行)
以下不需要看,为私人项目备份目的。
run_mul.py 代码如下:
# -*- encoding=utf8 -*-
from airtest.core.android.adb import ADB
from multiprocessing.pool import Pool
import os
def get_all_dir():
"""
:return: 获得所有的文件夹
"""
cur_dir = os.path.dirname(os.path.realpath(__file__))
dirs_ls = []
for dirs in os.listdir(cur_dir):
isdir = os.path.join(cur_dir, dirs)
if os.path.isdir(isdir):
dirs_ls.append(isdir)
return dirs_ls
def create_dic_data():
"""
:return: [{"dev":"","login.air":"","NEXT.air":""},]
"""
ls = []
devicess = ADB().devices()
# print(devicess)
if len(devicess) == len(get_all_dir()):
for num in range(len(devicess)):
d = {}
d["device"]=devicess[num][0]
d["login.air"]=get_all_dir()[num]+"/login.air"
d["NEXT.air"]=get_all_dir()[num]+"/NEXT.air"
ls.append(d)
else:
print("设备个数与脚本个数对应不上:设备个数:%s,脚本个数:%s"%(len(devicess),len(devicess)))
return ls
def create_dic_command():
"""
:return: [[airtest ... login.air,airtest ... NEXT.air],]
"""
ls = []
for i in create_dic_data():
comm_login = 'airtest run %s --device Android:///%s' % (i['login.air'], i['device'])
log_path = i['NEXT.air'].replace("NEXT.air","report")
comm_next = 'airtest run %s --device Android:///%s --log %s' % (i['NEXT.air'], i['device'],log_path)
lls=[comm_login,comm_next]
ls.append(lls)
return ls
def main(comm):
print("main:%s"%comm)
os.system(comm)
if __name__ == '__main__':
pool = Pool()
pool.map(main,[i[0] for i in create_dic_command()])
pool.map(main,[i[1] for i in create_dic_command()])
二. 一个脚本对应多台设备
github: https://codeload.github.com/AirtestProject/multi-device-runner/zip/master