def __init__(self): self.logger = MyLog() self.readconfig = ReadConfig() self.send_mail = SendEmail() # self.env = ResetEnv() self.is_send = self.readconfig.get_email("is_send") # 测试报告基本信息 self.testers = "Roman" self.title = "元丁接口测试报告" self.description = "正式/测试环境:Develop,IP地址:%s" % self.readconfig.get_base_url( ) # print(self.description) # 导入TestCase目录下的全部测试用例 self.discover = unittest.defaultTestLoader.discover(test_case_path, pattern='test*.py') # 导入指定测试用例列表文件 self.case_list_file = case_list_path self.case_list_list = [] # print(self.case_list_list) # 重置测试环境 self.is_env = True
def __init__(self): self.method = RunMethod() self.data = GetData() self.com_result = CompareResult() self.config = ReadConfig() self.depend = DependData() self.sendemail = SendEmail()
def __init__(self, file_name=None): # print("打开excel") self.open_excel = OperationExcel() self.set_excel = ReadConfig() if file_name: self.open_json = OperationJson(file_name) else: self.open_json = OperationJson()
def setUp(self): self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_case' self.row = list(range(2, 20)) self.log.info(message="----------测试开始----------", name="test01_OrcLogin.py")
def setUp(self): # print('执行开始') self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_fenxi' self.row = list(range(2, 30)) self.log.info(message="----------测试开始----------", name="test_piyue.py")
def openbrowser(self, driver): browser = ReadConfig().get_string('browser_type', 'browserName') logger.info("选择的浏览器为: %s 浏览器" % browser) if browser == 'Firefox': driver = webdriver.Firefox() logger.info("启动火狐浏览器") elif browser == 'Chrome': driver = webdriver.Chrome(self.chrome_driver_path) logger.info("启动谷歌浏览器") elif browser == 'IE': driver = webdriver.Ie(self.ie_driver_path) logger.info("启动IE浏览器") url = ReadConfig().get_string('url', 'login_url') driver.get(url) logger.info("打开URL: %s" % url) driver.maximize_window() logger.info("全屏当前窗口") driver.implicitly_wait(5) logger.info("设置5秒隐式等待时间") return driver
import yagmail import time from config.readConfig import ReadConfig emall = ReadConfig() on_off = emall.get_emall('on_off') # 开关 subject = emall.get_emall('subject') # 标题 smtp = emall.get_emall('smtp') # 邮箱服务器 emall_user = emall.get_emall('emall_user') # 邮箱账号 emall_pass = emall.get_emall('emall_pass') # 邮箱密码 emall_to = emall.get_emall('emall_to') # 接收者邮箱 class operate_emall(): def send_emall(self, file_name=None): em = yagmail.SMTP(user=emall_user, password=emall_pass, host=smtp) current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) content = '接口自动化报告!!!' em.send(to=emall_to, subject=subject + current_time, contents=content, attachments=file_name) if __name__ == '__main__': operate_emall().send_emall()
#!/usr/bin/python3 # coding=utf-8 import requests import json from common.myLog import MyLog from common.operationJson import OperationJson from config.readConfig import ReadConfig log = MyLog() config = ReadConfig() class ResetEnv: def __init__(self): self.op_json = OperationJson() self.omp = DeleteOmpName() self.headers = self.op_json.key_get_data("orc_token_header") def get_db_list(self): url = config.get_base_url() + "/tenant" res_json = requests.get(url=url, headers=self.headers).json() return json.dumps(res_json, ensure_ascii=False, sort_keys=False, indent=2) # def delete_db(self): # """清理所有DB""" # all_db_dict = json.loads(self.get_db_list()) # if all_db_dict["status"]: # all_db_list = [] # db_number = len(all_db_dict["results"]) # for i in range(db_number): # db_id = all_db_dict["results"][i]["tenant_name"]
#该文件是构造发送邮件的方法,用到python标准库smtplib和email #可以获取最新的测试报告,把最新的测试报告以文本和附件的形式发送 import smtplib import os from common.myLog import MyLog from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from config.readConfig import ReadConfig # 路径 path_dir = str( os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) reportpath = path_dir + '/report' local_readConfig = ReadConfig() class SendEmail: def __init__(self): global host, user, password, sender, title host = local_readConfig.get_email('mail_host') # 邮箱服务器 user = local_readConfig.get_email('mail_user') # 发件人用户名 password = local_readConfig.get_email('mail_pass') # 发件人邮箱授权码,非登录密码 sender = local_readConfig.get_email('sender') # 发件人邮箱 title = local_readConfig.get_email('title') # 邮件标题 self.logger = MyLog() self.receive_user = local_readConfig.get_email('receive_user') # 收件人邮箱 self.receive_user_list = [] for i in str(self.receive_user).split('/'): self.receive_user_list.append(i)
def __init__(self): self.get_dep_data = GetDependData() self.data = GetData() self.config = ReadConfig() self.run_method = RunMethod()
#coding=utf-8 ''' Created on 2017/9/29 @author: chengww3 Project:执行接口自动化测试项目 ''' import os from common.createSuite import CreateSuite from common.createReport import CreatReport from common.sendMail import SendMail from config.readConfig import ReadConfig def getRootPath(): #获取根目录路径 rootpath = os.path.dirname(os.path.realpath(__file__)) return rootpath if __name__ == '__main__': rootpath = getRootPath() testsuite = CreateSuite().creatSuite(rootpath) # 获取测试套件 # 搜索测试用例,执行测试,生成测试报告 CreatReport().createReport(rootpath,u'接口自动化测试报告', u'test', testsuite) # 获取email的配置信息 sender, receiver, subject, username, password = ReadConfig().getEmailConfig() SendMail().sendMail(rootpath,sender, receiver, subject, username, password)
# -*- coding: utf-8 -*- # @Time : 2018/9/5/005 16:20 # @Author : Administor # @File : page.py # @Software: PyCharm from selenium.webdriver.common.by import By from config.readConfig import ReadConfig loc = (By.XPATH, ReadConfig().get_string('xpath', 'username')) loc1 = (By.XPATH, ReadConfig().get_string('xpath', 'passwd')) user_name = ReadConfig().get_string('login_state', 'user_name') passwd = ReadConfig().get_string('login_state', 'passwd') login_button = (By.XPATH, ReadConfig().get_string('xpath', 'login')) login = ReadConfig().get_string('url', 'login') h5_url = ReadConfig().get_string('url', 'h5_url') pc_url = ReadConfig().get_string('url', 'pc_url') app_url = ReadConfig().get_string('url', 'app_url') banner_management = (By.XPATH, ReadConfig().get_string('xpath', 'banner_management')) banner_channel = (By.XPATH, ReadConfig().get_string('xpath', 'banner_channel')) h5_page = (By.XPATH, ReadConfig().get_string('xpath', 'h5_page')) pc_page = (By.XPATH, ReadConfig().get_string('xpath', 'pc_page')) app_page = (By.XPATH, ReadConfig().get_string('xpath', 'app_page')) banner_limit = (By.XPATH, ReadConfig().get_string('xpath', 'banner_limit')) query_button = (By.XPATH, ReadConfig().get_string('xpath', 'query_button')) reset_search = (By.XPATH, ReadConfig().get_string('xpath', 'reset_search')) product_FAQ = (By.XPATH, ReadConfig().get_string('xpath', 'product_FAQ')) product_categories = (By.XPATH, ReadConfig().get_string('xpath', 'product_categories'))
def homePage(selenium): homePage = HomePage(selenium, root_uri=ReadConfig().get_http('url')) homePage.get('/') time.sleep(1) return homePage
# coning = utf-8 __author__ = 'Aimee' from config.readConfig import ReadConfig import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import time from config.project_path import report_path, data_path, log_path from common.loger import Log log = Log() now_time = time.strftime('%Y-%m-%d %H:%M:%S') #获取配置信息 info = ReadConfig() email_host = info.get_email('mail_host') send_user = info.get_email('mail_send') password = info.get_email('mail_sender_password') sub = info.get_email('subject') user = "******" + "<" + send_user + ">" receivers = info.get_email('receiver').split(';') filepath = [report_path, data_path, log_path] class sendEmail(): def send_mail(self, receivers, filepath): message = MIMEMultipart() message['Subject'] = sub message['From'] = user message['To'] = ','.join(receivers) #邮件正文
def __get_datalist(fileName): readconfig = ReadConfig(os.path.join(dirpath, "interface", fileName)) datalist = [(readconfig.get('DATA', 'Data' + str(i)), readconfig.get('ASSERT', 'assert' + str(i)), readconfig.get('HTTP', 'url'), readconfig.get('HTTP', 'header'), readconfig.get('HTTP', 'method')) for i in range(1, (1 + int(readconfig.get('HTTP', 'dataNum'))))] return datalist
import os import common.log from config import getPathInfo from common.configEmall import operate_emall from config.readConfig import ReadConfig from common.HTMLTestRunner import HTMLTestRunner from unite.testSuite import testSuite log = common.log.logger path = getPathInfo.get_path() resultPath = os.path.join(path, 'result', 'report.html') send_emall = operate_emall() on_off = ReadConfig().get_emall('on_off') def run(): try: report = open(resultPath, 'wb') suite = testSuite().set_case_suite() if suite is not None: runny = HTMLTestRunner(stream=report, title='接口自动化报告', description='接口自动化报告描述', verbosity=2) runny.run(suite) else: print('Have no case to test.') except Exception as e: print('e:', str(e))