def subSendMail(): if int(isSendMailStr[1]) == 1: # 发送附件 UsualTool.send_mail(emailList, subject, emailText, self.testReportFilePath, subType="html") else: # 不发送附件 UsualTool.send_mail(emailList, subject, emailText, subType="html")
def subSendMail(): if int(isSendMailStr[1]) == 1: # 发送附件 testReportFilePath = "%s/static/ui_test/reports/%s/report.html" % ( EnvConfig.WEB_ROOT, self.reportDir) UsualTool.send_mail(emailList, subject, emailText, testReportFilePath, subType="html") else: # 不发送附件 UsualTool.send_mail(emailList, subject, emailText, subType="html")
def sendEmailToExecutor(self): self.globalDB.initGlobalDBConf() res = self.globalDB.execute_sql( "select email from tb_user where loginName='%s' " % self.addBy) self.globalDB.release() resEmailList = self.emailList print("self.emailList", self.emailList) if res: # emailList = "%s" % res[0]['email'] # ;分号间隔 emailList = "" # ;分号间隔 if resEmailList.strip() != "": resEmList = resEmailList.split(",") for tmpMail in resEmList: emailList = emailList + ";" + tmpMail # emailList = emailList + ";[email protected]" subject = "[%s]UI任务[%s:%s]测试报告" % (self.testResult, self.taskId, self.title) # 开始生成emailText的html############################################################################### """ (一)测试报告概况: 任务ID:HTTP_TASK_62 执行环境:预发布灰度 执行结果:FAIL 执行耗时:36秒 任务名称:SFA-CPQ团队-自动化测试【staging灰度环境】 任务描述:(1)【产品】PC端和APP端 (2)【价格表】&【价格表明细】PC端和APP端(3)【合同】PC端和APP端 包含ywx:['SFA'] 包含mk:['产品', '合同', '价格表'] 备注:在jenkins上执行自动化测试任务 所有统计: (1)用例统计:用例总数10个,通过7,失败3,通过率70%。【说明:因为任务中的用例都会被执行,通过率 = 通过数量 / 总数量】 (2)接口统计:接口总数500个,通过400个,失败50个,未执行50个,通过率80%。【说明:接口总数包含独立接口和用例接口之和。因为用例的靠前的接口可能失败,靠后的接口不会被执行,通过率定义方式大家可以多提建议。通过率 = 通过数量 / 总数量】 (二)失败的所有接口汇总:【说明:包含独立接口和用例接口】 (1)mk:【产品】 接口[/json/crm_product/save.action]:已执行4次,通过0,失败4,通过率0.00%。 (2)mk:【合同】 接口[/mobile/common/search.action]:已执行2次,通过1,失败1,通过率50.00%。 接口[/json/crm_common_detail/lock-data.action]:已执行1次,通过0,失败1,通过率0.00%。 详情见附件。 """ bgColor = "#f2dede" if self.testResult == "PASS": bgColor = "#dff0d8" emailText = "<html><body style='background-color:%s;display:block;'>" % bgColor # 1、测试报告概况 emailText = emailText + ( """ <h1>(一)UI测试报告概况</h1> <h2>任务基本信息</h2> <table border="1px" cellpadding="3px" width="80%%"> <tr><th width="20%%" align="left">任务ID</th><td width="80%%">%s</td></tr> <tr><th align="left">执行环境</th><td>%s</td></tr> <tr><th align="left">执行时间</th><td>%s</td></tr> <tr><th align="left">执行结果</th><td>%s</td></tr> <tr><th align="left">执行耗时</th><td>%s秒</td></tr> <tr><th align="left">任务名称</th><td>%s</td></tr> <tr><th align="left">任务描述</th><td>%s</td></tr> <tr><th align="left">包含%s</th><td>%s</td></tr> <tr><th align="left">包含%s</th><td>%s</td></tr> <tr><th align="left">备注</th><td>%s</td></tr> </table>""" % (self.taskId, self.httpConfKey, self.execStartTime, self.testResult, self.execTakeTime, self.title, self.taskdesc, CommonConf.groupLevel1, self.businessLineName, CommonConf.groupLevel2, self.moduleName, (self.execComments.strip() == "" and "无" or self.execComments.strip()))) if isDictJson(self.testResultMessage): resDict = json.loads(self.testResultMessage) if resDict['caseTotalCount'] == 0: caseRate = 0.00 else: caseRate = float(resDict['casePassCount']) / float( resDict['caseTotalCount']) if resDict['caseStepTotalCount'] == 0: stepRate = 0.00 else: stepRate = float(resDict['caseStepPassCount']) / float( resDict['caseStepTotalCount']) # 所有统计信息开始################################################################ emailText = emailText + "<h2>结果统计信息</h2>" emailText = emailText + """ <table border="1px" cellpadding="3px" width="80%%"> <thead> <tr style="background-color:#fcf8e3;"> <th width="5%%"></th> <th width="10%%">总计</th> <th width="10%%">PASS</th> <th width="10%%">FAIL</th> <th width="10%%">WARNING</th> <th width="10%%">通过率</th> </tr> </thead> <tbody> <tr style="background-color:%s;" id="total_summay"><td>用例</td> <td><bdi id="summay_totalCount">%s</bdi></td> <td><bdi id="summay_passCount">%s</bdi> <td><bdi id="summay_failCount">%s</bdi></td> <td><bdi id="summay_failCount">%s</bdi></td> <td><bdi id="summay_passPercent">%.2f%%</bdi></td></tr> <tr style="background-color:%s;" id="total_summay"><td>步骤</td> <td><bdi id="summay_totalCount">%s</bdi></td> <td><bdi id="summay_passCount">%s</bdi></td> <td><bdi id="summay_failCount">%s</bdi></td> <td><bdi id="summay_failCount">%s</bdi></td> <td><bdi id="summay_passPercent">%.2f%%</bdi></td></tr> </tbody> </table>""" % (bgColor, resDict['caseTotalCount'], resDict['casePassCount'], resDict['caseFailCount'], resDict['caseWarningCount'], caseRate * 100, bgColor, resDict['caseStepTotalCount'], resDict['caseStepPassCount'], resDict['caseStepFailCount'], resDict['caseStepWarningCount'], stepRate * 100) else: # task 执行结果 结果没有返回正常的json emailText = emailText + self.testResultMessage + "<br>" # self.isSendEmail 是否发送是否带附件PassFailErrorException isSendMailStr = str(self.isSendEmail) # 不够6位后面补1 addOneCount = 6 - len(isSendMailStr) for i in range(0, addOneCount): isSendMailStr = isSendMailStr + "1" if int(isSendMailStr[1]) == 1: emailText = emailText + "<br>详情见附件。" else: tmpurl = "%s/static/ui_test/reports/%s/report.html" % ( EnvConfig.WEB_URI, self.reportDir) emailText = emailText + ( "<br>详情见: <a href='%s'>%s</a>" % (tmpurl, tmpurl)) emailText = emailText + "</body></html>" # 结束生成emailText的html############################################################################### # 开始发送邮件 def subSendMail(): if int(isSendMailStr[1]) == 1: # 发送附件 testReportFilePath = "%s/static/ui_test/reports/%s/report.html" % ( EnvConfig.WEB_ROOT, self.reportDir) UsualTool.send_mail(emailList, subject, emailText, testReportFilePath, subType="html") else: # 不发送附件 UsualTool.send_mail(emailList, subject, emailText, subType="html") if self.testResult == ResultConst.PASS and int( isSendMailStr[2]) == 1: subSendMail() elif self.testResult == ResultConst.FAIL and int( isSendMailStr[3]) == 1: subSendMail() elif self.testResult == ResultConst.ERROR and int( isSendMailStr[4]) == 1: subSendMail() elif self.testResult == ResultConst.EXCEPTION and int( isSendMailStr[5]) == 1: subSendMail() else: emailList = EmailConfig.sender # ;分号间隔 subject = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % ( self.testResult, self.taskId, self.title, self.addBy) emailText = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % ( self.testResult, self.taskId, self.title, self.addBy) UsualTool.send_mail(emailList, subject, emailText, subType="html")
def sendEmailToExecutor(self): self.globalDB.initGlobalDBConf() res = self.globalDB.execute_sql("select email from tb_user where loginName='%s' " % self.execBy) resEmailList = self.globalDB.execute_sql("select emailList from tb_task_execute where id=%d" % int(self.taskExecuteId)) self.globalDB.release() if res: # emailList = "%s" % res[0]['email'] # ;分号间隔 emailList = "" if resEmailList: resEmList = resEmailList[0]['emailList'].split(",") for tmpMail in resEmList: emailList = emailList +";" + tmpMail # emailList = emailList + ";[email protected]" subject = "[%s]任务[%s:%s]测试报告" % (self.testResult,self.taskId, self.title) if emailList == "": logging.info("邮箱列表为空,不执行邮件发送") return #开始生成emailText的html############################################################################### """ (一)测试报告概况: 任务ID:HTTP_TASK_62 执行环境:预发布灰度 执行结果:FAIL 执行耗时:36秒 任务名称:SFA-CPQ团队-自动化测试【staging灰度环境】 任务描述:(1)【产品】PC端和APP端 (2)【价格表】&【价格表明细】PC端和APP端(3)【合同】PC端和APP端 包含ywx:['SFA'] 包含mk:['产品', '合同', '价格表'] 备注:在jenkins上执行自动化测试任务 所有统计: (1)用例统计:用例总数10个,通过7,失败3,通过率70%。【说明:因为任务中的用例都会被执行,通过率 = 通过数量 / 总数量】 (2)接口统计:接口总数500个,通过400个,失败50个,未执行50个,通过率80%。【说明:接口总数包含独立接口和用例接口之和。因为用例的靠前的接口可能失败,靠后的接口不会被执行,通过率定义方式大家可以多提建议。通过率 = 通过数量 / 总数量】 (二)失败的所有接口汇总:【说明:包含独立接口和用例接口】 (1)mk:【产品】 接口[/json/crm_product/save.action]:已执行4次,通过0,失败4,通过率0.00%。 (2)mk:【合同】 接口[/mobile/common/search.action]:已执行2次,通过1,失败1,通过率50.00%。 接口[/json/crm_common_detail/lock-data.action]:已执行1次,通过0,失败1,通过率0.00%。 详情见附件。 """ bgColor = "#f2dede" if self.testResult == "PASS": bgColor = "#dff0d8" emailText = "<html><body style='background-color:%s;display:block;'>" % bgColor #1、测试报告概况 emailText = emailText + (""" <h1>(一)测试报告概况</h1> <h2>任务基本信息</h2> <table border="1px" cellpadding="3px" width="80%%"> <tr><th width="20%%" align="left">任务ID</th><td width="80%%">%s</td></tr> <tr><th align="left">创建人</th><td>%s</td></tr> <tr><th align="left">执行环境</th><td>%s(%s)</td></tr> <tr><th align="left">执行时间</th><td>%s</td></tr> <tr><th align="left">执行结果</th><td>%s</td></tr> <tr><th align="left">执行耗时</th><td>%s秒</td></tr> <tr><th align="left">任务名称</th><td>%s</td></tr> <tr><th align="left">任务描述</th><td>%s</td></tr> <tr><th align="left">包含%s</th><td>%s</td></tr> <tr><th align="left">包含%s</th><td>%s</td></tr> <tr><th align="left">备注</th><td>%s</td></tr> </table>""" % (self.taskId,self.addBy,self.confHttpLayer.alias,self.confHttpLayer.key,self.execTime,self.testResult,self.taskExecTakeTime,self.title,self.taskDesc,CommonConf.groupLevel1,self.businessLineGroup,CommonConf.groupLevel2,self.modulesGroup,(self.execComments.strip()=="" and "无" or self.execComments.strip()))) if isDictJson(self.testResultMsg): resDict = json.loads(self.testResultMsg) #所有统计信息开始################################################################ emailText = emailText + "<h2>所有统计</h2>" emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" if resDict['totalExecuteSummary']['total'] > 0: emailText = emailText + """<tr><th align="left" width="20%%">所有接口统计</th><td width="80%%">接口总数%d个,已执行接口%d个,通过%d,失败%d,未执行%d个,通过率%.2f%%。</td></tr>""" \ % (resDict['interfaceExecuteSummary']['total']+resDict['testcaseStepExecuteSummary']['total'], (resDict['interfaceExecuteSummary']['total']+resDict['testcaseStepExecuteSummary']['total']-resDict['interfaceExecuteSummary']['notrun'] - resDict['testcaseStepExecuteSummary']['notrun']), resDict['interfaceExecuteSummary']['pass']+resDict['testcaseStepExecuteSummary']['pass'], resDict['interfaceExecuteSummary']['fail'] + resDict['testcaseStepExecuteSummary']['fail'], resDict['interfaceExecuteSummary']['notrun'] + resDict['testcaseStepExecuteSummary']['notrun'], ((float(resDict['interfaceExecuteSummary']['pass']+resDict['testcaseStepExecuteSummary']['pass']) / float(resDict['interfaceExecuteSummary']['total']+resDict['testcaseStepExecuteSummary']['total'])) * 100)) if resDict['interfaceExecuteSummary']['total'] > 0: emailText = emailText + """<tr><th align="left">独立接口统计</th><td>已执行接口%d个,通过%d,失败%d,通过率%.2f%%。</td></tr>""" % (resDict['interfaceExecuteSummary']['total'], resDict['interfaceExecuteSummary']['pass'], resDict['interfaceExecuteSummary']['fail'],((float(resDict['interfaceExecuteSummary']['pass']) / float(resDict['interfaceExecuteSummary']['total'])) * 100)) if resDict['testcaseExecuteSummary']['total'] > 0: emailText = emailText + """<tr><th align="left">用例统计</th><td>已执行用例%d个,通过%d,失败%d,通过率%.2f%%。</td></tr>""" % (resDict['testcaseExecuteSummary']['total'], resDict['testcaseExecuteSummary']['pass'], resDict['testcaseExecuteSummary']['fail'],((float(resDict['testcaseExecuteSummary']['pass']) / float(resDict['testcaseExecuteSummary']['total'])) * 100)) emailText = emailText + """</table>""" #所有统计信息结束################################################################ #yewuxian mokuai统计信息################################# emailText = emailText + "<h2>%s%s统计</h2>" % (CommonConf.groupLevel1,CommonConf.groupLevel2) emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" for k,v in self.businessLineExecuteSummayDict.items(): emailText = emailText + """<tr><th align="left">%s</th><td>接口总数%d个,已执行接口%d个,通过%d,失败%d,未执行%d个,通过率%.2f%%。</td></tr>""" %( k,v['total'],(v['total']-v['notrun']),v['pass'],v['fail'],v['notrun'],((float(v['pass']) / float(v['total'])) * 100) ) for km,vm in self.moduleExecuteSummayDict[k].items(): emailText = emailText + """<tr><th align="left">%s->%s</th><td>接口总数%d个,已执行接口%d个,通过%d,失败%d,未执行%d个,通过率%.2f%%。</td></tr>""" % ( k,km, vm['total'],(vm['total']-vm['notrun']), vm['pass'], vm['fail'], vm['notrun'], ((float(vm['pass']) / float(vm['total'])) * 100) ) emailText = emailText + """</table>""" #ywwuxian mokuai统计信息结束################################# #失败接口汇总 if self.testResult != ResultConst.PASS: emailText = emailText + "<h1>(二)失败的所有接口汇总</h1>" emailText = emailText + "<h2>按照%s%s统计失败的接口和用例</h2>" % (CommonConf.groupLevel1,CommonConf.groupLevel2) # 列出失败的接口+=========================================================================== emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" emailText = emailText + """<tr><th width="20%%" align="left">%s->%s</th><th width="20%%" align="left">接口/用例ID</th><th width="50%%" align="left">描述</th><th width="10%%" align="left">结果</th></tr>""" % (CommonConf.groupLevel1,CommonConf.groupLevel2) for tmpInterface in self.taskInterfaceList: if tmpInterface.testResult != ResultConst.PASS: emailText = emailText + ("<tr><td>%s->%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (self.busiDict[str(tmpInterface.businessLineId)],self.moduleDict[str(tmpInterface.modules)],tmpInterface.interfaceId, tmpInterface.title,tmpInterface.testResult)) for tmpTestcase in self.taskTestcaseList: if tmpTestcase.testResult != ResultConst.PASS: emailText = emailText + ("<tr><td>%s->%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (self.busiDict[str(tmpTestcase.businessLineId)],self.moduleDict[str(tmpTestcase.moduleId)],tmpTestcase.caseId, tmpTestcase.title,tmpTestcase.testResult)) for i in range(0,len(tmpTestcase.stepTestcaseList)): emailText = emailText + ("<tr><td></td><td>步骤:%s</td><td>%s</td><td>%s</td></tr>" % (tmpTestcase.stepTestcaseList[i].stepNum, tmpTestcase.stepTestcaseList[i].desc,tmpTestcase.stepTestcaseList[i].testResult)) if tmpTestcase.stepTestcaseList[i].testResult!=ResultConst.PASS: break emailText = emailText + """</table>""" #列出失败的接口结束+======================================================================= #显示失败接口的执行通过率。 interfaceCountDict = resDict['interfaceCountDict'] testcaseStepInterfaceCountDict = resDict['testcaseStepInterfaceCountDict'] totalInterfaceCountDict = resDict['totalInterfaceCountDict'] if len(interfaceCountDict) > 0 : emailText = emailText + "<h2>接口中失败接口执行详情</h2>" emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" for k,v in interfaceCountDict.items(): if v['total'] != v['pass']: emailText = emailText + "<tr><th width=40%% align='left'>%s</th><td width=60%% >已执行%d次,通过%d,失败%d,通过率%.2f%%。</td></tr>" % (k,v['total'],v['pass'],v['fail'],((float(v['pass']) / float(v['total'])) * 100)) emailText = emailText + """</table>""" if len(testcaseStepInterfaceCountDict) > 0: emailText = emailText + "<h2>用例中失败接口执行详情</h2>" emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" for k,v in testcaseStepInterfaceCountDict.items(): if v['total'] != v['pass']: emailText = emailText + "<tr><th width=40%% align='left'>%s</th><td width=60%% >已执行%d次,通过%d,失败%d,通过率%.2f%%。</td></tr>" % (k,v['total'],v['pass'],v['fail'],((float(v['pass']) / float(v['total'])) * 100)) emailText = emailText + """</table>""" if len(totalInterfaceCountDict) > 0 and len(interfaceCountDict) > 0 and len(testcaseStepInterfaceCountDict) > 0: emailText = emailText + "<h2>所有接口失败执行详情</h2>" emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" for k,v in totalInterfaceCountDict.items(): if v['total'] != v['pass']: emailText = emailText + "<tr><th width=40%% align='left'>%s</th><td width=60%% >已执行%d次,通过%d,失败%d,通过率%.2f%%。</td></tr>" % (k,v['total'],v['pass'],v['fail'],((float(v['pass']) / float(v['total'])) * 100)) emailText = emailText + """</table>""" else: # task 执行结果 结果没有返回正常的json emailText = emailText + self.testResultMsg +"<br>" #self.isSendEmail 是否发送是否带附件PassFailErrorException isSendMailStr = str(self.isSendEmail) #不够6位后面补1 addOneCount = 6 - len(isSendMailStr) for i in range(0,addOneCount): isSendMailStr = isSendMailStr+"1" if int(isSendMailStr[1]) == 1: emailText = emailText + "<br>详情见附件。" else: if CommonConf.http_report_to_AWS == "1": tmpurl = self.testReportUrl else: tmpurl = EnvConfig.WEB_URI + self.testReportUrl emailText = emailText + ("<br>详情见: <a href='%s'>%s</a>" % (tmpurl,tmpurl)) emailText = emailText + "</body></html>" #结束生成emailText的html############################################################################### #开始发送邮件 def subSendMail(): if int(isSendMailStr[1]) == 1: # 发送附件 UsualTool.send_mail(emailList, subject, emailText, self.testReportFilePath, subType="html") else: # 不发送附件 UsualTool.send_mail(emailList, subject, emailText, subType="html") if self.testResult == ResultConst.PASS and int(isSendMailStr[2]) == 1: subSendMail() elif self.testResult == ResultConst.FAIL and int(isSendMailStr[3]) == 1: subSendMail() elif self.testResult == ResultConst.ERROR and int(isSendMailStr[4]) == 1: subSendMail() elif self.testResult == ResultConst.EXCEPTION and int(isSendMailStr[5]) == 1: subSendMail() else: emailList = EmailConfig.sender# ;分号间隔 subject = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % (self.testResult,self.taskId, self.title,self.execBy) emailText = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % (self.testResult,self.taskId, self.title,self.execBy) UsualTool.send_mail(emailList, subject, emailText,subType="html")
def sendEmailToExecutor(taskSuiteDict): resEmailList = taskSuiteDict["emailList"].split(",") if len(resEmailList) > 0: emailList = "" for tmpMail in resEmailList: emailList = emailList + ";" + tmpMail subject = "[%s]任务[%s:%s]测试报告" % (taskSuiteDict["testResult"], taskSuiteDict["taskSuiteId"], taskSuiteDict["title"]) if emailList == "": logging.info("邮箱列表为空,不执行邮件发送") return # 开始生成emailText的html############################################################################### """ (一)测试报告概况: 任务ID:HTTP_TASK_62 执行环境:预发布灰度 执行结果:FAIL 执行耗时:36秒 任务名称:SFA-CPQ团队-自动化测试【staging灰度环境】 任务描述:(1)【产品】PC端和APP端 (2)【价格表】&【价格表明细】PC端和APP端(3)【合同】PC端和APP端 包含ywx:['SFA'] 包含mk:['产品', '合同', '价格表'] 备注:在jenkins上执行自动化测试任务 所有统计: (1)用例统计:用例总数10个,通过7,失败3,通过率70%。【说明:因为任务中的用例都会被执行,通过率 = 通过数量 / 总数量】 (2)接口统计:接口总数500个,通过400个,失败50个,未执行50个,通过率80%。【说明:接口总数包含独立接口和用例接口之和。因为用例的靠前的接口可能失败,靠后的接口不会被执行,通过率定义方式大家可以多提建议。通过率 = 通过数量 / 总数量】 (二)失败的所有接口汇总:【说明:包含独立接口和用例接口】 (1)mk:【产品】 接口[/json/crm_product/save.action]:已执行4次,通过0,失败4,通过率0.00%。 (2)mk:【合同】 接口[/mobile/common/search.action]:已执行2次,通过1,失败1,通过率50.00%。 接口[/json/crm_common_detail/lock-data.action]:已执行1次,通过0,失败1,通过率0.00%。 详情见附件。 """ bgColor = "#f2dede" if taskSuiteDict["testResult"] == "PASS": bgColor = "#dff0d8" emailText = "<html><body style='background-color:%s;display:block;'>" % bgColor # 1、测试报告概况 emailText = emailText + (""" <h1>(一)测试报告概况</h1> <h2>任务集基本信息</h2> <table border="1px" cellpadding="3px" width="80%%"> <tr><th width="20%%" align="left">任务集ID</th><td width="80%%">%s</td></tr> <tr><th align="left">执行环境</th><td>%s</td></tr> <tr><th align="left">执行结果</th><td>%s</td></tr> <tr><th align="left">任务集名称</th><td>%s</td></tr> <tr><th align="left">任务集描述</th><td>%s</td></tr> <tr><th align="left">备注</th><td>%s</td></tr> </table>""" % ( taskSuiteDict["taskSuiteId"], taskSuiteDict["httpConfKeyAliasList"], taskSuiteDict["testResult"], taskSuiteDict["title"], taskSuiteDict["taskSuiteDesc"], (taskSuiteDict["execComments"].strip() == "" and "无" or taskSuiteDict["execComments"].strip()))) if isDictJson(taskSuiteDict["testResultMsg"]): resDict = json.loads(taskSuiteDict["testResultMsg"]) # 所有统计信息开始################################################################ emailText = emailText + "<h2>所有统计</h2>" emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" if resDict['task']['total'] > 0: emailText = emailText + """<tr><th align="left" width="20%%">所有任务统计</th><td width="80%%">任务总数%d个,通过%d,失败%d,通过率%.2f%%。</td></tr>""" \ % (resDict['task']['total'], resDict['task']['PASS'], resDict['task']['FAIL'], (float(resDict['task']['PASS']) / float(resDict['task']['total']) * 100) ) emailText = emailText + """</table>""" # 所有统计信息结束################################################################ emailText = emailText + "<h1>任务列表</h1>" # 列出失败的接口+=========================================================================== emailText = emailText + """<table border="1px" cellpadding="3px" width="80%%">""" emailText = emailText + """<tr><th width="20%%" align="left">任务ID</th> <th width="15%%" align="left">名称</th> <th width="15%%" align="left">环境</th> <th width="15%%" align="left">通过率</th> <th width="15%%" align="left">结果</th> <th width="20%%" align="left">报告</th></tr>""" for tmpTask in resDict["taskList"]: emailText = emailText + ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s%%</td><td>%s</td><td><a href='%s' target='_blank'>查看报告</a></td></tr>" % ( tmpTask["taskId"], tmpTask["taskName"], tmpTask["httpConfKey"], tmpTask['executeSummary']['total'] > 0 and "%.2f" % (float(tmpTask['executeSummary']['pass']) / float(tmpTask['executeSummary']['total']) * 100) or 0, tmpTask["testResult"], tmpTask["testReportUrl"].startswith("http") and tmpTask["testReportUrl"] or EnvConfig.WEB_URI + tmpTask["testReportUrl"])) emailText = emailText + """</table>""" # 列出失败的接口结束+======================================================================= else: # task 执行结果 结果没有返回正常的json emailText = emailText + taskSuiteDict["testResultMsg"] + "<br>" # self.isSendEmail 是否发送是否带附件PassFailErrorException isSendMailStr = str(taskSuiteDict["isSendEmail"]) # 不够6位后面补1 addOneCount = 6 - len(isSendMailStr) for i in range(0, addOneCount): isSendMailStr = isSendMailStr + "1" if int(isSendMailStr[1]) == 1: emailText = emailText + "<br>详情见链接。" else: if isReleaseEnv and CommonConf.http_report_to_AWS == "1": tmpurl = taskSuiteDict["testReportUrl"] else: tmpurl = EnvConfig.WEB_URI + taskSuiteDict["testReportUrl"] emailText = emailText + ("<br>详情见: <a href='%s'>%s</a>" % (tmpurl, tmpurl)) emailText = emailText + "</body></html>" # 结束生成emailText的html############################################################################### # 开始发送邮件 from core.tools.UsualTool import UsualTool def subSendMail(): # if int(isSendMailStr[1]) == 1: # # 发送附件 # UsualTool.send_mail(emailList, subject, emailText, self.testReportFilePath, subType="html") # else: # # 不发送附件 UsualTool.send_mail(emailList, subject, emailText, subType="html") if taskSuiteDict["testResult"] == ResultConst.PASS and int(isSendMailStr[2]) == 1: subSendMail() elif taskSuiteDict["testResult"] == ResultConst.FAIL and int(isSendMailStr[3]) == 1: subSendMail() elif taskSuiteDict["testResult"] == ResultConst.ERROR and int(isSendMailStr[4]) == 1: subSendMail() elif taskSuiteDict["testResult"] == ResultConst.EXCEPTION and int(isSendMailStr[5]) == 1: subSendMail() else: emailList = EmailConfig.sender # ;分号间隔 subject = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % (taskSuiteDict["testResult"], taskSuiteDict["taskSuiteId"], taskSuiteDict["title"], taskSuiteDict["execBy"]) emailText = "[%s]任务[%s:%s]测试报告,没有找到收件人,执行者为%s" % (taskSuiteDict["testResult"], taskSuiteDict["taskSuiteId"], taskSuiteDict["title"], taskSuiteDict["execBy"]) from core.tools.UsualTool import UsualTool UsualTool.send_mail(emailList, subject, emailText, subType="html")