Robotframework做接口测试

一 导入库

1.win+r 输入cmd进入命令提示符,输入以下内容执行安装:
pip install requests
pip install robotframework-requests
安装好后pip list查看:
在这里插入图片描述
2.RF中导入:RequestsLibrary在这里插入图片描述
*** Settings ***
Library RequestsLibrary
Library Collections
Library Selenium2Library

二 实例脚本 get

2.1 参数在链接中

获取collection列表数据,参数在第一行链接中直接修改${collection_list}中的参数值即可,也可参数化在变量中修改参数:
在这里插入图片描述

${
   collection_list}	set variable	list?page=1&limit=10
create session	collectionlist	${
   url[0]}${
   collection_list}		
${
   get_head}	create dictionary	Content-Type=application/x-www-form-urlencoded	Authori-zation=${
   token[0]}	
${
   collection_list}	Get Request	collectionlist	${
   url[0]}${
   collection_list}	headers=${
   get_head}
#打印结果				
log	${
   collection_list.text}			
log	${
   collection_list.json()}			
log	----- 开始断言 ------			
${
   result}	run keyword and return status	should be equal as strings	ok	${
   collection_list.json()["msg"]}
Should Be True	${
   result}			
delete all sessions				

断言:msg返回ok即执行通过
在这里插入图片描述

执行结果:在这里插入图片描述
在这里插入图片描述

遇到问题:
在这里插入图片描述
解决方法:
方法1.清空get request的uri即可
在这里插入图片描述
在这里插入图片描述
方法2.把${collection_list} 放到Get Request中
在这里插入图片描述

2.2 参数放params中

获取产品详情,提供产品id放到变量${get_data}中,将变量值赋予patams:
在这里插入图片描述

${
   fulu_product}	set variable	/ams/fulu/getGoods			
create session	checkproduct	${
   url[0]}			
${
   get_head}	create dictionary	Content-Type=application/x-www-form-urlencoded	Authori-zation=${
   token[2]}		
${
   get_data}	to json	{
   "product_id":"10000353"}			
${
   fululist}	Get Request	checkproduct	${
   fulu_product}	headers=${
   get_head}	params=${
   get_data}
#打印结果					
log	${
   fululist.text}				
log	${
   fululist.json()}				
log	----- 开始断言 ------				
${
   result
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值