需求:api/car/detail/recommendcar.json 接口返回的车辆数量少于等于20且车辆不能重复
分析:统计接口中返回的列表的长度,再把carid拿出来组成一个新的列表,判断这个列表中的元素是否存在重复
代码如下:
推荐车辆 [Arguments] ${carId} ${data} create dictionary carId=${carId} fromBroker=false ${response} Rest.Get /api/car/detail/recommendcar.json ${data} form ${hosts["wdprepub"]} ${result} set variable ${response["data"]["carList"]} ${result length} get length ${result} #检查推荐的车辆是否少于等于20辆 should be true ${result length}<=20 ${caridlist}= create list : FOR ${item} IN @{response["data"]["carList"]} ${carid} set variable ${item["id"]} append to list ${caridlist} ${carid} #检查返回的车辆是否去重 List Should Not Contain Duplicates ${caridlist} log ${caridlist}