码迷,mamicode.com
首页 > 其他好文 > 详细

robot framework get、post 接口调用

时间:2020-01-26 17:21:25      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:style   headers   cep   问题   wow   live   none   ike   post   

使用rf调用 get、post接口,可以先定义好 对应的关键字,后面直接使用

 

关键字如下:

一、  set login headers

入参为 cookie,如果没有,传 {}

1     [Arguments]    ${cookies}
2     ${loginheader}    Evaluate    json.loads({"User-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36","Content-Type":"application/json;charset=UTF-8","Connection":"keep-alive","Accept-Encoding":"gzip, deflate","Accept":"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest","Content-Length":"72","cache-control":"no-cache","Accept-Language": "zh-CN,zh;q=0.9"})    json
3     ${header}    Create Dictionary    Cookie=${cookies}
4     log    ${header}
5     ${header}    Evaluate    dict(${header},**${loginheader})
6     [Return]    ${header}

技术图片

 

二、http-post

 

1     [Arguments]    ${host}    ${path}    ${postdata}    ${headers}
2     Create Session    url    ${host}    ${headers}
3     ${data}    Evaluate    json.loads(${postdata})    json
4     ${res}    Post Request    url    ${path}    ${postdata}
5     Delete All Sessions
6     [Return]    ${res.content}

技术图片

 

 

三、http-get

 

1     [Arguments]    ${host}    ${headers}    ${path}    ${getdata}=None
2     Create Session    url    ${host}
3     ${res}    Get Request    url    ${headers}    ${path}    ${getdata}
4     Delete All Sessions
5     [Return]    ${res.content}

技术图片

 

 

 

四、调用

 技术图片

 

 

 结果如下:

技术图片

技术图片

 

 

问题:

1.如果 结果中需要鉴权的 header不叫 cookie,可这样使用

不用 第一个关键字,直接编写 header

1     ${newCookie}    Set Variable    xxxxxx
2     ${header}    Create Dictionary    Content-Type=application/json    newCookileNeam=${newCookie}
3     ${res}    http-post    http://xxxxxx.com    /xxxx {postdata}    ${header}

 

robot framework get、post 接口调用

标签:style   headers   cep   问题   wow   live   none   ike   post   

原文地址:https://www.cnblogs.com/whycai/p/12234312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!