def __init__(self): global resultPath resultPath = os.path.join(report_path, "report.html") # result\report.html print(os.path.join(getpathInfo.get_path(), "result", "report.html")) self.caseListFile = os.path.join(path, "caselist.txt") # 配置执行哪些测试文件的配置文件路径 self.caseFile = os.path.join(path, "testCase") # 真正的测试断言文件路径 self.caseList = []
def get_xls(self, xls_name=None, sheet_name=None, start=None, end=None, repeat=None): # xls_name填寫用例的Excel名稱 sheet_name該Excel的sheet名稱 path = getpathInfo.get_path() cls = [] # 獲取用例文件路徑 casePath = os.path.join(path, "testFile", 'case') for root, dirs, files in os.walk(casePath): if xls_name is None: xlsfiles = [_ for _ in files if _.endswith('.xlsx')] else: xlsfiles = [xls_name] for xlsfile in xlsfiles: file = open_workbook(os.path.join(root, xlsfile)) # 打開用例Excel if sheet_name in file.sheet_names(): # 檢查分頁是否存在excel sheet = file.sheet_by_name(sheet_name) # 獲得打開Excel的sheet # 獲取這個sheet內容行數 nrows = sheet.nrows try: if (start != None and end != None and repeat != None): for j in range(repeat): for i in range(start, end): if sheet.row_values( i )[0] != u'case_name': # 如果這個Excel的這個sheet的第i行的第一列不等於case_name那麽我們把這行的數據添加到cls[] cls.append(sheet.row_values(i)) elif (start != None and end != None): for i in range(start, end): if sheet.row_values(i)[0] != u'case_name': cls.append(sheet.row_values(i)) elif (repeat != None): for j in range(repeat): for i in range(1, nrows): cls.append(sheet.row_values(i)) else: for i in range(1, nrows): cls.append(sheet.row_values(i)) except IndexError: print('list index out of range') else: wb = openpyxl.load_workbook(os.path.join(root, xlsfile)) wb.create_sheet(sheet_name) wb.save(os.path.join(root, xlsfile)) return cls
def __init__(self): localReadConfig = ConfigReader() path = getpathInfo.get_path() self.log = Log.get_log() self.logger = self.log.get_logger() self.resultPath = self.log.get_report_path() self.on_off = localReadConfig.get_email("on_off") self.caseListFile = os.path.join(path, "caselist.txt") self.caseFile = os.path.join(path, "testCase") self.caseList = [] self.logger.info('resultPath' + self.resultPath) # 將resultPath的值輸入到日誌,方便定位查看問題 self.logger.info('caseListFile' + self.caseListFile) # 同理 self.logger.info('caseList' + str(self.caseList)) # 同理 self.email = MyEmail.get_email()
def __init__(self): self.path = getpathInfo.get_path() localReadConfig = ConfigReader() self.host = localReadConfig.get_email("mail_host") self.user = localReadConfig.get_email("mail_user") self.password = localReadConfig.get_email("mail_pass") self.port = localReadConfig.get_email("mail_port") self.sender = localReadConfig.get_email("sender") self.title = localReadConfig.get_email("subject") self.content = localReadConfig.get_email("content") # get receiver list self.value = localReadConfig.get_email("receiver") self.receiver = [] for n in str(self.value).split("/"): self.receiver.append(n) # defined email subject date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") self.subject = "接口測試報告" + " " + date self.log = MyLog.get_log() self.logger = self.log.get_logger() self.msg = MIMEMultipart('related')
# -*- coding: utf-8 -*- #_author:"hancel" #date:2020/8/5 from selenium import webdriver from selenium.webdriver.chrome.options import Options from configparser import ConfigParser import os import getpathInfo from framework.logger import Logger logger = Logger(logger="BrowserDriver").get_logger() pro_dir = getpathInfo.get_path() class BrowserDriver(object): driver_path = pro_dir + '/tools/' chrome_driver_path = driver_path + "chromedriver.exe" ie_driver_path = driver_path + "IEDriverServer.exe" firefox_driver_path = "geckodriver.exe" def __init__(self, driver): self.driver = driver def open_browser(self, driver): config = ConfigParser() file_path = os.path.join(pro_dir + '/config/config.ini') config.read(file_path)
import os import Common.HTMLTestRunner as HTMLTestRunner import getpathInfo import unittest import readConfig from Common.configEmail import send_email import pythoncom import Common.Log from apscheduler.schedulers.blocking import BlockingScheduler send_email = send_email() path = getpathInfo.get_path() report_path = os.path.join(path, 'result') on_off = readConfig.ReadConfig().get_email('on_off') log = Common.Log.logger class AllTest: def __init__(self): global resultPath resultPath = os.path.join(report_path, 'report.html') self.caseListFile = os.path.join(path, 'caselist.txt') self.caseFile = os.path.join(path, 'testCase') self.caseList = [] log.info('resultPath' + resultPath) log.info('caseListFile' + self.caseListFile) log.info('caseList' + str(self.caseList)) def set_case_list(self): fb = open(self.caseListFile) for value in fb.readlines():
# 读取配置文件的方法,并返回文件中内容 import os import configparser import getpathInfo path = getpathInfo.get_path() # 获取项目绝对路径 config_path = os.path.join(path, 'config.ini') # 在项目绝对路径后加一级 config = configparser.ConfigParser() # 读取配置文件的方法 config.read(config_path, encoding='utf-8') class ReadConfig: def get_email(self, name): value = config.get("EMAIL", name) return value def get_http(self, name): value = config.get("HTTP", name) return value def get_db(self, name): value = config.get("DATABASE", name) return value if __name__ == "__main__": print('HTTP中的baseurl值为:', ReadConfig().get_http("baseurl")) print('EMAIL中的开关on_off值为:', ReadConfig().get_email("on_off"))
import os import codecs import configparser import getpathInfo proDir = getpathInfo.get_path() configPath = os.path.join(proDir, "config.ini") class ConfigReader: def __init__(self): fd = open(configPath) data = fd.read() # remove BOM if data[:3] == codecs.BOM_UTF8: data = data[3:] file = codecs.open(configPath, "w") file.write(data) file.close() fd.close() self.cf = configparser.ConfigParser() self.cf.read(configPath) def get_email(self, name): value = self.cf.get("EMAIL", name) return value def get_http(self, name): value = self.cf.get("HTTP", name) return value
import unittest from common import HTMLTestRunner import os import readConfig import getpathInfo from common.configEmail import SendEmail import common.log send_mail = SendEmail( username=readConfig.ReadConfig().get_email("sender"), # 发件人 passwd=readConfig.ReadConfig().get_email("password"), # 密码 recv=['*****@*****.**'], # 收件人,多个收件人用逗号隔开,如:['*****@*****.**', '*****@*****.**'] title='接口自动化测试', # 标题 content='三病系统接口测试', # 正文 file=os.path.join(getpathInfo.get_path(), "result", "report.html"), # 附件 report.html ssl=True, ) path = getpathInfo.get_path() report_path = os.path.join(path, 'result') on_off = readConfig.ReadConfig().get_email('on_off') logger = common.log.logger class AllTest: def __init__(self): global resultPath resultPath = os.path.join(report_path, "report.html") # result\report.html print(os.path.join(getpathInfo.get_path(), "result", "report.html")) self.caseListFile = os.path.join(path,
import json import os # import urllib import urllib.parse from common.configHttp import RunMain from getpathInfo import get_path from getpathInfo import get_path import readConfig path = get_path() report_path = os.path.join(path, 'result') on_off = readConfig.ReadConfig().get_email('on_off') resultPath = os.path.join(report_path, "report.html") # result/report.html caseListFile = os.path.join(path, "caselist.txt") # 配置执行哪些测试文件的配置文件路径 print(caseListFile, "caseListFile") caseFile = os.path.join(path, "testCase") # 真正的测试断言文件路径 caseList = [] print(os.path) print(caseFile, "caseFile") print(caseList, "caseList") def checkResult(): # 断言 """ check test result :return: """
def __init__(self, driver): self.driver = driver self.pro_path = getpathInfo.get_path()
def __init__(self): proDir = getpathInfo.get_path() urlFile = os.path.join(proDir, "device", "InterfaceUrl.json") with open(urlFile) as f: self.data = json.load(f)
import os import configparser import getpathInfo path = getpathInfo.get_path() #调用实例化方法 config_path = os.path.join(path, "config.ini") config = configparser.ConfigParser() #调用外部的读取配置文件方法 config.read(config_path, encoding="utf-8") class ReadConfig(): def get_http(self, name): value = config.get('HTTP', name) return value def get_https(self, name): value = config.get('HTTPS_login', name) return value def get_https_pay(self, name): value = config.get('HTTPS_pay', name) return value def get_email(self, name): value = config.get('EMAIL', name) return value def get_mysql(self, name): # value = config.get('DATABASE', name) return value