文章目录
- 一 导入库
- 二 实例脚本 get
- 三 实例脚本 post
- 四 其他
- 五 遇到的报错:
- 1.Keyword 'RequestsLibrary.Post Request' got positional argument after named arguments.
- 2.ValueError: too many values to unpack
- 3."status":400,"msg":"XX不能为空"
- 4.ValueError: Expecting ',' delimiter: line 1 column 541 (char 540)
- 5. {"status":400,"msg":"商品轮播图必须是数组" } ==这个问题总算被同事给解决了☺==
- 6. ValueError: No JSON object could be decoded
- 7.ValueError: Expecting property name enclosed in double quotes: line 1 column 142 (char 141)
- 8 Keyword 'RequestsLibrary.To Json' expected 1 to 2 arguments, got 65.
一 导入库
1.win+r 输入cmd进入命令提示符,输入以下内容执行安装:
pip install requests
pip install robotframework-requests
安装好后pip list查看:
2.RF中导入:RequestsLibrary
*** Settings ***
Library RequestsLibrary
Library Collections
Library Selenium2Library
二 实例脚本 get
2.1 参数在链接中
获取collection列表数据,参数在第一行链接中直接修改${collection_list}中的参数值即可,也可参数化在变量中修改参数:
${
collection_list} set variable list?page=1&limit=10
create session collectionlist ${
url[0]}${
collection_list}
${
get_head} create dictionary Content-Type=application/x-www-form-urlencoded Authori-zation=${
token[0]}
${
collection_list} Get Request collectionlist ${
url[0]}${
collection_list} headers=${
get_head}
#打印结果
log ${
collection_list.text}
log ${
collection_list.json()}
log ----- 开始断言 ------
${
result} run keyword and return status should be equal as strings ok ${
collection_list.json()["msg"]}
Should Be True ${
result}
delete all sessions
断言:msg返回ok即执行通过
执行结果:
遇到问题:
解决方法:
方法1.清空get request的uri即可
方法2.把${collection_list} 放到Get Request中
2.2 参数放params中
获取产品详情,提供产品id放到变量${get_data}中,将变量值赋予patams:
${
fulu_product} set variable /ams/fulu/getGoods
create session checkproduct ${
url[0]}
${
get_head} create dictionary Content-Type=application/x-www-form-urlencoded Authori-zation=${
token[2]}
${
get_data} to json {
"product_id":"10000353"}
${
fululist} Get Request checkproduct ${
fulu_product} headers=${
get_head} params=${
get_data}
#打印结果
log ${
fululist.text}
log ${
fululist.json()}
log ----- 开始断言 ------
${
result