def __init__(self,xml,log,html,opt,inform=None,**kdb): if xml is None: raise Exception('the path of xml is empty') if log is None: raise Exception('the path of log is empty') if html is None: raise Exception('the path of html is empty') #database con = None if kdb.get('start-up'): import Databases if kdb['engine'] == 'mysql': con = Databases.mysql('mysql')(**kdb['settings']) #xml varmap = Config.load_xml(xml) #log self.logger=Loger() self.logger.Open(log) #html self.fp_html = open(html, 'wb') #create the IContext,and Gather self.ctx = IContext(varmap=varmap,logger=self.logger,opt=opt,con=con) self.gather = Gather.Gather(HTMLTestRunner._TestResult(1), \ htmlhelper=HTMLHelper(stream=self.fp_html, title='FTTReport', description='This is the report for FTT framework'))
#生成测试报告 now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) now_hour = time.strftime("%Y-%m-%d-%H", time.localtime(time.time())) dir1 = os.path.abspath(os.path.dirname(__file__)) dir2 = os.path.join(dir1, 'log') dir2 = os.path.join(dir2, 'report') html_filename = os.path.join(dir2, "report" + now + "result.html") picture_name = os.path.join(os.path.join(dir1, 'screenshot'), now_hour + ".jpg") listpart = [html_filename, picture_name] fp = getReport.MakeReport(html_filename) runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='UFA自动化', description='众家联PC端自动化测试报告') result = runner.run(suite) testResult = HTMLTestRunner._TestResult() runNumber = int(str(result)[str(result).find('run') + 4]) errorNumber = int(str(result)[str(result).find('errors') + 7]) failuresNumber = int(str(result)[str(result).find('failures') + 9]) log1.info(result) fp.close() to_addr_list = ['*****@*****.**'] #to_addr_list = ['*****@*****.**', '*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**'] if errorNumber > 0 or failuresNumber > 0: text = "自动化测试用例失败,请及时定位,其中:运行用例数=" + str(runNumber) + "; error=" + str( errorNumber) + "; failure=" + str(failuresNumber) sendEmail.SendEmail(listpart, text, to_addr_list) else: text = "自动化测试用例正常,网站正常打开。本次是测试邮件,以后会在异常的时候再发邮件。每天8点和14点自动执行一次" #sendEmail.SendEmail(listpart, text,to_addr_list) log1.info("end")
t = ThreadClass(testDict,options.mode) tList.append(t) t.start() #t.join() #the thread (case )will be run one by one, not simultaneously for t in tList: #the thread (case )run simultaneously t.join() if options.indication=='yes': stopListen(p) if __builtin__.htmlReport: #generate HTML report allTests=unittest.TestSuite() allTestResults=HTMLTestRunner._TestResult() allResult=[] allSuccess_count=0 allfailure_count=0 allerror_count=0 threadList= __builtin__.resultG.keys() threadList.reverse() #let report show in Thread1, 2, 3 sequence from top to bottom for i in threadList: test=__builtin__.testG[i] result=__builtin__.resultG[i] for b in result.result: