Exemple #1
0
def get_common_report(start_test_time, endtime, starttime):
    mreport = m_report.GetReport()

    b_get_hp_info = phoneBase.get_phone_info(devices=ga.deviceName)
    raw = phoneBase.get_men_total(devices=ga.deviceName)

    apk_msg = apkBase.apkInfo(PATH('../img/t.apk'))
    mreport.app_name = apk_msg.get_apk_name()
    mreport.app_size = apk_msg.get_apk_size()
    mreport.app_version = apk_msg.get_apk_version()

    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.phone_name = b_get_hp_info["phone_name"] + " " + b_get_hp_info[
        "phone_model"]
    mreport.phone_rel = b_get_hp_info["release"]
    mreport.phone_pix = phoneBase.get_app_pix(devices=ga.deviceName)
    mreport.phone_raw = reportPhone.phone_raw(raw / 1024)

    print(common.MEN)
    avg_men = phoneBase.get_avg_raw(common.MEN, ga.deviceName)  # 获取每次占用内存多少
    mreport.phone_avg_use_raw = avg_men
    mreport.phone_max_use_raw = reportPhone.phone_max_use_raw(common.MEN)
    mreport.phone_cpu = phoneBase.get_cpu_kel(devices=ga.deviceName)
    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.test_date = start_test_time
    mreport.fps_max = reportPhone.fps_max(common.FPS)
    mreport.fps_avg = reportPhone.fps_avg(common.FPS)
    b_report.OperateReport().set_report(mreport)
Exemple #2
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 = "检查不到元素"
                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 = "失败"
                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 = "失败"
            self.GetAppCaseInfo.test_reason = "崩溃了"
            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 = "失败"
            self.GetAppCaseInfo.test_reason = "找不到元素"

        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")
Exemple #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 = "检查不到元素"
                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 = "失败"
                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 = "失败"
            self.GetAppCaseInfo.test_reason = "崩溃了"
            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 = "失败"
            self.GetAppCaseInfo.test_reason = "找不到元素"

        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")
    def execCase(self, f, **kwargs):
        logTest = testLog.myLog().getLog()
        bc = self.getModeList(f)
        go = bo.OperateElement(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.GetAppCaseInfo.test_result = "成功"
            logTest.resultOK(kwargs["test_name"])
        else:
            # logTest.screenshotNG(GetVariable.DRIVER, kwargs["test_name"])
            logTest.checkPointNG(common.DRIVER, kwargs["test_name"],
                                 kwargs["test_name"])
            common.test_failed += 1
            test_reason = "检查不到元素"
            # if GetVariable.I_ANR > 0:
            #     test_reason = "有ANR错误"
            # if GetVariable.I_CRASH > 0:
            #     test_reason = "有CRASH错误"
            # if GetVariable.I_EXCEPTION > 0:
            #     test_reason = "有EXCEPTION错误"
            self.GetAppCaseInfo.test_result = "失败"
            self.GetAppCaseInfo.test_reason = test_reason

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

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

        common.RESULT["info"].append(
            json.loads(json.dumps(self.GetAppCaseInfo().to_primitive())))
        if kwargs["isLast"] == "1":
            # 最后case要写最下面的统计步骤
            common.RRPORT["info"].append(common.RESULT["info"])
Exemple #5
0
    def execCase(self, f, **kwargs):
        '''

        :param f: 用例文件
        :param kwargs:
        test_name: 用例名
        is_last: 最后一个用例 1, 0
        :return:
        '''
        logTest = testLog.myLog().getLog()
        bc = self.getModeList(f)
        go = bo.OperateElement(driver=self.driver)
        ch_check = bc[-1]
        # l_report = {"info": [], "init": []}  # case的init,info信息
        # _init = []
        # _info = []
        _d_report_common = {
            "test_success": 0,
            "test_failed": 0,
            "test_sum": 0
        }  #case的运行次数和性能
        for k in bc:
            if k["operate_type"] != "false":
                k["devices"] = self.devices
                if go.operate_element(k) == False:
                    logTest.checkPointNG(driver=self.driver,
                                         caseName=kwargs["test_name"],
                                         checkPoint=kwargs["test_name"])
                    logTest.resultNG(kwargs["test_name"], "找不页面元素")

                get_men = ap.get_men(devices=self.devices,
                                     pkg_name=self.package)
                get_cpu = ap.top_cpu(devices=self.devices,
                                     pkg_name=self.package)
                get_fps = ap.get_fps(devices=self.devices,
                                     pkg_name=self.package)

                # 单个case
                self.GetAppCaseInfo.test_devices = self.get_phone_name()
                self.cpu.append(get_cpu)
                self.men.append(get_men)
                self.fps.append(get_fps)

        _d_report_common["test_sum"] += 1
        if go.findElement(ch_check):
            _d_report_common["test_success"] += 1
            self.GetAppCaseInfo.test_result = "成功"
            logTest.resultOK(kwargs["test_name"])
            self.write_report_collect(
                _d_report_common, f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数

        else:
            # logTest.screenshotNG(GetVariable.DRIVER, kwargs["test_name"])
            logTest.checkPointNG(driver=self.driver,
                                 caseName=kwargs["test_name"],
                                 checkPoint=kwargs["test_name"])
            _d_report_common["test_failed"] += 1
            test_reason = "检查不到元素"
            self.write_report_collect(
                _d_report_common, f=common.REPORT_COLLECT_PATH)  # 写入case运行的总个数

            self.GetAppCaseInfo.test_result = "失败"
            self.GetAppCaseInfo.test_reason = test_reason

        self.GetAppCaseInfo.test_name = kwargs["test_name"]
        self.GetAppCaseInfo.test_module = self.test_module

        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)
        self.GetAppCaseInfo.test_phone_name = self.get_phone_name()

        info_case = json.loads(json.dumps(
            self.GetAppCaseInfo().to_primitive()))
        # _info.append(info_case)
        self.write_detail(info_case, f=common.REPORT_INFO_PATH,
                          key="info")  # 写入所有的case包括,init,info中的excel中的case情况
        if kwargs["isLast"] == "1":
            d_report = {}
            raw = ba.get_men_total(devices=self.devices)
            d_report["phone_name"] = self.get_phone_name()
            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)
            # 记录每个设备的case运行情况
            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
            # _init.append(d_report)
            #最后case要写最下面的统计步骤
            self.write_detail(
                d_report, f=common.REPORT_INIT,
                key="init")  #写入所有的case包括,init,info中的excel中的case情况