def run_case(self, suites): result = BeautifulReport(suites) result.report(filename=self.report_name, tester=self.testor, title=self.title, description=self.des, log_path=self.report_path)
def run_app(): # 定义测试报告 discover = unittest.defaultTestLoader.discover(test_dir, pattern='apptest*.py') BeautifulReport(discover).report(filename='UI自动化测试报告' + now, description='测试用例', log_path='./report/')
def run_case(): """ 用例执行并打印测试报告 """ test_suite = suite() # print("打印"+str(test_suite)) # # 生成一整份用例报告 # result = BeautifulReport(test_suite) # test_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # # report_name = 'UI自动化测试报告' + '{}'.format(time.strftime('%Y-%m-%d_%H_%M_%S')) # 生成对应时间执行的报告名称 # report_name = 'UI自动化测试报告' # result.report(filename=report_name, description=report_name + test_date, report_dir='./report', # theme='theme_default') for i in test_suite: # 生成每份用例的BR报告 result = BeautifulReport(i) test_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) report_name = 'Web端UI自动化测试报告' + '{}'.format( time.strftime('%Y-%m-%d_%H_%M_%S')) # 生成对应时间执行的报告名称 # report_name = 'Web端UI自动化测试报告' report_path = globalparam.report_path result.report(filename=report_name, description=report_name + test_date, report_dir=report_path, theme='theme_default')
def case(): test_suite = unittest.defaultTestLoader.discover( '..\\testCase', pattern='formalJustbonCase.py') result = BeautifulReport(test_suite) result.report(filename='justbon_test', description='正式环境嘉宝生活家', log_path='..\\report')
def case(): test_suite = unittest.defaultTestLoader.discover( '..\\testCase', pattern='testFinanceCase.py') result = BeautifulReport(test_suite) result.report(filename='report_finance', description='收费系统测试报告', log_path='..\\report')
def run(city, case_path=casepath): discover = unittest.defaultTestLoader.discover( case_path, pattern=f"test_{city}_pencm.py", top_level_dir=None) result = BeautifulReport(discover) result.report(filename=f'{city} Report.html', description='Automation Test', log_path='./report')
def beautiful_report_run(test_class): """ BeautifulReport运行方式 :param test_class: 参数为测试类名 :return: """ suite = unittest.TestLoader().loadTestsFromTestCase(test_class) result = BeautifulReport(suite) result.report( filename=beautiful_filename, # 测试报告文件名称, 如果不指定,默认文件名为report.html description=beautiful_description, # 测试报告名称展示 report_dir=report_log_path, # 测试报告文件写入路径 theme="theme_default", # 测试报告主题样式 ) # BeautifulReport生成html测试报告 logger.info("被测环境:{}", environment) logger.info("用例总数:{}", result.testsRun) logger.info("通过总数:{}", result.success_count) logger.info("失败总数:{}", result.failure_count) logger.info("跳过总数:{}", result.skipped) logger.info("错误总数:{}", result.error_count)
def run(test_suit): description = "E7 FSSC " \ ".0自动化测试报告" result = BeautifulReport(test_suit) result.report(filename=reportName, description=description, log_path='report')
def run_test(): try: dirpath = './scripts' # discover=unittest.defaultTestLoader.discover(dirpath,pattern='*_tc.py') # dirpath = './scripts' discover = unittest.defaultTestLoader.discover(dirpath, pattern='*_tc.py') #获取不需要执行的模块名称 configpath = './po/config.xlsx' m = GetSkipScripts_P(configpath) #获取不需要执行的用例名称 casepath = './testcase/测试用例.xlsx' n = GetSkipTestCases_P(casepath) #获取不需要执行的脚本 s = get_test_suite(discover, m, n) currenttime = time.strftime('%y%m%d%H%M%S ') report_path = './report' report_name = 'report_' + currenttime result = BeautifulReport(s) result.report(filename=report_name, description='测试报告', log_path=report_path) # 链接邮箱服务器 yag = yagmail.SMTP(user="******", password="******", host="smtp.qq.com") # 邮箱正文 contents = '测试报告' # 发送邮件 yag.send('*****@*****.**', '测试报告', contents, 'D:\\project\\work\\report\\{}.html'.format(report_name)) except BaseException as msg: log = InsertLog_P() log.error(msg)
def run(test_suit): result = BeautifulReport(test_suit) now = time.strftime('%Y%m%d %H%M%S') # 获取当前时间 filename = test_report + '\\' + now + 'result.html' # 拼接出测试报告名 result.report(filename='report.html', description='测试beautiful报告', log_path='report')
def run(): suite1 = unittest.TestLoader().loadTestsFromTestCase(MyTestCase) suite = unittest.TestSuite([suite1]) result = BeautifulReport(suite) result.report(filename='测试报告', description='测试deafult报告', log_path='report')
def run_test(data, path, log_path): now = datetime.utcnow() timestamp = now.strftime('%Y-%m-%d-%H-%M-%S') context = dict() context.update({'timestamp': timestamp}, **data) description = """ 测试时间:{timestamp} 测试平台:{platformName} """.format(**context) base_report_path = '{}/{}/{}/{}'.format(log_path, now.year, calendar.month_abbr[now.month], timestamp) exception_image_path = '{}/image/exception'.format(base_report_path) normal_image_path = '{}/image/normal'.format(base_report_path) for _path in (exception_image_path, normal_image_path): os.makedirs(_path) props = ( ('BASE_REPORT_PATH', base_report_path), ('EXCEPTION_IMAGE_PATH', exception_image_path), ('NORMAL_IMAGE_PATH', normal_image_path), ) log_format = "%(asctime)s - %(levelname)s - %(message)s" logging.basicConfig(level=logging.INFO, filename='{}/report.log'.format(base_report_path), filemode='a', format=log_format) for prop in props: setattr(settings, prop[0], prop[1]) test_suite = unittest.defaultTestLoader.discover(path, pattern='test_*.py') result = BeautifulReport(test_suite) result.report( filename='测试报告', description=description, report_dir=base_report_path)
def run(self, description, filename: str = None, report_dir=".", log_path=None, theme="theme_default"): """ 运行测试套并产生报告进行存放 :param description: 见 BeautifulReport 的 report 方法参数 :param filename: 见 BeautifulReport 的 report 方法参数 :param report_dir: 见 BeautifulReport 的 report 方法参数 :param log_path: 见 BeautifulReport 的 report 方法参数 :param theme: 见 BeautifulReport 的 report 方法参数 :return: 返回新的报告名称 """ # 项目开始装配时输出文本到控制台 TextTool().project_start() # 获取新的报告名 new_filename = self.get_html_name(filename, report_dir) # 运行测试并产出报告存放 self.get_html_name(filename, report_dir) BeautifulReport(self.suites).report(filename=new_filename, description=description, report_dir=report_dir, theme=theme) # 由于可配置是否允许报告被覆盖,这里返回的是报告新名字 return new_filename
def RunTestCase(starttime, devices): print("进入", devices, "的RunTestCase") # 获取路径 configPath = "./config.ini" package = Config.getValue(configPath, "packName")[0] casepath = os.path.join(os.getcwd(), "TestCase") if not os.path.exists(casepath): print("测试用例需放到‘TestCase’文件目录下") reportpath = os.path.join(os.getcwd(), "Report") if not os.path.exists(reportpath): os.mkdir(reportpath) os.mkdir(reportpath + "/Screen") #读取ini文件,获得期望测试的用例列表 TestList = Config.getValue(configPath, "testcase") # 通过GetPyList方法,取得目录里可测试的用例列表 scriptList = File.GetPyList(casepath) suite = unittest.TestSuite() for i in range(len(TestList)): fileName = "TC_" + TestList[i] if fileName in scriptList: result = globals()[fileName].Main(devices) suite.addTests(result) unittestReport = BeautifulReport(suite) #处理模拟器端口用的冒号 if ":" in devices: devices = devices.split(":")[1] print("devices=", devices) nowtime = time.strftime("%H%M%S") unittestReport.report(filename=devices + "_" + str(nowtime), description=package, report_dir=reportpath) stop_app(package)
def run(): test_suite = create_test_suite() result = BeautifulReport(test_suite) report_file_name = "接口测试报告" + now result.report(filename=report_file_name, description="接口自动化测试报告", log_path=report_path) # 发送测试报告给指定人 sender = SendMail(smtp_server="mail.zcsmart.com", smtp_port=993, smtp_sender="*****@*****.**", smtp_senderpassword="******", smtp_receiver=send_mail_list, smtp_subject="大毛的自动化测试邮件", smtp_body="<p>接口测试报告:</p>", smtp_file='.\\Report\\report_file\\{a}.html'.format( a=report_file_name)) sender.send_mail() logger.info("邮件发送成功!") # 自动判定日志文件及报告文件的个数,若超过10条就剪切之备份文件夹,少于10条不剪切 zip_file(report_path, zip_report) # 测试报告 zip_file(logs_path, zip_log) # 日志 # 制定完毕后自动打开测试报告 try: os.system( r'C:\softuser\FireFox\firefox.exe .\Report\report_file\{a}.html'. format(a=report_file_name)) except Exception as e: logger.error("打开报告异常:{a}".format(a=e))
def run(): # test_dir = './testcase' # suite = unittest.defaultTestLoader.discover(start_dir=test_dir,pattern='test*.py') 按格式匹配加入测试集的测试用例 suite = getSuite(1) now = time.strftime('%Y-%m-%d_%H_%M_%S') initialize.del_image_file(globalparam.img_path) initialize.del_test_app_info() initialize.del_test_manage_info() lg = login.Login() lg.login() lg.login_admin() #######################使用HTMLTestRunner模板############# # reportname = globalparam.report_path + '\\' + 'TestResult' + now + '.html' # with open(reportname,'wb') as f: # runner = HTMLTestRunner.HTMLTestRunner( # stream=f, # title='测试报告', # description='Test the import testcase' # ) # runner.run(suite) ########################################################## ###################使用BeautifulReport模板######################## result = BeautifulReport(suite) result.report(filename='TestResult' + now, description="智能版基础用例", log_path=globalparam.report_path) ################################################################## time.sleep(3) # 发送邮件 mail = sendmail_2.SendMail() mail.send()
def run(self): """ run test :return: """ try: suit = self.set_case_suite() if suit is not None: logger.info("********TEST START********") # fp = open(resultPath, 'wb') # runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='Test Report', description='Test Description') # runner.run(suit) result = BeautifulReport(suit) result.report(filename='测试报告', description='测试deafult报告', log_path=resultPath) else: logger.info("Have no case to test.") except Exception as ex: logger.error(str(ex)) finally: logger.info("*********TEST END*********") # fp.close() # send test report by email if on_off == 'on': self.email.send_email() elif on_off == 'off': logger.info("Doesn't send report email to developer.") else: logger.info("Unknow state.")
def toreport(self): logger().info('开始读取unittest测试核心目录') base_path=os.path.dirname(os.path.abspath(__file__)) dir_path=os.path.join(base_path,unittest_path) print(dir_path) logger().info('开始discover到测试') try: discover=unittest.defaultTestLoader.discover(dir_path,pattern='*.py') except Exception as e: logger().error("加载测试用例路径失败,请查看报错原因:{0}".format(e)) #报告命名加上时间格式 logger().info('设置报告名称格式') time=datetime.now() now=time.strftime('%Y-%m-%d %H_%M_%S') #报告绝对路径 reportname=report_path+now reportpath=reportname+'result.html' #打开文件,写入测试结果 logger().info('执行测试用例开始.......') try: # # f=open(reportpath,'a') # runner=HTMLTestRunner(stream=f,verbosity=2,report_title='接口用例测试报告') # runner.run(discover) # f.close() result=BeautifulReport(discover) result.report(description='用例执行详细信息',filename=reportname+'result') logger().info('写入报告成功') except Exception as e: logger().error("执行用例失败,请查看报错原因:{0}".format(e)) logger().info("执行测试用例结束。。。。。。。。。。。。。") sendemail().send_mail(reportpath)
def RunTestCase(madb,start): devices=madb.get_mdevice() print("进入{}的RunTestCase".format(devices)) # 获取路径 package = madb.get_packagename() TestCasePath = madb.get_TestCasePath() print("TestCasePath=",TestCasePath) if not os.path.exists(TestCasePath): print("测试用例需放到‘TestCase’文件目录下") reportpath = os.path.join(os.getcwd(), "Report") #读取ini文件,获得期望测试的用例列表 TestList=madb.get_testcaseforselfdevice() print("{}的待测用例为:{}".format(madb.get_mdevice(),TestList)) # 通过GetPyList方法,取得目录里可测试的用例列表 scriptList = File.GetPyList(TestCasePath) suite = unittest.TestSuite() for i in range(len(TestList)): fileName = "TC_" + TestList[i] print("fileName=",fileName) if fileName in scriptList: print("进入循环") #在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其Main函数。 result = globals()[fileName].Main(devices) suite.addTests(result) #聚合报告到BR unittestReport = BeautifulReport(suite) nowtime=time.strftime("%H%M%S",start) #unittestReport.report(filename=madb.get_nickdevice()+"_"+str(nowtime),description=package, report_dir=reportpath,rundevice=madb.get_mdevice()) # unittestReport.report(filename=madb.get_nickname()+"_"+str(nowtime),description=package, report_dir=reportpath) unittestReport.report(filename=madb.get_nickname()+"_report",description=package, log_path=reportpath) stop_app(package)
def run(self): """ run test :return: """ try: suit = self.set_case_suite() # 只执行set_case_suite方法中返回的应该执行的case # suit = unittest.defaultTestLoader.discover(".", pattern="test*.py", top_level_dir=None) #执行所有test开头的case print('try') print(str(suit)) if suit is not None: # 判断test_suite是否为空 print('if-suit') fp = open(resultPath, 'wb') # 打开result/20181108/report.html测试报告文件,如果不存在就创建 # 调用HTMLTestRunner # runner = HTMLTestRunner(stream=fp,title='万人万店接口自动化测试报告', description='接口测试统计' ) # runner.run(suit) run = BeautifulReport(suit) run.report(description='万人万店接口测试统计', filename='万人万店接口自动化测试报告2') else: print("Have no case to test.") except Exception as ex: print(str(ex)) finally: print("*********TEST END*********") # log.info("*********TEST END*********") fp.close() # 判断邮件发送的开关 if on_off == 'on': # 测试发送QQ邮件 test_path = os.getcwd() # "D:\\pycharm\\test02\\" newget_report = new_report(test_path) send_mail(newget_report) else: print("邮件发送开关配置关闭,请打开开关后可正常自动发送测试报告")
def run_test(path: str = 'testcase'): """ :param path: With default path testcase, the method will execute all testcases, otherwise it only execute the cases which in the specific path :return: test report """ report_name = "{}_{}".format(path, str(datetime.now().strftime("%Y%m%d%H%M"))) testsuits = TestSuite() if path == 'testcase': for dir in os.listdir(os.path.join(os.curdir, path)): testsuits.addTests( unittest.defaultTestLoader.discover(dir, pattern='*test.py', top_level_dir='testcase')) else: testsuits.addTests( unittest.defaultTestLoader.discover(path, pattern='*test.py', top_level_dir='testcase')) result = BeautifulReport(testsuits) result.report(filename=report_name, description=path, log_path='result') shutil.copy('result/%s.html' % report_name, 'result/test_api_ressult.html') if result.failure_count or result.error_count: #主动出发失败导致jenkins失败 raise Exception("主动失败,发送邮件")
def run_case(suites): result = BeautifulReport(suites) result.report(filename=report_name, tester='非攻', title='自动化测试报告', description='百度、CSDN、慕课用例批量执行测试', log_path=report_path)
def report(ts,file='report.html',report_dir='.',title='测试报告',description=None,tester = "beidouxing",type_='htr'): """ :param ts: 测试套件 :param file:测试报告名称 :param report_dir:测试报告路径 :param title: 测试标题 :param description: 测试描述 :param tester:测试人 :return: """ #在文件名加上时间 file = "{}--{}".format(datetime.now().strftime('%Y-%m-%d %H时%M分%S秒'),file); #检测目录是否存在,不存的话要创建 if not os.path.exists(report_dir): os.makedirs(report_dir); #拼接报告名称 file_path = os.path.join(report_dir,file); #生成htmlreport报告 if type_.lower() =='htr': with open(file_path, 'wb') as fb: # 生成测试报告,这一块不需要添加encoding='utf8'这个参数 html_01 = HTMLTestRunner(stream=fb, description=description, title=title, tester=tester); html_01.run(ts); # 执行suit #可以组装多个类型的测试报告 elif type_.lower() == 'br': BeautifulReport(ts).report(filename=file,description=description,report_dir=report_dir); # if __name__ == '__main__': # ts = 1; # report(ts,file='report.html',report_dir='.',title='测试报告',description=None,tester = "beidouxing")
def RunTestCase(madb, start): # 获取设备列表 devices = madb.get_mdevice() logger.info("进入{}的RunTestCase".format(devices)) # 获取是否跳过生成测试报告 skip_report = madb.get_skip_report() report_flag = True if skip_report == "1" else False # 获取jenkins部署信息 jenkins_branch, timestamp = jenkins_lastBuild_info() logger.info('jenkins分支:{}'.format(jenkins_branch)) timeArray = time.localtime(timestamp / 1000) jenkins_time = time.strftime("%Y--%m--%d %H:%M:%S", timeArray) logger.info('部署时间:{}'.format(jenkins_time)) # 获取手机型号 command = adb + " -s {} shell getprop ro.product.model".format(devices) brand = os.popen(command).read() # 获取手机版本 command1 = adb + " -s {} shell getprop ro.build.version.release".format( devices) version = os.popen(command1).read() # 获取路径 package = madb.get_packagename() TestCasePath = madb.get_TestCasePath() if not os.path.exists(TestCasePath): logger.error("测试用例需放到‘TestCase’文件目录下") reportpath = os.path.join(os.getcwd(), "Report") # 读取ini文件,获得期望测试的用例列表 TestList = madb.get_testcaseforselfdevice() logger.info("{}的待测用例为:{}".format(madb.get_mdevice(), TestList)) # 通过GetPyList方法,取得目录里可测试的用例列表 scriptList = File.GetPyList(TestCasePath) # 初始化测试套件 suite = unittest.TestSuite() # 初始化poco poco = AndroidUiautomationPoco() for i in range(len(TestList)): fileName = "TC_" + TestList[i] logger.debug("fileName={}".format(fileName)) if fileName in scriptList: # 在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其run_case函数。 result = globals()[fileName].run_case(devices, poco) # 根据result类型判断调试单个方法or全部方法 if isinstance(result, unittest.suite.TestSuite): suite.addTests(result) else: suite.addTest(result) # 聚合报告到BR unittestReport = BeautifulReport(suite) nowtime = time.strftime("%Y%m%d%H%M%S", start) unittestReport.report(filename=madb.get_nickname() + "_" + str(nowtime), description=package, report_dir=reportpath, brand=brand, version=version, jenkins_branch=jenkins_branch, jenkins_time=jenkins_time, report_flag=report_flag)
def runner(city): discover = unittest.defaultTestLoader.discover( ".", pattern=f"test_{city}_1*.py", top_level_dir=None) city1 = city.title() BeautifulReport(discover).report(filename=f"{city1} Test Report {nowtime}", description='Automation Test', log_path='./report')
def command_line_runner(): if sys.version < '3': raise SystemExit('请使用Python 3.0.0以上的版本^^') # 获得命令行参数解析器 parser = get_parser() # 解析命令行参数 args = parser.parse_args() report_type = args.report_type # 当前文件所在目录 current_file_dir = os.path.dirname(__file__) # 定义测试用例的目录 test_dir = os.path.join(current_file_dir, 'app/case') # 定义测试套件 suite = unittest.defaultTestLoader.discover(test_dir, pattern='Test*.py') # suite1 = unittest.TestLoader().loadTestsFromModule(TestLogin) # suite2 = unittest.defaultTestLoader.discover(test_dir, pattern='Test*.py') # suite = unittest.TestSuite([suite1, suite2]) # 按照一定的格式获取当前的时间 now = time.strftime("%Y-%m-%d %H_%M_%S") # 定义报告存放路径、报告文件名 test_report_path = os.path.join(current_file_dir, 'report/') filename = now + "_test_result.html" if report_type == 1: # 使用HTMLTestRunner生成测试报告 with open(test_report_path + filename, 'wb') as fp: runner = HTMLTestRunner(stream=fp, title="测试统计报告", description="测试用例执行统计报告") runner.run(suite) # 最新测试报告 new_report_file = GlobalFunction.new_report(test_report_path) # 邮件内容, 这里读取最新的一个测试报告 with open(new_report_file, 'rb') as fp: mail_content = fp.read() elif report_type == 2: # 使用BeautifulReport生成测试报告 result = BeautifulReport(suite) result.report(filename=filename, description="测试用例执行统计报告", log_path=test_report_path) # 可以从result中获取用例个数 mail_content = "用例总数为{total}, 成功用例个数为{success}, 失败用例个数为{failure}, 错误用例个数为{error}".format( total=result.testsRun, success=result.success_count, failure=result.failure_count, error=result.error_count) # 发送邮件 send_email(args.email, mail_content)
def run(test_suit): #now=time.strftime("%Y-%m-%d %H_%M_%S") #report_name=now+"report.html" result = BeautifulReport(test_suit) result.report(filename=report_name, description='天马商城自动化测试报告', log_path='report') time.sleep(2) new_report_addr=acquire_report_address(reportpath) send_email(new_report_addr)
def run_case(all_case): '''执行所有的用例, 并把结果写入测试报告''' result = BeautifulReport(all_case) path = os.path.abspath('..') finalpath = path + "\Report" #nowday = time.strftime('%Y%m%d%H%M', time.localtime()) #filename='ip价值评估测试报告'+nowday result.report(filename="ip价值评估测试报告", description="", log_path=finalpath)
def run(self): while not self.queue.empty(): tests = self.queue.get() result = BeautifulReport(tests) result.report(description="测试报告", log_path="report", filename="自动化测试报告") self.queue.task_done()
def run(): filename = os.path.join(os.path.dirname(__file__), 'test_report', get_now_time() + 'UIReport.html') fp = open(filename, 'w') result = BeautifulReport(allTests()) result.report(filename=get_now_time() + 'Report', description='UI自动化测试报告', log_path='reports')