Postman使用总结

1.可在param参数中设置对应key的值进行随机值的设置:
----
{{$timestamp}}
{{$microtimestamp}} # 毫秒级别的当前时间戳
{{$randomInt}}
{{$guid}}
----

2.可在请求body中修改对应报文的值

--------------------
3.将返回报文值作为全局变量,在下一个接口进行调用:
在Tests:

var jsonData = JSON.parse(responseBody); //设置变量

var subInfo = jsonData.suborderInfo[0];

console.log(subInfo.subOrderId);

pm.globals.set("subOrd",subInfo.subOrderid); //设置全局环境变量

pm.test("Body matches string", function() {
pm.expect(pm.response.text().to.include("subOrderId")); //test
});

pm.test("response time is less than 500ms", function() {
pm.expect(pm.response.responseTime().to.be.below(200));
});

***********
格式:
pm.test("随便起的名字", function() {
pm.expect().to.方法.(比较的参数);
});
---------------------------------------------------------------
设置全局变量
使用时,{{变量名}}

==============================================================

4.利用Postman中collections的runner进行半自动化测试:

思路:将CSV格式文件的数据输入到postman中的一个参数进行测试

步骤: (1)将postman中Pre-request Script设置一个环境变量:
pm.environment.set("phoneNum",data.["phoneNumber"-文件名中与请求变量同名的名称]);
(2)将postman中变量参数设置为{{phoneNumber}};
(3) 在collection Runner中设置iterations迭代次数、选择csv文件;
(4)发起run接口集合。
=============
5.Postman可以对数据库进行增删改查操作:
安装:xmysql启动该服务,cmd--xmysql -h localhost -u root -p 123456 databaseName;

步骤:1.用postman中get请求数据库的url---2.通过get方法可以查数据库(eg:get:http://localhost:3000/api/table_name?_where(id,eq,1)),post方法可以增加数据库,delete方法可以删除数据库中的记录

====================
6.postman和Newman的用法:(唯一好处是可以生成报告)
Newman专门用来运行postman的脚本,安装Newman后,利用命令行进行对js脚本的运行:
newman run d:postman.json -reporters-html-postmanrun.html
--也可以使用CSV文件、环境全局变量、并做断言:
newman run url -environment env.json -iteration-data -timeout-request 2000;

原文地址:https://www.cnblogs.com/zhangcnblogs/p/12510671.html