def page_sliding_to_right(self, node_kw, key, long=100000): read_ini = ReadIni(node=node_kw) data = read_ini.get_value(key) value = data.split('>')[1] num = int(data.split('>')[2]) js = "var q=document.getElementsByClassName('{}')[{}].scrollLeft={}".format( value, num, long) self.driver.execute_script(js)
def test_1(self): """ 登录流程 """ self.log.info('TestCase1 Start Running') # 获取用户名和密码 username = ReadIni('Sys_config.ini', 'Base').get_value('username') password = ReadIni('Sys_config.ini', 'Base').get_value('password') # 获取Org名称 org_name = self.login.login_suc(username, password) self.assertEqual('重构测试Rock', org_name, '机构名称不一致 --- 测试用例不通过')
def __init__(self): self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) formatter = logging.Formatter( '[%(asctime)s]-[%(levelname)s] %(filename)s--> %(funcName)s ----->%(message)s' ) # 设置控制台日志信息 console = logging.StreamHandler() console.setFormatter(formatter) # 设置级别日志级别,Logging中有NOTSET < DEBUG < INFO < WARNING < ERROR < CRITICAL这几种级别,日志会记录设置级别以上的日志 console.setLevel(logging.DEBUG) self.logger.addHandler(console) # 生成日志文件的开关,为debug模式,不生成文件 if ReadIni('Sys_config.ini', 'Base').get_value('is_debug') == 'False': # 生成文件路径 file_name = datetime.datetime.now().strftime("%Y-%m-%d") + ".log" # 获取当前目录的绝对路径 cur_path = os.path.abspath(__file__) # 获取logs文件夹的绝对路径 logs_path = os.path.join(os.path.abspath(os.path.dirname(cur_path) + os.path.sep + '../logs/'), '') # 设置文件日志信息 file_handle = logging.FileHandler(logs_path + file_name, mode='a', encoding='utf-8') file_handle.setFormatter(formatter) file_handle.setLevel(logging.INFO) self.logger.addHandler(file_handle)
def get_element(self, node_kw, key): read_ini = ReadIni(node=node_kw) data = read_ini.get_value(key) by = data.split('>')[0] value = data.split('>')[1] num = int(data.split('>')[2]) try: if by == 'id': return self.driver.find_elements_by_id(value)[num] elif by == 'name': return self.driver.find_elements_by_name(value)[num] elif by == 'classname': return self.driver.find_elements_by_class_name(value)[num] elif by == 'xpath': return self.driver.find_element_by_xpath(value) except Exception: raise NameError('选择器错误!')
class SendEmail(object): def __init__(self, file_path): self.file_path = file_path self.info = ReadIni('Sys_config.ini', 'Email') def new_report(self): report_list = os.listdir(self.file_path) report_list.sort( key=lambda fn: os.path.getmtime(self.file_path + "\\" + fn)) file_new = os.path.join(self.file_path, report_list[-1]) print("测试结束,报告路径: " + file_new) return file_new def send_mail(self, report_file): # 邮件配置信息 smtpserver = 'smtp.qq.com' user = self.info.get_value('EMAIL_ADDRESS') password = self.info.get_value('PASSWORD') sender = self.info.get_value('EMAIL_ADDRESS') receiver = ["*****@*****.**"] msg = MIMEMultipart() msg['Subject'] = Header('UI自动化测试报告', 'utf-8') msg["From"] = sender msg["To"] = ",".join(receiver) # 邮件正文内容 msg.attach( MIMEText('附件为本次UI自动化测试报告,为保证最佳浏览效果,请使用Chrome打开查看', 'plain', 'utf-8')) # 构造附件,传入最新的测试报告文件 sendfile = open(report_file, 'rb').read() att = MIMEText(sendfile, 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="UITestReport.html"' msg.attach(att) smtp = smtplib.SMTP_SSL("smtp.qq.com", 465) smtp.connect(smtpserver) smtp.login(user, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() print("邮件发送成功")
def setUpClass(cls) -> None: # 初始化开始 LogInfo().log.info('Initialization Start') cls.driver = SelectBrowser().select_browser('chrome') cls.dr = PySelenium(cls.driver) cls.dr.test_url( ReadIni('Sys_config.ini', 'Base').get_value('website_url')) cls.dr.maximize_window() # 初始化结束 LogInfo().log.info('Initialization Completed') # 前置条件:登录系统 LogInfo().log.info('Preposition: Login System') username = ReadIni('Sys_config.ini', 'Base').get_value('username') password = ReadIni('Sys_config.ini', 'Base').get_value('password') cls.login = LoginBusiness(cls.driver) cls.login.login_suc(username, password) # 选择校区 cls.campus_select = HomeBusiness(cls.driver) cls.campus_select.select_campus(4) cls.log.info('Campus Selected') # 员工管理业务流程 LogInfo().log.info('Account Cases Suite Start Running') cls.account = AccountBusiness(cls.driver) # 课程管理业务流程 LogInfo().log.info('Course Cases Suite Start Running') cls.course = CourseBusiness(cls.driver) # 班级管理业务流程 LogInfo().log.info('Class Cases Suite Start Running') cls.classroom = ClassBusiness(cls.driver) # 班级管理业务流程 LogInfo().log.info('Customer Cases Suite Start Running') cls.customer = CustomerBusiness(cls.driver)
def setUpClass(cls) -> None: # 初始化开始 LogInfo().log.info('Initialization Start') cls.driver = SelectBrowser().select_browser('chrome') cls.dr = PySelenium(cls.driver) cls.dr.test_url( ReadIni('Sys_config.ini', 'Base').get_value('website_url')) cls.dr.maximize_window() # 初始化开始 LogInfo().log.info('Initialization Completed') # 登录业务流程-测试用例 LogInfo().log.info('Login Cases Suite Start Running ') cls.login = LoginBusiness(cls.driver)
def get_element(self, node_kw, key): read_ini = ReadIni(node=node_kw) data = read_ini.get_value(key) by = data.split('>')[0] value = data.split('>')[1] num = int(data.split('>')[2]) element = None try: web_driver_wait = WebDriverWait(self.driver, 10, 0.5) if by == 'id': element = web_driver_wait.until( ec.presence_of_all_elements_located((By.ID, value))) elif by == 'name': element = web_driver_wait.until( ec.presence_of_all_elements_located((By.NAME, value))) elif by == 'classname': element = web_driver_wait.until( ec.presence_of_all_elements_located( (By.CLASS_NAME, value))) elif by == 'xpath': element = web_driver_wait.until( ec.presence_of_all_elements_located((By.XPATH, value))) elif by == 'tag': element = web_driver_wait.until( ec.presence_of_all_elements_located((By.TAG_NAME, value))) elif by == 'css': element = web_driver_wait.until( ec.presence_of_all_elements_located( (By.CSS_SELECTOR, value))) # 页面未找到该元素,返回False except (NoSuchElementException, IndexError, TimeoutException): return False # 没有发生异常,说明已找到该元素,返回该元素 else: return element[num]
def get_element(self, node_kw, key): read_ini = ReadIni(node=node_kw)
# -*- coding: utf-8 -*- # @Time : 2019/6/12 13:23 # @Author : DannyDong # @File : run.py # @describe: 程序主入口 import time from Utils.read_ini import ReadIni from Utils.send_email import SendEmail from Utils.HTMLTestRunner_cn import HTMLTestRunner from Test.CaseSuite.case_suite import case_suite suite = case_suite() read_ini = ReadIni('Sys_config.ini', 'Report') url = read_ini.get_value('REPORTURL') if __name__ == '__main__': filename = url + time.strftime('%Y%m%d%H%M%S', time.localtime( time.time())) + 'result.html' fp = open(filename, 'wb') runner = HTMLTestRunner(stream=fp, title='UI自动化测试报告', description='Demo Test') runner.run(suite) fp.close() # 发送邮件开关is_debug,debug模式下,不发送邮件 if ReadIni('Sys_config.ini', 'Base').get_value('is_debug') == 'True':
def __init__(self): read_ini = ReadIni('Sys_config.ini', 'HotScreen') self.url = read_ini.get_value('SCREENSHOTURL')
# -*- coding: utf-8 -*- # @Time : 2019/6/12 13:23 # @Author : DannyDong # @File : run.py # @describe: 程序主入口 import time from Utils.webhook import WebHook from Utils.read_ini import ReadIni from Utils.send_email import SendEmail from Utils.HTMLTestRunner_cn import HTMLTestRunner from Test.CaseSuite.case_suite import case_suite # 获取WebHook要@的人 phone = ReadIni('Sys_config.ini', 'WEBHOOK').get_value('phone') # 如果是debug模式,不发生WebHook if ReadIni('Sys_config.ini', 'Base').get_value('is_debug') == 'False': # WebHook发送开始通知 WebHook().web_hook('UI自动化测试任务开始', phone) # 实例化测试集 suite = case_suite() read_ini = ReadIni('Sys_config.ini', 'Report') url = read_ini.get_value('REPORTURL') filename = url + time.strftime('%Y%m%d%H%M%S', time.localtime( time.time())) + 'result.html' fp = open(filename, 'wb')
def __init__(self, file_path): self.file_path = file_path self.info = ReadIni('Sys_config.ini', 'Email')
def __init__(self): self.url = ReadIni('Sys_config.ini', 'WEBHOOK').get_value('web_hook_url')