Esempio n. 1
0
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("未找到设备,测试结束")
Esempio n. 2
0
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("未找到设备,测试结束")
Esempio n. 3
0
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("未找到设备,测试结束")
Esempio n. 4
0
    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()))
            break
        print("{}开始进行性能测试".format(madb.get_mdevice()))
        # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing方法。
        p = Process(target=enter_performance, args=(
            madb,
            flag,
            start,
        ))
        Processlist.append(p)
    for p in Processlist:
        p.start()
    for p in Processlist:
        p.join()

    print("性能测试结束")
Esempio n. 5
0
        self.args = args

    def run(self):
        self.result = self.func(*self.args)

    def get_result(self):
        threading.Thread.join(self)  # 等待线程执行完毕
        try:
            return self.result
        except Exception as e:
            print(traceback.format_exc())
            return None


#调试代码,单独执行的话,flag默认为1。
if __name__ == "__main__":
    devicesList = Madb().getdevices()
    pool = multiprocessing.Pool(processes=len(devicesList))
    print("启动进程池")
    for i in range(len(devicesList)):
        madb = Madb(devicesList[i])
        flag = Value('i', 1)
        if madb.get_androidversion() < 5:
            print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice()))
            break
        pool.apply_async(
            enter_performance,
            (madb, flag))  # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing方法。
    pool.close()
    pool.join()
    print("性能测试结束")
Esempio n. 6
0
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 = "自动化测试完毕"
    '''