import json# 检查是否为升序 是返回True 否返回False
def isSortAsc(lst):return all(lst[i] <= lst[i + 1] for i in range(len(lst)-1))# 检查是否为降序 是返回True 否返回False
def isSortDesc(lst):return all(lst[i] >= lst[i + 1] for i in range(len(lst)-1))# 脚本断言
def compare(actual, expect):# 增加判断逻辑# actual为当前步骤响应结果封装# expect为期望结果封装# Struct类型为平台定义,详见帮助文档# json字符格式格式预处理,否则转json报错jstr = str(actual)[1:]jstr = jstr[0:len(jstr)-1]jstr = "[" + jstr + "]"jstr = jstr.replace('\\"', '"')# print(jstr)jsonObj = json.loads(jstr)# 遍历json集合数据totalCount = jsonObj[0]['totalCount']if totalCount == 0:return TruedataList = jsonObj[0]['data']code = jsonObj[0]['code']print("code:",code)tempList = []print("length:",len(dataList))if len(dataList) > 0:for GoodsList in dataList:tmpValue = ""try:tmpValue = GoodsList['priceInfo']['price'] except Exception as e:pass# print('异常数据:',GoodsList)tempList.append(tmpValue)print("集合数据:",tempList)# 定义Bool变量ISflag = Trueif code != 200:ISflag = False# 排序检查 ISflag = isSortAsc(tempList)if ISflag ==False:print("排序断言不通过")print(ISflag)return ISflag;
