A、需要安装的库
1.RequestsLibrary,安装命令:pip2 install requests 2.HttpLibrary,安装命令:pip2 install robotframework-httplibrary 3.HttpLibrary.HTTP,这个库是在HttpLibrary中,HTTP是HttpLibrary的一个class 4.json,安装命令:pip2 install jsonpatch 5.Collections,这个库是python自带的,直接引入即可 |
B、RF需导入的库
1. HttpLibrary 2. HttpLibrary.HTTP-----------------------------------Get Json Value,parse json3. json---------------------------------------------------loads4. RequestsLibrary------------------------------------------to json5.Collections--------------------------------------------------get from dictionary |
C、取json中的值
${json_data} set variable {"id": "18701236666","code": 200,"msg": "ok","data": {"tag_list": [{"game_id": "28","game_name": "天天酷跑"},{"game_id": "29","game_name": "斗地主"}]}} ${text01} Get Json Value ${json_data} /id${text02} Get Json Value ${json_data} /data${text03} Get Json Value ${json_data} /data/tag_list
|
D、将json格式中[]转化成python中dict格式
#将json[]中的值转化成python dict格式 ${data_to_json} to json ${text03}log ${data_to_json} ${data_parse_json} parse json ${text03}log ${data_parse_json} ${data_loads_json} loads ${text03}log ${data_loads_json}
|
E、取值
#取值 ${value} get from dictionary ${data_parse_json[0]} game_namelog ${value} ${value} get from dictionary ${data_parse_json[0]} game_idlog ${value}
|