十九、RF接口测试汇总(一)

搭建项目:转自  http://chuansong.me/n/1858477

 

 

A、请求方式为get请求

  方式一:导入RequestsLibrary库,get request    [ alias | uri | headers=None | json=None | params=None | allow_redirects=None | timeout=None ]

create session             api                  http://localhost:8000
${resp}=                    get request     api                                users/1
log                               ${resp.content}

 

 

 

  方式二:导入requests库, requests.get    Arguments:[ url | params=None | **kwargs ]


${resp1}=               requests.get                   http://localhost:8000/users/1
log                           ${resp1.content}

 

 

 

  第三:如果接口只有登录后才可发送请求,在创建session的时候加上用户名和密码即可,以列表的形式传入即可

create session    Arguments:

[ alias | url | headers={} | cookies=None | auth=None | timeout=None | proxies=None | verify=False | debug=0 | max_retries=3 | backoff_factor=0.1 | disable_warnings=0 ]

${auth}                                                                          create list                                       ok                                     python
create session                                                                  api                                                http://localhost:8000                                                                      ${auth}
${resp}=                                                                       get request                                     api                                     401
log                                                                                 ${resp.content}
should be equal as strings                                                 ${resp.status_code}                           200

 

 

 

 

B、请求方式为post请求

  方式一:导入RequestsLibrary库   Post request             Arguments:[ alias | uri | data=None | params=None | headers=None | files=None | allow_redirects=None | timeout=None ]

${cc}                                                          create dictionary                                    Content-Type=application/x-www-form-urlencoded


create session                                            api                                                          http://netsale.api/                                                         ${cc}

${url}                                                         Set Variable                                            /Api/GetCinema                                                              #自定义接口地址

#md5加密
${pVerifyInfo}                                           Md5 32 Lowercase                                  ${pAppCode}${token}


${postdata}                                             Create Dictionary                                     pAppCode=${pAppCode}                                              pVerifyInfo=${pVerifyInfo}

#发送请求
${resp}=                                                 Post request                                             api                                                                                 /Api/GetCinema                                data=${postdata}
log                                                           ${resp.content}
should be equal as strings                      ${resp.status_code}                                200

 

 

  方式二:导入requests库, request.Post 


${url}                                                         Set Variable                                            http://netsale.api/Api/GetCinema                                                              #自定义接口地址

#md5加密
${pVerifyInfo}                                           Md5 32 Lowercase                                  ${pAppCode}${token}


${postdata}                                             Create Dictionary                                     pAppCode=${pAppCode}                                              pVerifyInfo=${pVerifyInfo}

#发送请求
${resp}=                                                 request.Post                                             ${url}                                                                             ${postdata}
log                                                           ${resp.content}
should be equal as strings                      ${resp.status_code}                                200

 

 

C、针对返回字符串操作

#json格式化
${respdata}                                             to json                                     ${resp.content}
log                                                          ${respdata}
${a}                                                       get dictionary keys                     ${respdata}
log                                                          ${a[0]}
${b}                                                       get dictionary values                   ${respdata}
log ${b[0]}
${dict}                                                    get dictionary items                    ${respdata}
log                                                          ${dict}
${value}                                                 get from dictionary                     ${respdata}                     1
log                                                          ${value}

 

 

posted @ 2018-08-17 18:04  旅行没有终点  阅读(2919)  评论(0编辑  收藏  举报