def logger(self): """ 封装一个记录的日志方法 :return: """ # 创建一个logger logger = logging.getLogger("myLogger") logger.setLevel(logging.DEBUG) # 创建一个handler,用于写入日志文件 conf = Config("FilePath") log_path=conf.get_path_config(self.logs) log_file = logging.FileHandler(SystemOs().sys_path(log_path)) log_file.setLevel(logging.DEBUG) # 再创建一个handler,用于输出到控制台 console = logging.StreamHandler() console.setLevel(logging.DEBUG) # 定义handler的输出格式 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') log_file.setFormatter(formatter) console.setFormatter(formatter) # 给logger添加handler logger.addHandler(log_file) logger.addHandler(console) return logger
def sendEmail(self): config = Config("Email") fromAddress = config.get_email("fromaddress") password = config.get_email("password") toAddress = config.get_email("toAddress").split(",") #主题 content = "您好:\n 测试已完成,详情请查看附件报告!\n 祝好" textApart = MIMEText(content) m = MIMEMultipart() openFile = open(self.reportPath, 'rb') addFile = openFile.read() apart = MIMEApplication(addFile) openFile.close() apart.add_header('Content-Disposition', 'attachment', filename="report.html") m.attach(apart) m.attach(textApart) now_time = datetime.datetime.now().strftime('%Y-%m-%d') m["Subject"] = "自动化测试报告" + now_time try: server = smtplib.SMTP('smtp.163.com') server.login(fromAddress, password) server.sendmail(fromAddress, toAddress, m.as_string()) print('success') server.quit() except smtplib.SMTPException as e: print(traceback.format_exc())
def childConfigXML(self,Pageskeyword,UIElementkeyword): confFile = self.rootChildConfigPath() config2 = Config("XMLFilePath", confFile) filepath = config2.get_path_config("uilogin") filepath = SystemOs().sys_path(filepath) xmlspath = XmlUtil(filepath) # 获取XML中相关信息 xmls = xmlspath.xml_parsing(Pageskeyword, UIElementkeyword) return xmls
def childConfigXlsx(self,sheet,dictData): # "获取子配置文件中信息",loginXlsx confFile = self.rootChildConfigPath() config1= Config("XlsxFilePath",confFile) loginXlsx = config1.get_path_config("user_login") loginXlsx = SystemOs().sys_path(loginXlsx) #dictData = {"userName": 3, "password": 4, "expected": 6} excelUtil = DoExcel(loginXlsx, sheet).do_excel(**dictData) return excelUtil
def childConfigImgPath(self): """ 获取图片路径,并新建以日期为基础的文件目录名 例如: img/2019-01-01/ :return: """ confFile = self.rootChildConfigPath() config3 = Config("ImgPath",confFile) img_path = config3.get_path_config("error_img") data_path = TestDateTime().local_day() img_path = SystemOs().sys_path(img_path,data_path) SystemOs().mkdirs_file(img_path) return img_path
def get_configMySql(self): conf= Config('MySqlDB') self.host = conf.get_mysqldb("db_host") self.uname = conf.get_mysqldb("db_user") self.passwd = conf.get_mysqldb("db_pwd") self.sqltable = conf.get_mysqldb("db_table") self.port = int(conf.get_mysqldb("db_port"))
def rootChildConfigPath(self): # 从主配置文件中获取子配置文件路径 conf2 = Config("ConfigKIDs") # 获取子文件路径 confFile = conf2.get_configPath("markerting_points_configs") return confFile
def rootConfigURL(self): # 从主配置文件Config中获取URL conf1 = Config("URL") url = conf1.get_url_config("marketing") return url
def childConfigTestFile(self): # "获取子配置文件中信息",testFile confFile = self.rootChildConfigPath() config1 = Config("TestFile", confFile) testFile = config1.get_path_config("mprTestFile") return testFile
def childConfigReport(self): # "获取子配置文件中信息",report confFile = self.rootChildConfigPath() config1 = Config("ReportFile", confFile) mpreport = config1.get_path_config("mpReport") return mpreport