def __init__(self, path): self.wcfconfig = wcfconfig(path) self.db = database(self.wcfconfig) self.config = configuration(self.db, self.wcfconfig) self.logger = logger(self.db) self.cpnr = self.db.cpnr self.wcfnr = self.db.wcfnr
#-*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText import time, os from framework.logger import logger from framework import getcwd from email.mime.multipart import MIMEMultipart logger = logger(logger="EmailReport").getlog() class EmailReport(): def send_mail(self, file_new): #定义发送邮件的方法 #发信邮箱 mail_from = "*****@*****.**" #收信邮箱 mail_to = "*****@*****.**" #定义正文 msg = MIMEMultipart('related') f = open(file_new, 'rb') mail_body = f.read() f.close() content = MIMEText(mail_body, _subtype='html', _charset='utf-8') msg.attach(content) #定义标题 msg['subject'] = u"审批拆分包自动化测试报告" #构造附件 att = MIMEText(mail_body, 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="report.html"' msg.attach(att)
import os.path from configparser import ConfigParser from selenium import webdriver from framework.logger import logger import time logger=logger(logger="BrowserEngine").getlog() class BrowserEngine(object): dir=os.path.dirname(os.path.abspath(".")) chrome_driver_path=dir+"/tools/chromedriver.exe" ie_driver_path=dir+"/tools/IEDriverServer.exe" firefox_driver_path=dir+"/tools/geckodriver.exe" def open_browser(self): config=ConfigParser() file_path=os.path.dirname(os.path.abspath("."))+"/config/config.ini" config.read(file_path) browser=config.get("browserType","browsername") logger.info("你选择%s浏览器"%browser) url=config.get("testServer","URL") logger.info("测试的服务链接是%s"%url) if browser=="Firefox": self.driver=webdriver.Firefox(executable_path=self.firefox_driver_path) logger.info("开始火狐浏览器") elif browser=="Chrome": self.driver=webdriver.Chrome(self.chrome_driver_path) logger.info("开始Chrome浏览器") elif browser=="IE": self.driver=webdriver.Ie(self.ie_driver_path) logger.info("开始IE浏览器")
from framework.email_report import EmailReport from framework.logger import logger #from testsuites.ApprBase.登录与注销.test_loginout import Loginout # 指定测试报告文件 report_path = getcwd.get_cwd() + '/test_report/' now = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time())) HtmlFile = report_path + now + "report.html" # 加载所有测试套件中的所有测试用例 suite_path = getcwd.get_cwd() + r"\testsuites" suite = unittest.TestLoader().discover(suite_path) # suite = unittest.TestSuite() # suite.addTest(Loginout('test_login')) # suite.addTest(Loginout('test_logout')) if __name__ == '__main__': with open(HtmlFile, 'wb') as fp: # 打开测试报告文件,用于写入测试报告 runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"政务系统自动化测试报告", description=u"备注:测试报告附件请用chorome打开,否则无法展开详情", verbosity=2) runner.run(suite) # 调用自动发邮件方法 # email_report = EmailReport() # email_report.send_report() logger = logger(logger="TestRunner").remove_logs()
import cx_Oracle from framework import readConfig from framework.logger import logger localReadConfig = readConfig.ReadConfig() logger = logger(logger="configMySql").getlog() class Oracle: global host, pwd, port, tnsname host = localReadConfig.get_oracle("host") #username = localReadConfig.get_oracle("username") #审批个性化,需要连接gd_base和gd_dbwizard,所以不固定用户名,便于切换数据库 pwd = localReadConfig.get_oracle("password") port = localReadConfig.get_oracle("port") tnsname = localReadConfig.get_oracle("tnsname") #实例名 def __init__(self): # self.log = Log.get_log() # self.logger = self.log.get_logger() self.db = None self.cursor = None def connectDB(self, username): """ connect to database :return: """ try: # connect to DB self.db = cx_Oracle.connect(username, pwd, host + ':' + port + '/' + tnsname)
)) t2 = threading.Thread(target=self.run, args=( self.discover2, 1, )) t3 = threading.Thread(target=self.run, args=( self.discover3, 2, )) t4 = threading.Thread(target=self.run, args=( self.discover4, 3, )) t1.start() t2.start() t3.start() t4.start() t1.join() t2.join() t3.join() t4.join() self.fp.close() if __name__ == '__main__': run = runner() run.muti_run() # email_report = EmailReport() # email_report.send_report() logger = logger( logger="MutithreadRunner").remove_logs() #定期清理7天前过期日志截图及报告功能
import time # import win32api # import win32gui # import win32con from selenium.common.exceptions import NoSuchElementException from selenium.webdriver import ActionChains from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import WebDriverWait from framework import getcwd from framework.browser_engine import BrowserEngine from framework.logger import logger # create a logger instance logger = logger(logger="BasePage").getlog() class BasePage(object): """ 定义一个页面基类,让所有页面都继承这个类,封装一些常用的页面操作方法到这个类 """ def __init__(self, driver): self.driver = driver # quit browser and end testing def quit_browser(self): self.driver.quit()