def request_by_step(self, case_steps): self.temporary = np.load(fileutils.local_file(temporary_data_path), allow_pickle=True).item() logger.info('本次测试前读取到的变量值为%s' % self.temporary) for case_step in case_steps: rseult = self.request(case_step) if rseult['check_result'] == False: break np.save(fileutils.local_file(temporary_data_path), self.temporary) logger.info('本次测试后写入变量值为%s' % self.temporary) return rseult
def email_image_send(self, report_path, title): report_png = "logs\\report.png" driver = webdriver.Chrome( executable_path=fileutils.local_file('config/chromedriver')) driver.get("file://%s" % report_path) driver.maximize_window() ele_list = driver.find_elements_by_xpath('//*[@type="case"]') for element in ele_list: driver.execute_script( 'arguments[0].setAttribute("class","hiddenRow");', element) #block-打开详情 time.sleep(3) image_path = fileutils.local_file(report_png) driver.save_screenshot(image_path) self.send_email(title, image_path, report_path) os.remove(image_path) # 移除截图 driver.close()
import pytest import time from utils.file_utils import fileutils from path import report_path from utils.SmtpReport import SmtpReport from utils.config_utils import configutils reports_path = fileutils.local_file(report_path) report_ = time.strftime("%Y_%m_%d_%H:%M:%S", time.localtime()) report_html = '%s/%s.html' % (reports_path, report_) email = SmtpReport(configutils.get_inidata('email', 'receiver')) print(report_html) pytest.main(['-s', 'testcases']) #email.email_image_send(report_html,"接口自动化测试报告")
def __init__(self, sheet_name="Sheet1"): self.path = fileutils.local_file(excel_path) self.xlrd = xlrd3.open_workbook(self.path) self.sheet = self.xlrd.sheet_by_name(sheet_name)
import configparser from utils.file_utils import fileutils from path import ini_path cfg = configparser.ConfigParser() ini_path = fileutils.local_file(ini_path) cfg.read(ini_path,encoding="utf-8") '''# 1.获取所用的section节点 print(cfg.sections()) # 2.获取指定节点中的key print(cfg.options('test')) # 3.获取指定section中option的value print(cfg.get('test','host')) #print(cfg.getint('test','host')) # 将获取到值转换为int型,只能转换整数 #print(cfg.getfloat('test','host')) #将获取到值转换为浮点型,只能转换数字 #print(cfg.getboolean('test','host')) #将获取到值转换为bool型,只能转换Ture和false # 4.获取指点section的所有配置信息 print(cfg.items('test')) ''' # opti = cfg.items('test') # print(opti) # for i in range(0,len(opti)): # key = opti[i][0] # value = opti[i][1] # print('%s====%s'%(key,value)) # opti = [('host', 'http://180.169.51.178:19081/',0), ('username', 'jintang',1), ('password', '123@abAB',2)] # a,b,c,d,e= ['sadhs','shajkd',11,1213,343] # print(a,b,c,d,e) # for key,value,w in opti: # print('%s====%s===%s' % (key, value,w))
def __init__(self, sheet_name="Sheet1"): self.excel_path = fileutils.local_file(excel_path) self.excelutils = ExcelUtils(sheet_name)
def __init__(self): self.logs_path = fileutils.local_file(log_path) self.time_ = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) self.log_name = '%s/%s.log' % (self.logs_path, time)
def __init__(self,config_path = ini_path): self.config = configparser.ConfigParser() self.path = fileutils.local_file(config_path) self.config.read(self.path)
import numpy as np from utils.file_utils import fileutils from path import temporary_data_path # data = {'name':"ly",'age':'23'} # # np.save('../../data/temporary_data.npy', data) # demo1 = np.load('../../data/temporary_data.npy', allow_pickle=True) # print(demo1.item()) # # np.save('../../data/temporary_data.npy', {}) # demo2 = np.load('../../data/temporary_data.npy', allow_pickle=True) # print(demo2.item()) temporary = np.load(fileutils.local_file(temporary_data_path), allow_pickle=True).item() print(temporary)
import xlrd3 from path import * from utils.file_utils import fileutils path = fileutils.local_file(excel_path) excel = xlrd3.open_workbook(path) sheet = excel.sheet_by_name('Sheet1') # sheet.merged_cells 获取合并单元格的坐标 print(sheet.merged_cells) # row_index:行;col_index:列 def get_merged_cell_value(row_index,col_index): cell_value = None for min_x,max_x,min_y,max_y in sheet.merged_cells: if min_x <= row_index and max_x >row_index: if min_y <= col_index and max_y>col_index: cell_value = sheet.cell_value(min_x,min_y) return cell_value else: cell_value = sheet.cell_value(row_index,col_index) return cell_value else: cell_value = sheet.cell_value(row_index, col_index) return cell_value ''' for i in range(0,sheet.nrows): for j in range(0,sheet.ncols): value = get_merged_cell_value(i,j) print(value,end=',') print('\n')''' excel_list_date = []