def main(): devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) print("测试开始") results = "" if devicesList: try: pool = multiprocessing.Pool(processes=len(devicesList)) print("启动进程池") results = [] for i in range(len(devicesList)): madb = Madb(devicesList[i]) pool.apply_async(enter_processing, ( i, madb, )) # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing方法。 pool.close() pool.join() print("进程回收完毕") print("测试结束") except AirtestError as ae: print("Airtest发生错误" + traceback.format_exc()) except PocoException as pe: print("Poco发生错误" + traceback.format_exc()) except Exception as e: print("发生未知错误" + traceback.format_exc()) else: print("未找到设备,测试结束")
def main(): #默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备 devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) #读取是否需要同步性能测试的配置。 need_performance = Madb().get_needperformance() reportpath = os.path.join(os.getcwd(), "Report") # 没有Report目录时自动创建 if not os.path.exists(reportpath): os.mkdir(reportpath) os.mkdir(reportpath + "/Screen") print(reportpath) print("测试开始") if devicesList: try: print("启动进程池") list = [] # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。 for i in range(len(devicesList)): #start会被传递到2个进程函数里,作为区分最终产物html和excel的标志 start = time.localtime() madb = Madb(devicesList[i]) if madb.get_androidversion() < 5: print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice())) continue else: #进程通信变量flag,默认为0,完成测试时修改为1。 flag = Value('i', 0) if need_performance == "True": p1 = Process(target=enter_performance, args=( madb, flag, start, )) list.append(p1) p2 = Process(target=enter_processing, args=( i, madb, flag, start, )) list.append(p2) for p in list: p.start() for p in list: p.join() print("进程回收完毕") print("测试结束") except AirtestError as ae: print("Airtest发生错误" + traceback.format_exc()) except PocoException as pe: print("Poco发生错误" + traceback.format_exc()) except Exception as e: print("发生未知错误" + traceback.format_exc()) else: print("未找到设备,测试结束")
def main(): #默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备 devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=",devicesList) need_performance=Madb().get_needperformance() print("测试开始") if devicesList: try: print("启动进程池") list=[] for i in range(len(devicesList)): start=time.localtime() madb=Madb(devicesList[i]) # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。 if madb.get_androidversion()<5: print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice())) continue else: #进程通信变量flag,默认为0,完成测试时修改为1。 flag = Value('i', 0) if need_performance=="True": p1 = Process(target=enter_performance, args=(madb,flag,start,)) list.append(p1) p2=Process(target=enter_processing, args=(i,madb,flag,start,)) list.append(p2) for p in list: p.start() for p in list: p.join() print("进程回收完毕") print("测试结束") except AirtestError as ae: print("Airtest发生错误" + traceback.format_exc()) except PocoException as pe: print("Poco发生错误" + traceback.format_exc()) except Exception as e: print("发生未知错误" + traceback.format_exc()) else: print("未找到设备,测试结束")
def main(): devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) print("测试开始") if devicesList: try: print("启动进程池") list = [] for i in range(len(devicesList)): madb = Madb(devicesList[i]) # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。 if madb.get_androidversion() < 5: print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice())) continue else: p1 = Process(target=enter_performance, args=(madb, )) list.append(p1) p2 = Process(target=enter_processing, args=( i, madb, )) list.append(p2) for p in list: p.start() for p in list: p.join() print("进程回收完毕") print("测试结束") except AirtestError as ae: print("Airtest发生错误" + traceback.format_exc()) except PocoException as pe: print("Poco发生错误" + traceback.format_exc()) except Exception as e: print("发生未知错误" + traceback.format_exc()) else: print("未找到设备,测试结束")
fr_r_index = content.rfind(tag) else: fr_r_index = content.find(tag) for i in range(1, round_num): if reverse: fr_r_index = content.rfind(tag, 0, fr_r_index) else: fr_r_index = content.find(tag, fr_r_index + 1) fr_prev = content[0:fr_r_index] fr_next = content[fr_r_index:len(content)] return fr_prev, fr_next #调试代码,单独执行的话,flag默认为1。 if __name__ == "__main__": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) start = time.localtime() ''' madb = Madb(devicesList[0]) flag = Value('i', 0) enter_performance (madb, flag, start,) ''' print("启动进程池") flag = Value('i', 0) Processlist = [] for i in range(len(devicesList)): madb = Madb(devicesList[i]) if madb.get_androidversion() < 5: print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice()))
AndroidVersion, ABI) push_minicap = adb + " -s {} push {}/{}/minicap".format( devices, airtest_minicap_path, ABI) + " /data/local/tmp/" push_minicapso = adb + " -s {} push {}".format( devices, airtest_minicapso_path) + " /data/local/tmp/" os.popen(push_minicap) os.popen(push_minicapso) chmod = adb + " -s {} shell chmod 777 /data/local/tmp/*".format( devices) os.popen(chmod) wm_size_command = adb + " -s {} shell wm size".format(devices) vm_size = os.popen(wm_size_command).read() vm_size = vm_size.split(":")[1].strip() start_minicap = adb + " -s {} shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {}@{}/0 -t".format( devices, vm_size, vm_size) result = os.popen(start_minicap).read() print(result) print("设备{}上已经成功安装并开启了MiniCap。".format(devices)) except Exception as e: print(e, traceback.format_exc()) if __name__ == "__main__": devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) for device in devicesList: #ini_MiniCap(device) GetScreenbyMiniCap(time.time(), device, "测试")
def main(): #默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备 devicesList = Madb().get_devicesList() if devicesList[0] == "": devicesList = Madb().getdevices() print("最终的devicesList=", devicesList) if Madb().get_apkpath() == "" or Madb().get_packagename() == "": print("配置文件填写不全,packagename和apkpath是必填项") devicesList = None #读取是否需要同步性能测试的配置。 skip_performance = Madb().get_skip_performance() skip_performance = True if skip_performance == "1" else False is_storaged_by_excel = Madb().get_storage_by_excel() is_storaged_by_excel = True if is_storaged_by_excel == "1" else False reportpath = os.path.join(os.getcwd(), "Report") # 没有Report目录时自动创建 if not os.path.exists(reportpath): os.mkdir(reportpath) os.mkdir(reportpath + "/Screen") os.mkdir(reportpath + "/Data") print(reportpath) print("测试开始") if devicesList: try: print("启动进程池") list = [] # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。 for i in range(len(devicesList)): #start会被传递到2个进程函数里,作为区分最终产物html和excel的标志 start = time.localtime() madb = Madb(devicesList[i]) if madb.get_androidversion() < 5: print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice())) continue else: #进程通信变量flag,默认为0,完成测试时修改为1。 flag = Value('i', 0) fpsflag = Value('i', 0) if not skip_performance: p1 = Process(target=enter_performance, args=(madb, flag, start, is_storaged_by_excel)) list.append(p1) p2 = Process(target=enter_processing, args=( i, madb, flag, start, )) list.append(p2) for p in list: p.start() for p in list: p.join() print("进程回收完毕") print("测试结束") screenoff = Madb().get_screenoff() screenoff = True if screenoff == "1" else False if screenoff: for i in devicesList: setScreenOFF(i) print("设备{}已灭屏".format(i)) except AirtestError as ae: print("Airtest发生错误" + traceback.format_exc()) except PocoException as pe: print("Poco发生错误" + traceback.format_exc()) except Exception as e: print("发生未知错误" + traceback.format_exc()) else: print("未找到设备,测试结束") mailtext = "自动化测试完毕" '''
if installflag == "Success": try: #尝试启动应用 madb.StartApp() startflag = "Success" except Exception as e: print("运行失败" + traceback.format_exc()) time.sleep(madb.get_timeout_of_per_action()) #应用启动成功则开始运行用例 if (startflag == "Success"): RunTestCase.RunTestCase(madb, start) print("{}完成测试".format(devices)) else: print("{}未运行测试。".format(devices)) else: print("设备{}连接失败".format(devices)) except Exception as e: print("连接设备{}失败".format(devices) + traceback.format_exc()) #无论结果如何,将flag置为1,通知Performance停止记录。 flag.value = 1 if __name__ == "__main__": screenoff = Madb().get_screenoff() screenoff = True if screenoff == "1" else False devicesList = Madb().getdevices() if screenoff: for i in devicesList: setScreenOFF(i) print("设备{}已灭屏".format(i))
except Exception as e: print( "{}安装失败,installResult={}".format(devices, installResult) + traceback.format_exc()) if installflag == "Success": try: #尝试启动应用 madb.StartApp() startflag = "Success" except Exception as e: print("运行失败" + traceback.format_exc()) time.sleep(madb.get_timeout_of_per_action()) #应用启动成功则开始运行用例 if (startflag == "Success"): RunTestCase.RunTestCase(madb, start) print("{}完成测试".format(devices)) else: print("{}未运行测试。".format(devices)) else: print("设备{}连接失败".format(devices)) except Exception as e: print("连接设备{}失败".format(devices) + traceback.format_exc()) #无论结果如何,将flag置为1,通知Performance停止记录。 flag.value = 1 madb.setScreenOFF() if __name__ == "__main__": madb = Madb("172.16.6.82:20484") madb.setScreenOFF()