1、Pre-request Script输入以下内容,其中userid1和username1对应的是*.txt文件里的title名,需要传几个参数,写几个列名。postman传参数,第一行需要写列名,否则无法识别。userid2和username2是setEnvironmentVariable方法的key
值,作为post请求体Body里的value
值
postman.setEnvironmentVariable("userid2",data["userid1"]);
postman.setEnvironmentVariable("username2",data["username1"]);
![](https://img.haomeiwen.com/i2665834/e0d425410568ba08.png)
2、Body里的内容,user_id和user_name是数据库表中存储的字段名,userid2和username2的值对应的是Pre-request Script中setEnvironmentVariable方法的
key
值
[{"user_id":"{{userid2}}","user_name":"{{username2}}"}]
![](https://img.haomeiwen.com/i2665834/d7785fd86e37204a.png)
3、输入正确的Url、Header(一般写Authorization和Content-Type,其他看具体项目要求)、Body和Pre-request Script,直接可以点击左上角的Runner按钮(postman版本是Version 5.5.2),打开Collection Runner
![](https://img.haomeiwen.com/i2665834/edd05db74756179d.png)
4、选择具体的Collection,Iterations迭代次数,在Data处点击Select File打开上述第1点中*.txt文件,此时会出现Data File Type选项,选择text/csv,点击Prewiew按钮进行预览
![](https://img.haomeiwen.com/i2665834/86079456270d0b37.png)
注意:txt文本如果有中文输入,一点要将这个txt文件的编码格式改为UTF-8,否则postman导入后预览看到的是乱码
![](https://img.haomeiwen.com/i2665834/170650ffad36f6a0.png)
5、点击Collection Runner->Start Runner按钮,查看结果。postman不会显示通过和失败的具体个数(原因不详),但是我们可以去项目中查看对应接口实现的功能,肯定是生效了。
![](https://img.haomeiwen.com/i2665834/9d6c56eb22bbef5b.png)
网友评论