POSTMAN脚本录制
https://blog.csdn.net/u011541946
postman有两种使用方式:
- postman安装版
- chrome插件版
postman安装版
postman安装版使用代理方式来捕获浏览器的http请求。
这里,我们使用chrome浏览器和Windows安装版来演示录制postman脚本的过程。
-
首先,下载并安装postman,从官网https://www.getpostman.com/apps下载
图片.png -
打开安装后的postman
图片.png -
创建Collection,在Collections里添加一个新的采集目录test
图片.png
-
点击右上方的按钮Capture API requests with postman,设置代理,端口号Port设为5555,Target目标文件设为Collection: test
图片.png
![](http://upload-images.jianshu.io/upload_images/12830151-551eb1a56af67697.png?imageMogr2/auto-orient/strip|imageView2/2/w/477/format/webp)
-
打开chrome浏览器,设置代理:系统->打开代理设置->连接->局域网设置。
图片.png -
开始录制脚本
比如,我们模拟登录http://andaily.com/hb/login.hb的过程,一共有三步:
a. 在浏览器地址栏输入http://andaily.com/hb/login.hb
b.输入用户名密码,点击登录
c.登录成功,浏览器跳转到首页http://andaily.com/hb/instance/list.hb
做完这三步后,可以看到,Collections下面的test目录会捕获这三次请求的记录。
- 导出脚本
图片.png
图片.png
选择Collection V2,执行Export。
postman插件版
- 首先,需要在chrome浏览器安装两个插件:
-
Postman Interceptor拦截器,用于拦截chrome浏览器的http请求
-
Postman,真正的http监控工具,拦截器拦截的http请求会传给Postman
在chrome网上应用店中,搜索Postman Interceptor,添加该拓展程序到浏览器
![](http://upload-images.jianshu.io/upload_images/12830151-f3cec4e61b19920f.png?imageMogr2/auto-orient/strip|imageView2/2/w/558/format/webp)
添加后,启动Postman Interceptor插件,在Postman Interceptor小窗口,点击Postman Chrome app,安装Postman插件。
![](http://upload-images.jianshu.io/upload_images/12830151-9c8ffa169b04e844.png?imageMogr2/auto-orient/strip|imageView2/2/w/319/format/webp)
![](http://upload-images.jianshu.io/upload_images/12830151-301b42c5655c8fab.png?imageMogr2/auto-orient/strip|imageView2/2/w/558/format/webp)
安装后,设置 Postman Interceptor拦截器的Request Capture为ON
同时,打开Postman拓展程序
![](http://upload-images.jianshu.io/upload_images/12830151-8eec9b753fc7ba44.png?imageMogr2/auto-orient/strip|imageView2/2/w/306/format/webp)
![](http://upload-images.jianshu.io/upload_images/12830151-7853adbad405dce5.png?imageMogr2/auto-orient/strip|imageView2/2/w/558/format/webp)
启动Postman Interceptor拦截器后,拦截器会拦截所有chrome浏览器的请求,所有请求在Postman工具的History列表可以看到。
- 开始录制脚本
比如,我们模拟登录http://andaily.com/hb/login.hb的过程,一共有三步:
a. 在浏览器地址栏输入http://andaily.com/hb/login.hb
b.输入用户名密码,点击登录
c.登录成功,浏览器跳转到首页http://andaily.com/hb/instance/list.hb
做完这三步后,可以看到,Postman的历史列表已经有了这三次请求的记录。
![](http://upload-images.jianshu.io/upload_images/12830151-ed4d2afd51a41583.png?imageMogr2/auto-orient/strip|imageView2/2/w/309/format/webp)
在Collections,添加一个新的采集文件test,将History里面需要的请求添加到test采集文件夹。
![](http://upload-images.jianshu.io/upload_images/12830151-b1f39bf8fef000d5.png?imageMogr2/auto-orient/strip|imageView2/2/w/303/format/webp)
![](http://upload-images.jianshu.io/upload_images/12830151-0be5358062b9b338.png?imageMogr2/auto-orient/strip|imageView2/2/w/299/format/webp)
![](http://upload-images.jianshu.io/upload_images/12830151-0e2f4b1098126de0.png?imageMogr2/auto-orient/strip|imageView2/2/w/295/format/webp)
然后,开始从Postman导出脚本
![](http://upload-images.jianshu.io/upload_images/12830151-45a391f34dc28ac0.png?imageMogr2/auto-orient/strip|imageView2/2/w/298/format/webp)
![](http://upload-images.jianshu.io/upload_images/12830151-e1bf0c5f6e42af82.png?imageMogr2/auto-orient/strip|imageView2/2/w/475/format/webp)
选择Collection V2,执行Export。
将导出的脚本内容复制到API监控的导入页面,执行导入。
作者:jection
链接:https://www.jianshu.com/p/e16e24e9abc7
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。