# @FileName :send_Email.py # @Sofaware :PyCharm import os import datetime import win32com.client as win32 from config import readConfig import getPathInfo read_conf = readConfig.ReadConfig() subject = read_conf.get_email('subject') #从配置文件中读取邮件主题 app = read_conf.get_email('app') #从配置文件中获取邮件类型 addresses = read_conf.get_email('addresses') copy = read_conf.get_email('copy') today = datetime.datetime.now().strftime('%Y%m%d') mail_path = os.path.join(getPathInfo.get_path(), 'Reports', today, 'Report_' + today + '.html') class send_email(): def Outlook(self): outlook = win32.Dispatch("%s.Application" % app) # outlook = win32.Dispatch("Foxmail.Application") mail = outlook.CreateItem(0) # mail = outlook.CreateItem(win32.constants.olMailItem) mail.To = addresses mail.CC = copy mail.subject = str( datetime.datetime.now())[0:19] + '_' + '%s' % subject mail.Attachments.Add(mail_path, 1, 1, "Myfile") content = """
# @FileName :AllRun.py # @Sofaware :PyCharm import os import controll.HTMLTestRunner as HTMLTestRunner import getPathInfo import unittest import datetime from config import readConfig from Utils.send_Email import send_email import controll.log from apscheduler.schedulers.blocking import BlockingScheduler import pythoncom send_email = send_email() path = getPathInfo.get_path() today = datetime.datetime.now().strftime('%Y%m%d') report_path = os.path.join(path, 'Reports', today) on_off = readConfig.ReadConfig().get_email('on_off') Log = controll.log.logger class AllTest(): def __init__(self): global resultPath resultPath = os.path.join(report_path, 'Report_' + today + '.html') #存储报告路径 self.caseListFile = os.path.join(path, 'Datas', 'testfile.txt') #配置执行那些测试文件的配置文件路径 self.caseFile = os.path.join(path, 'testcases') self.caseList = []
# -*- coding:utf-8 -*- # @Time :2020/6/17 17:15 # @Author :chendaiwu_biubiubiu----- # @FileName :readConfig.py # @Sofaware :PyCharm import os # from config import getPathInfo1 import getPathInfo import configparser path = getPathInfo.get_path() #调用实例恶化,该类返回的路径是:H:\Auto_API_test\config config_path = os.path.join( path, 'config', 'config.ini') #在返回该路径下增加一级,路径为:H:\Auto_API_test\config\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_email(self, name): value = config.get('EMAIL', name) return value def get_mysql(self, name): value = config.get('DATABASE', name) return value
#!/bin/bash/evn python # encoding=utf-8 """ @file:readExcel.py @time:5/24/20|11:37 PM """ import os from xlrd import open_workbook from getPathInfo import get_path path = get_path() class ReadExcel(object): def get_excel(self, xls_name, sheet_name): rows_ = [] excel_path = os.path.join(path, 'testFile', 'caseDOC', xls_name) wb = open_workbook(excel_path) sheet = wb.sheet_by_name(sheet_name) nrows = sheet.nrows for i in range(nrows): if sheet.row_values(i)[0] != u'case_name': rows_.append(sheet.row_values(i)) return rows_ if __name__ == '__main__': print(ReadExcel().get_excel('loginCase.xlsx', 'login')) print(ReadExcel().get_excel('loginCase.xlsx', 'login')[0][1]) print(ReadExcel().get_excel('loginCase.xlsx', 'login')[1][2])
# -*- coding:utf-8 -*- # @Time :2020/6/18 10:24 # @Author :chendaiwu_biubiubiu----- # @FileName :ReadExcel.py # @Sofaware :PyCharm import os import xlrd # from config import getPathInfo1 import getPathInfo path = getPathInfo.get_path() #获取文件当前路径 class ReadExcel(): def read_excel(self, excel_name, sheet_name): #excel_name是用例的excel名称,sheet_name是sheet页名称 dataset = [] excel_path = os.path.join(path, 'Datas', excel_name) #获取excel文件路径 workbook = xlrd.open_workbook(excel_path) #打开excel sheet = workbook.sheet_by_name(sheet_name) #获取sheet名称 for n in range(sheet.nrows): #根据总行数进行循环 if sheet.row_values(n)[0] != u'case_name': #如果sheet的第一个值不等于case_name,就把盖子添加到dataset[]中 dataset.append(sheet.row_values(n)) return dataset if __name__ == '__main__': print(ReadExcel().read_excel('case.xlsx', 'case')) print(ReadExcel().read_excel('case.xlsx', 'case')[0][1]) print(ReadExcel().read_excel('case.xlsx', 'case')[1][2])