1、通过api接口进行登录,并获取打印返回值,脚本如下:
1 | Create Session | api | http://******:8070 | |||
2 | ${headers} | Create Dictionary | Content-Type=application/json |
User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 |
||
3 | ${data} | Create Dictionary | username=zhangsan | password=123456 | ||
4 | ${body} | Post Request | api | /api/gv-crcs/userAuth/login | headers=${headers} | data=${data} |
5 | log | ${body.json()["data"]} | ||||
6 | log | ${body.json()["data"]["accessToken"]} |
网页返回json格式结果:
2、json格式的响应结果的提取可以用图上方的2种方式,若是json有多层级,则继续用Get From Dictionary提取逐层级的内容:如body参数是data下一级;
1 | ${body} | to json | ${body.content} | |
2 | ${body} | Get From Dictionary | ${body} | data |
3 | ${body} | Get From Dictionary | ${body} | accessToken |
4 | log | ${body} |
如下json格式: {"code":200,"message":"操作成功","data":{"accessToken":"eyJhbGciOiJIUzUxM.........."}
-------------或者如下脚本----------
可参考 https://www.cnblogs.com/weizhideweilai/p/10947438.html