示例#1
0
def get_common_report(start_test_time, endtime, starttime):
    mreport = Mreport.report()

    BappK = BappKernel.getPhoneMsg()
    raw = BappKernel.get_men_total(r"d:\men.log")
    appbase = get_app_basemsg(PATH('../img/t.apk'))
    mreport.test_sum = common.test_sum
    mreport.test_failed = common.test_failed
    mreport.test_success = common.test_success
    mreport.test_sum_date = str((endtime - starttime).seconds - 6) + "秒"
    mreport.app_name = appbase[0]
    mreport.app_size = appbase[1]
    mreport.phone_name = BappK["phone_name"] + " " + BappK["phone_model"]
    mreport.phone_rel = BappK["release"]
    mreport.phone_pix = BappKernel.get_app_pix()
    mreport.phone_raw = reportPhone.phone_raw(raw / 1024)

    print(common.MEN)
    avg_men = BappKernel.get_avg_raw(common.MEN)  # 获取每次占用内存多少
    mreport.phone_avg_use_raw = avg_men
    mreport.phone_max_use_raw = reportPhone.phone_max_use_raw(common.MEN)
    mreport.phone_cpu = BappKernel.get_cpu_kel()
    mreport.phone_avg_use_cpu = reportPhone.phone_avg_use_cpu(common.CPU)
    mreport.phone_avg_max_use_cpu = reportPhone.phone_avg_max_use_cpu(
        common.CPU)
    mreport.app_version = appbase[2]
    mreport.test_date = start_test_time
    mreport.fps_max = reportPhone.fps_max(common.FPS)
    mreport.fps_avg = reportPhone.fps_avg(common.FPS)
    Breport.set_report(mreport)
示例#2
0
    def execCase(self, f, **kwargs):
        logTest = testLog.myLog().getLog()
        bc = self.getModeList(f)
        go = bo.getOperateElement(driver=common.DRIVER)
        ch_check = bc[-1]
        for k in bc:
            if k["operate_type"] != "false":
                if go.operate_element(k) == False:
                    logTest.checkPointNG(common.DRIVER, kwargs["test_name"],
                                         kwargs["test_name"])
                    logTest.resultNG(kwargs["test_name"], "找不页面元素")

                get_men = ap.get_men(common.PACKAGE)
                get_cpu = ap.top_cpu(common.PACKAGE)
                get_fps = ap.get_fps(common.PACKAGE)

                self.cpu.append(get_cpu)
                self.men.append(get_men)
                self.fps.append(get_fps)

                common.MEN.append(get_men)
                common.CPU.append(get_cpu)
                common.FPS.append(get_fps)

        if go.findElement(ch_check):
            common.test_success += 1
            self.getTempCase.test_result = "成功"
            logTest.resultOK(kwargs["test_name"])
        else:
            # logTest.screenshotNG(common.DRIVER, kwargs["test_name"])
            logTest.checkPointNG(common.DRIVER, kwargs["test_name"],
                                 kwargs["test_name"])
            common.test_failed += 1
            test_reason = "检查不到元素"
            # if common.I_ANR > 0:
            #     test_reason = "有ANR错误"
            # if common.I_CRASH > 0:
            #     test_reason = "有CRASH错误"
            # if common.I_EXCEPTION > 0:
            #     test_reason = "有EXCEPTION错误"
            self.getTempCase.test_result = "失败"
            self.getTempCase.test_reason = test_reason

        self.getTempCase.test_name = kwargs["test_name"]
        self.getTempCase.test_module = self.test_module
        common.test_sum += 1

        self.getTempCase.test_men_max = rp.phone_max_use_raw(self.men)
        avg_men = ba.get_avg_raw(self.men)  # 获取每次占用内存多少
        self.getTempCase.test_men_avg = avg_men
        self.getTempCase.test_cpu_max = rp.phone_avg_max_use_cpu(self.cpu)
        self.getTempCase.test_cpu_avg = rp.phone_avg_use_cpu(self.cpu)
        self.getTempCase.test_fps_max = rp.fps_max(self.fps)
        self.getTempCase.test_fps_avg = rp.fps_avg(self.fps)

        common.RESULT["info"].append(
            json.loads(json.dumps(self.getTempCase().to_primitive())))
        if kwargs["isLast"] == "1":
            # 最后case要写最下面的统计步骤
            common.RRPORT["info"].append(common.RESULT["info"])
