接口自动化测试首先需要安装RequestsLibrary库
pip install robotframework-requests
下面直接分享几个完整的case脚本,供大家参考哈
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
官网
${head} Create Dictionary User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Create Session api https://xxxxx ${head} verify=True
${a} Set Variable data[username]=xxxx
${b} Set Variable data[password]=xxxx
${c} Set Variable data[remember]=1
${addr} Post Request api /xxx/login params=${a}&${b}&${c}
log ${addr.content}
${responsedata} To Json ${addr.content}
${wq} evaluate json.dumps(${responsedata},ensure_ascii=False) modules=json
log ${wq}
后台登录
${head} Create Dictionary Referer=http://xxxxx/authorize?appkey=100002&returnurl=http://xxxxx
Create Session api http://xxxxx ${head}
${a} Set Variable userName=xxxx
${b} Set Variable userPassword=111111
${c} Set Variable declineReason=
${addr} Post Request api /xxx/login params=${a}&${b}&${c}
log ${addr.content}
${responsedata} To Json ${addr.content}
${wq} evaluate json.dumps(${responsedata},ensure_ascii=False) modules=json
log ${wq}
${exp_id} evaluate (json.loads('${wq}'))['data']['url'] modules=json
${exp_id} Evaluate re.findall(r'=(.+?)&state','''${exp_id}''') re
log ${exp_id[0]}
Set Global Variable ${exp_id}
callback
${aa} Create Session api http://xxxxx
${a} Set Variable ticket=${exp_id[0]}
${b} Set Variable state=
${addr} get Request api /xxxx params=${a}&${b}
log ${addr.content}
Comment ${responsedata} To Json ${addr.content}
Comment ${wq} evaluate json.dumps(${responsedata},ensure_ascii=False) modules=json
Comment log ${wq}
${a1} Set Variable demandId=xxxxx
${b1} Set Variable declineType=12
${c1} Set Variable declineReason=
${addr1} Post Request api /xxxxxx params=${a1}&${b1}&${c1}
log ${addr1.content}
${responsedata1} To Json ${addr1.content}
${wq1} evaluate json.dumps(${responsedata1},ensure_ascii=False) modules=json
log ${wq1}
log ${aa.cookies}
Set Global Variable ${aa.cookies}
审核
Create Session api http://xxxxxx cookies=${aa.cookies}
${a} Set Variable demandId=xxxxx
${b} Set Variable declineType=12
${c} Set Variable declineReason=
${addr} Post Request api /xxxxxx params=${a}&${b}&${c}
log ${addr.content}
log ${addr.cookies}
${responsedata} To Json ${addr.content}
${wq} evaluate json.dumps(${responsedata},ensure_ascii=False) modules=json
log ${wq}
网友评论