1 *** Settings *** 2 Library Collections 3 Library json 4 Library requests 5 Library RequestsLibrary 6 Library HttpLibrary.HTTP 7 8 *** Variables *** 9 &{hosts} dfc=http://dfc.xxxxx.com crm=http://crm.xxxxx.com 10 11 *** Keywords *** 12 新建客户 13 14 登录xxxxx 15 [Arguments] ${apiurl} ${jpushid} ${loginName} ${password} 16 ${top} Create Dictionary Content-Type=application/x-www-form-urlencoded 17 Create Session api ${apiurl} ${top} 18 ${data} Create Dictionary jpushid=${jpushid} loginName=${loginName} password=${password} 19 ${req} Post Request api /rest/account/login data=${data} 20 log ${req.status_code} 21 ${reqj} To Json ${req.content} 22 log ${reqj} 23 ${reqjdata} Get From Dictionary ${reqj} data 24 ${TT} Get From Dictionary ${reqjdata} token 25 ${store} Get From Dictionary ${reqjdata} store 26 ${citycode} Get From Dictionary ${reqjdata} cityCode 27 set global variable ${TT} 28 Set Suite Variable ${store} 29 Set Suite Variable ${citycode} 30 ${form} Create Dictionary Content-Type=application/x-www-form-urlencoded 31 Set Global Variable ${form} 32 ${json} Create Dictionary Content-Type=application/json TT=${TT} 33 Set Global Variable ${json} 34 #Set Suite Variable $ 35 36 MoGet 37 [Arguments] ${apiurl} ${type}==json ${params}==${EMPTY} 38 #设置代理,用于调试 39 ${proxy} set variable http://127.0.0.0:8888/ 40 #根据tag来获取host 41 : FOR ${tag} IN @{TEST TAGS} 42 ${host} Evaluate ${hosts}.get($tag,"") 43 Run Keyword If "${host}"!="" Exit For Loop 44 log ${host} 45 #根据提交数据格式,设置Content-Type 46 ${top} Run Keyword If "${type}"=="form" Create Dictionary Content-Type=application/x-www-form-urlencoded TT=${TT} 47 ... ELSE Create Dictionary Content-Type=application/json TT=${TT} 48 Create Session api ${host} ${top} 49 ${resget} Get Request api ${apiurl} params=${params} 50 Should Be Equal As Strings ${resget.status_code} 200 51 log ${resget.status_code} 52 ${resj} To Json ${resget.content} 53 log ${resj} 54 55 MoPost 56 [Arguments] ${apiurl} ${type}==json ${params}==${EMPTY} 57 #设置代理,抓包 58 ${proxy} Set Variable http://127.0.0.1:8888/ 59 #根据tag来获取host 60 : FOR ${tag} IN @{TEST TAGS} 61 ${host} Evaluate ${hosts}.get($tag,"") 62 Run Keyword If "${host}"!="" Exit For Loop 63 log ${host} 64 #根据提交数据格式,设置Content-Type 65 ${top} Run Keyword If "${type}"=="json" Create Dictionary Content-Type=application/json TT=${TT} 66 ... ELSE IF "${type}"=="form" Create Dictionary Content-Type=application/x-www-form-urlencoded TT=${TT} 67 Create Session api ${host} ${top} 68 ${respost} Post Request api ${apiurl} params=${params} 69 Should Be Equal As Strings ${respost.status_code} 200 70 ${resj} To Json ${respost.content} 71 log ${resj}