def __write_excel(self, status=False, msg='', dsc=''): """ 写入关键字运行结果 :param status: 运行的状态 :param msg: 实际运行结果 :param dsc: 备注信息 :return: 无 """ if status is True: self.excel.write(row=self.excel_write_row, column=config.get('status'), value="PASS", color=MyColor.GREEN) elif status is False: self.excel.write(row=self.excel_write_row, column=config.get('status'), value="FAIL", color=MyColor.RED) if not is_Null(msg): # 有时候实际结果过长,我们就只保存前30000个字符 msg = str(msg) if len(msg) > 30000: msg = msg[0:30000] self.excel.write(row=self.excel_write_row, column=config.get('result'), value=str(msg)) try: if not is_Null(dsc): self.excel.write(row=self.excel_write_row, column=config.get('remark'), value=str(dsc)) except: pass
def get_summery_info(self, ): """ 获取用例信息 :param file_path: 用例文件路径 :return: """ # 重新赋值 self.summery_info.clear() self.summery_info['report_title'] = config.get('reportTitle') self.summery_info['tester'] = config.get('tester') self.summery_info['developer'] = config.get('developer') self.summery_info['case_version'] = config.get('case_version') self.summery_info['case_count'] = '' self.summery_info['pass_rate'] = '' self.summery_info['start_time'] = configs.time_start self.summery_info['end_time'] = configs.time_end case_pass_count = 0 case_fail_count = 0 case_block_count = 0 for sheet in self.sheets: self.excel.set_sheet(sheet) lines = self.excel.read_lines() for line in lines: # 过滤写分组信息和用例名称的列 if not (line[int(config.get('teem'))] == '' and line[int(config.get('caseName'))] == ''): pass # 是一个可执行的测试用例 elif not line[int(config.get('keyWord'))] == '': if line[int(config.get('status'))].upper() == 'FAIL': case_fail_count += 1 elif line[int(config.get('status'))].upper() == 'PASS': case_pass_count += 1 else: case_block_count += 1 case_count = case_fail_count + case_pass_count + case_block_count try: pass_rate = (int((case_pass_count * 10000) / case_count)) / 100 except Exception as e: pass_rate = 0.0 self.summery_info['case_count'] = case_count self.summery_info['pass_rate'] = pass_rate self.summery_info['case_fail_count'] = case_fail_count self.summery_info['case_pass_count'] = case_pass_count self.summery_info['case_block_count'] = case_block_count return self.summery_info
def __run_case(self, cell_list): # 第一列,第二列不执行 if len(cell_list[int(config.get('teem'))]) > 0 or len(cell_list[int( config.get('caseName'))]) > 0: return # print('cell_list =', cell_list) try: func = getattr(self.http, cell_list[int(config.get('keyWord'))]) li = cell_list[int(config.get('requestParamStart') ):int(config.get('requestParamEnd')) + 1] # print('li =', li) func(*li) except: self.excel.write(self.http.excel_write_row, config.get('status'), 'Fail', MyColor.RED) self.excel.write(self.http.excel_write_row, config.get('result'), '暂不支持该关键字,请检查') self.excel.write(self.http.excel_write_row, config.get('remark'), 'traceback.format_exc()') print(traceback.format_exc())
def __init__(self): self.email_form = config.get('mailFrom') self.password = config.get('passWord') self.email_to = config.get('mailTo') self.smtp_server = 'smtp.' + self.email_form[ self.email_form.find('@') + 1:len(self.email_form)] self.email_title = config.get('mailTitle') self.email_module = config.get('mailModule') if is_Null( config.get('mailModule')) else 'module1.html' # 获取html用例模板 with open(file=get_abspath('data/email_module/') + '/' + self.email_module, mode='r', encoding=self.charset) as f1: self.email_content = f1.read() self.file_path = get_abspath('data/case/result_HTTP接口用例.xls') # 附件 self.email_enclosure = [ self.file_path, ] self.summery_report = SummeryReport(self.file_path)
def get_group_info(self): """ 获取分组信息 :param file_path: :return: """ self.group_info.clear() case_count = 0 pass_count = 0 group_smale = {} sign = False group_name = '' for sheet in self.sheets: self.excel.set_sheet(sheet) lines = self.excel.read_lines() group_smale.clear() for i in range(1, len(lines)): line = lines[i] if line[int(config.get('teem'))] == '' and line[int(config.get('caseName'))] == '': if not line[int(config.get('keyWord'))] == '': if line[int(config.get('status'))].upper() == 'PASS': pass_count += 1 else: sign = True case_count += 1 elif not line[int(config.get('teem'))] == '': if i == 1: group_name = line[int(config.get('teem'))] pass else: # 分组 if sign: status = 'FAIL' sign = False else: status = 'PASS' group_smale['group_name'] = group_name group_smale['case_count'] = case_count group_smale['pass_count'] = pass_count group_smale['fail_count'] = case_count - pass_count group_smale['status'] = status self.group_info.append(group_smale) case_count = 0 pass_count = 0 group_smale = {} sign = False group_name = line[int(config.get('teem'))] # 完成一个sheet时,保存分组信息 if sign: status = 'FAIL' sign = False else: status = 'PASS' group_smale['group_name'] = group_name group_smale['case_count'] = case_count group_smale['pass_count'] = pass_count group_smale['fail_count'] = case_count - pass_count group_smale['status'] = status self.group_info.append(group_smale) case_count = 0 pass_count = 0 group_smale = {} sign = False return self.group_info