#生成指定长度的字符串 def generate_random_str(randomlength): str = 'zxcvbnmasdfghjklqwertyuiop' str_list = [random.choice(str) for i in range(randomlength)] random_str=''.join(str_list) return random_str
def get_distanceTime(day): ''' Args: day: 距离当前时间几天 Returns:距离当前时间几天前时间 ''' today_ele = datetime.datetime.now().date() return today_ele - datetime.timedelta(days=day)
#传入文件名,sheet名,用例执行的开始行,结束行,请求参数的列数,响应参数的列数(都是对应的excel行数和列数) #注意:从excel读出来的数据都是json格式类型,需要json.load转换为字典 def get_excelData(filename,sheetName,starcell,endcell,requestRow,responseRow): ''' :param filename: 文件名 :param sheetName: sheet名 :param starcell: 开始行 :param endcell: 结束行 :param requestRow: 请求参数列 :param responseRow: 返回参数列 :return: ''' dataList = [] file_path =os.path.dirname(os.path.dirname(__file__))+f'/data/apiData/{filename}' workbook = xlrd.open_workbook(file_path,formatting_info=True) workSheet = workbook.sheet_by_name(sheetName) for cell in range(int(starcell)-1,int(endcell)): requestData = workSheet.cell(cell,int(requestRow)-1).value responseData = workSheet.cell(cell,int(responseRow)-1).value dataList.append((json.loads(requestData),json.loads(responseData))) return dataList
#随机生成11位手机号 def phoneNORandomGenerator(): prelist=["130","131","132","133","134","135","136","137","138","139","147","150","151","152","153","155","156","157","158","159","186","187","188"] return random.choice(prelist)+"".join(random.choice("0123456789") for i in range(8))