def run(self): try: suit = self.set_case_suite() self.logger = MyLog.get_log() reprotPath = os.path.join(readConfig.proDir,"result",os.listdir(os.path.join(readConfig.proDir,"result"))[-1],"report.html") print(reprotPath) #self.reprotPath = os.path.join(os.path.join(os.path.join(readConfig.proDir, "result"), str(datetime.now().strftime("%Y%m%d%H%M"))),"report.html") #self.reprotPath = os.path.join(str(MyLog.get_path()), "report.html") if suit is not None: self.logger.logger.info("********TEST START********") fp = open(reprotPath, 'wb') runner = MyHTMLTestRunner.HTMLTestRunner(stream=fp, title='接口测试报告', description='登陆接口测试') runner.run(suit) else: self.logger.logger.info("Have no case to test.") except Exception as ex: self.logger.logger.error(str(ex)) finally: self.logger.logger.info("*********TEST END*********") localReadConfig = readConfig.ReadConfig() self.email = MyEmail().get_email() # send test report by email if int(localReadConfig.get_email("on_off")) == 0: #pass self.email.send_email() elif int(localReadConfig.get_email("on_off")) == 1: self.logger.logger.info("Doesn't send report email to developer.") else: self.logger.logger.info(" Unknow state.")
def run(self): """ run test :return: """ global fp try: fp = open(resultPath, 'wb') suite = self.set_case_suite() if suite is not None: logger.info("*********TEST START***********") runner = HTMLTestRunnerCN.HTMLTestRunner( stream=fp, title="Test Report", description="Test Description") runner.run(suite) else: logger.info("Have no case to test") except Exception as ex: logger.error(str(ex)) finally: MyEmail.get_email() logger.info("**********TEST ENDING***********") fp.close()
def __init__(self): '''初始化''' global log, logger, resultPath, on_off log = Log.get_log() logger = log.get_logger() resultPath = log.get_report_path() on_off = localReadConfig.get_email("on_off") self.caseListFile = os.path.join(readConfig.proDir, "gotham_caselist.txt") self.caseFile = os.path.join(readConfig.proDir, "testCase") # self.caseFile = None self.caseList = [] self.email = MyEmail.get_email() '''定义接口测试报告的title''' MyEmail.get_email().subject="gotham接口测试报告" + " " + MyEmail.get_email().date
def run(self): """ run test :return: """ try: print '获取测试套件...' suite = self.set_case_suite() if suite is not None: logger.info("********测试 开始!********") fp = open(resultPath, 'w+') runner = HTMLTestRunner.HTMLTestRunner( stream=fp, title='Test Report', description='若要查看详细结果,请下载附件查看!') runner.run(suite) else: logger.info("Have no case to test.") except Exception as ex: logger.error(str(ex)) finally: logger.info("*********测试 结束!*********") fp.close() # send test report by email if on_off == 'on': print '开始发送邮件...' send_email = MyEmail.get_email() send_email.send_email() print '邮件发送完成...' elif on_off == 'off': logger.info("不需要发动邮件给任何人!") else: logger.info("是否发送邮件的状态码书写错误!")
def __init__(self, devicePlatN, devicePlatV, deviceName, deviceID, devicePort): global log, logger global on_off self.devicePlatN = devicePlatN self.devicePlatV = devicePlatV self.deviceName = deviceName self.deviceID = deviceID self.devicePort = devicePort #实例化LOG, log = Log.get_log() logger = log.get_logger() #每个测试终端生成测试报告的文件地址和文件名 self.resultPath = log.get_report_path(self.deviceID) #获取配置文件中是否通过邮件发送报告的开关值on_off on_off = localReadConfig.get_email("on_off") #实例化发送邮件 self.email = MyEmail.get_email() #读取需要执行的测试用例的文件 self.caseListFile = os.path.join(readConfig.proDir, "caselist.txt") self.caseFile = os.path.join(readConfig.proDir, "testCase") self.caseList = []
def __init__(self): self.reportpath = log.get_report_path() testcasedir = localReadConfig.get_testcasedir("dir") self.caseListFile = os.path.join(readConfig.proDir, "caselist.txt") self.caseFile = os.path.join(readConfig.proDir, "testCase") + '\\' + testcasedir self.caseList = comm.get_testcase_from_txt() self.email = MyEmail.get_email()
def __init__(self): global log, logger, resultPath, on_off log = Log.get_log() logger = log.get_logger() resultPath = log.get_report_path() on_off = localReadConfig.get_email("on_off") self.caseListFile = os.path.join(readConfig.proDir, "caselist.txt") self.caseFile = os.path.join(readConfig.proDir, "testCase") self.caseList = [] self.email = MyEmail.get_email()
def __init__(self): global log, logger, resultPath, on_off #初始化变量 log = MyLog.get_log() #启动MyLog的 # get_log方法开启锁,get_log中又启动Log进行初始化 logger = log.get_logger() #获取记录 resultPath = log.get_report_path() #生成报告路径 on_off = localReadConfig.get_email("on_off") #邮件开关 self.caseListFile = os.path.join(readConfig.proDir, "caselist.txt") #设置caselist路径,配置每次执行的case self.caseFile = os.path.join(readConfig.proDir, "testCase") #设置testCase路径 # self.caseFile = None self.caseList = [] self.email = MyEmail.get_email() #邮件操作
def __init__(self): global log, Logger, resultPath, on_off,report_path log = MyLog.get_log(logger="AllTest") Logger = log.get_logger() report_path = log.get_report_path() #resultPath = log.get_result_path() on_off = localReadConfig.get_email("on_off") self.caseListFile = os.path.join(readConfig.proDir, "config_file\\testlist.ini") #accept file test self.caseFile = os.path.join(readConfig.proDir, "test_case") print(self.caseFile) # self.caseFile = None self.caseList = [] self.email = MyEmail.get_email()
def __init__(self): global log, logger, resultpath, on_off log = Log.get_log() logger = log.get_logger() on_off = localReadConfig.get_email("on_off") self.email = MyEmail.get_email()
class Runall: def set_case_list(self): self.casepath = os.path.join(readConfig.proDir,"caselist.txt") self.caseList =[] fb = open(self.casepath,"r",encoding="UTF-8") for value in fb.readlines(): data = str(value) if data != '' and not data.startswith("#"): self.caseList.append(data.replace("\n", "")) fb.close() def set_case_suite(self): self.set_case_list() test_suite = unittest.TestSuite() suite_model = [] for case in self.caseList: case_file = os.path.join(readConfig.proDir, "testCase") #print(case_file) case_name = case.split("/")[-1] #print(case_name+".py") discover = unittest.defaultTestLoader.discover(case_file, pattern=case_name + '.py', top_level_dir=None) suite_model.append(discover) if len(suite_model) > 0: for suite in suite_model: for test_name in suite: test_suite.addTest(test_name) else: return None return test_suite def run(self): try: suit = self.set_case_suite() self.logger = MyLog.get_log() reprotPath = os.path.join(readConfig.proDir,"result",os.listdir(os.path.join(readConfig.proDir,"result"))[-1],"report.html") print(reprotPath) #self.reprotPath = os.path.join(os.path.join(os.path.join(readConfig.proDir, "result"), str(datetime.now().strftime("%Y%m%d%H%M"))),"report.html") #self.reprotPath = os.path.join(str(MyLog.get_path()), "report.html") if suit is not None: self.logger.logger.info("********TEST START********") fp = open(reprotPath, 'wb') runner = MyHTMLTestRunner.HTMLTestRunner(stream=fp, title='接口测试报告', description='登陆接口测试') runner.run(suit) else: self.logger.logger.info("Have no case to test.") except Exception as ex: self.logger.logger.error(str(ex)) finally: self.logger.logger.info("*********TEST END*********") localReadConfig = readConfig.ReadConfig() self.email = MyEmail().get_email() # send test report by email if int(localReadConfig.get_email("on_off")) == 0: #pass self.email.send_email() elif int(localReadConfig.get_email("on_off")) == 1: self.logger.logger.info("Doesn't send report email to developer.") else: self.logger.logger.info(" Unknow state.")