示例#3
0
    def report(self, go, ch_check, _d_report_common, kwargs, is_crash):

        self.GetAppCaseInfo.test_men_max = rp.phone_max_use_raw(
            self.men)  # 内存最大使用情况
        avg_men = ba.get_avg_raw(self.men, self.devices)  # 获取每次占用内存平均值
        self.GetAppCaseInfo.test_men_avg = avg_men
        self.GetAppCaseInfo.test_cpu_max = rp.phone_avg_max_use_cpu(
            self.cpu)  # cpu最大使用
        self.GetAppCaseInfo.test_cpu_avg = rp.phone_avg_use_cpu(
            self.cpu)  # cpu平均使用
        self.GetAppCaseInfo.test_fps_max = rp.fps_max(self.fps)
        self.GetAppCaseInfo.test_fps_avg = rp.fps_avg(self.fps)

        d_report = {}
        raw = ba.get_men_total(devices=self.devices)
        d_report["phone_name"] = self.get_phone_name()[0]
        d_report["phone_pix"] = ba.get_app_pix(self.devices)
        d_report["phone_cpu"] = ba.get_cpu_kel(self.devices)
        d_report["phone_raw"] = rp.phone_raw(raw / 1024)
        if is_crash == NORMAL:  # 正常情况
            if go.findElement(ch_check):
                _d_report_common["test_success"] += 1
                self.GetAppCaseInfo.test_result = "成功"
                self.write_report_collect(
                    _d_report_common,
                    f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数
            else:
                _d_report_common["test_failed"] += 1
                test_reason = "Can not find element"
                self.write_report_collect(
                    _d_report_common,
                    f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数
                ng_img = testLogScreen.screenshotNG(
                    caseName=kwargs["test_name"],
                    driver=self.driver,
                    resultPath=common.SCREEN_IMG_PATH)
                self.GetAppCaseInfo.test_image = ng_img
                self.GetAppCaseInfo.test_result = "Fail"
                self.GetAppCaseInfo.test_reason = test_reason
        elif is_crash == IS_CRASH:  #如果闪退了
            _d_report_common["test_failed"] += 1
            self.write_report_collect(
                _d_report_common, f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数
            ng_img = testLogScreen.screenshotNG(
                caseName=kwargs["test_name"],
                driver=self.driver,
                resultPath=common.SCREEN_IMG_PATH)
            self.GetAppCaseInfo.test_image = ng_img
            self.GetAppCaseInfo.test_result = "Fail"
            self.GetAppCaseInfo.test_reason = "Crash"
            self.GetAppCaseInfo.test_log = self.pull_crash_log()  #记录本地日志
        elif is_crash == NO_ELEMENT:  #找不到元素
            _d_report_common["test_failed"] += 1
            self.write_report_collect(
                _d_report_common, f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数
            self.GetAppCaseInfo.test_result = "Fail"
            self.GetAppCaseInfo.test_reason = "Can not find element"

        self.GetAppCaseInfo.test_name = kwargs["test_name"]
        self.GetAppCaseInfo.test_module = self.test_module
        self.GetAppCaseInfo.test_phone_name = self.get_phone_name()[0]

        info_case = json.loads(json.dumps(
            self.GetAppCaseInfo().to_primitive()))
        self.write_detail(info_case, f=common.REPORT_INFO_PATH,
                          key="info")  # 写入所有的case包括,init,info中的excel中的case情况
        if kwargs["isLast"] == "1":
            # 记录每个设备的case运行情况
            if is_crash == NORMAL:  #如果没有闪退了
                d_report[
                    "phone_avg_use_cpu"] = self.GetAppCaseInfo.test_cpu_avg
                d_report[
                    "phone_avg_max_use_cpu"] = self.GetAppCaseInfo.test_cpu_max
                d_report[
                    "phone_avg_use_raw"] = self.GetAppCaseInfo.test_men_avg
                d_report[
                    "phone_max_use_raw"] = self.GetAppCaseInfo.test_men_max
                d_report["fps_avg"] = self.GetAppCaseInfo.test_fps_avg
                d_report["fps_max"] = self.GetAppCaseInfo.test_fps_max
            else:
                d_report["phone_avg_use_cpu"] = "0"
                d_report["phone_avg_max_use_cpu"] = "0"
                d_report["phone_avg_use_raw"] = "0"
                d_report["phone_max_use_raw"] = "0"
                d_report["fps_avg"] = "0"
                d_report["fps_max"] = "0"
            # 最后case要写最下面的统计步骤
            self.write_detail(d_report, f=common.REPORT_INIT, key="init")
示例#4
0
def phone_avg_max_use_cpus(cpu):
    return reportPhone.phone_avg_max_use_cpu(cpu)