Robot Framework--完整的接口测试用例
*** Settings *** Library Collections Library json Library requests Library RequestsLibrary Library HttpLibrary.HTTP *** Variables *** &{hosts} dfc=http://dfc.xxxxx.com crm=http://crm.xxxxx.com *** Keywords *** 新建客户 登录xxxxx [Arguments] ${apiurl} ${jpushid} ${loginName} ${password} ${top} Create Dictionary Content-Type=application/x-www-form-urlencoded Create Session api ${apiurl} ${top} ${data} Create Dictionary jpushid=${jpushid} loginName=${loginName} password=${password} ${req} Post Request api /rest/account/login data=${data} log ${req.status_code} ${reqj} To Json ${req.content} log ${reqj} ${reqjdata} Get From Dictionary ${reqj} data ${TT} Get From Dictionary ${reqjdata} token ${store} Get From Dictionary ${reqjdata} store ${citycode} Get From Dictionary ${reqjdata} cityCode set global variable ${TT} Set Suite Variable ${store} Set Suite Variable ${citycode} ${form} Create Dictionary Content-Type=application/x-www-form-urlencoded Set Global Variable ${form} ${json} Create Dictionary Content-Type=application/json TT=${TT} Set Global Variable ${json} #Set Suite Variable $ MoGet [Arguments] ${apiurl} ${type}==json ${params}==${EMPTY} #设置代理,用于调试 ${proxy} set variable http://127.0.0.0:8888/ #根据tag来获取host : FOR ${tag} IN @{TEST TAGS} \ ${host} Evaluate ${hosts}.get($tag,"") \ Run Keyword If "${host}"!="" Exit For Loop log ${host} #根据提交数据格式,设置Content-Type ${top} Run Keyword If "${type}"=="form" Create Dictionary Content-Type=application/x-www-form-urlencoded TT=${TT} ... ELSE Create Dictionary Content-Type=application/json TT=${TT} Create Session api ${host} ${top} ${resget} Get Request api ${apiurl} params=${params} Should Be Equal As Strings ${resget.status_code} 200 log ${resget.status_code} ${resj} To Json ${resget.content} log ${resj} MoPost [Arguments] ${apiurl} ${type}==json ${params}==${EMPTY} #设置代理,抓包 ${proxy} Set Variable http://127.0.0.1:8888/ #根据tag来获取host : FOR ${tag} IN @{TEST TAGS} \ ${host} Evaluate ${hosts}.get($tag,"") \ Run Keyword If "${host}"!="" Exit For Loop log ${host} #根据提交数据格式,设置Content-Type ${top} Run Keyword If "${type}"=="json" Create Dictionary Content-Type=application/json TT=${TT} ... ELSE IF "${type}"=="form" Create Dictionary Content-Type=application/x-www-form-urlencoded TT=${TT} Create Session api ${host} ${top} ${respost} Post Request api ${apiurl} params=${params} Should Be Equal As Strings ${respost.status_code} 200 ${resj} To Json ${respost.content} log ${resj}
原文地址:https://www.cnblogs.com/chengchengla1990/p/7044802.html