第2篇文章API测试之Postman使用全指南(二)讲述了如何将请求参数化
第3篇文章API测试之Postman使用全指南(三)讲述了如何创建Postman Tests和集合
如何使用Collection Runner 运行集合
有两种方式来运行一个集合,即Collection Runner和Newman。 Collection Runner: Step 1) 单击页面顶部导入按钮旁边的Runner按钮,如下图。

**Step 2)**Collection Runner页面应该出现如下所示。以下是对各个字段的描述

Step 3) 做如下设置,运行你的测试集合
- 选择Postman测试集合-集合迭代次数为3
- 设置延迟为2500毫秒
- 点击Start Run按钮

Step 4) 单击Run按钮后将显示Run结果页。根据延迟的不同,你应该在测试执行的同时看到显示的结果。
1、一旦测试完成,你就可以看到测试状态是通过还是失败,以及每个迭代的结果。 2、你将看到Get请求的Pass状态; 3、由于我们没有任何Post测试,所以应该会出现请求没有任何测试的消息。

可以出在请求中进行测试是多么重要,这样你就可以验证HTTP请求状态是否成功,以及是否创建或检索了数据。
如何使用Newman运行集合
运行集合的另一种方式是通过Newman。Newman和Collection Runner之间的主要区别如下: 1、Newman是Postman的替代品,所以需要单独安装Newman; 2、Newman使用命令行,而Collection Runner使用UI界面; 3、Newman可以用于持续集成。
安装Newman并运行Collection,步骤如下: Step 1) 下载并安装NodeJs: http://nodejs.org/download/ Step 2) 打开命令行窗口并输入下面命令:
npm install -g newman
安装后 如下图:

Step 3 ) Newman安装好之后,让我们回到Postman的workspace。在Collections框中,单击三个点 … 会出现新的选择选项,可看到Export选项,如下图:

Step 4 ) 选择导出集合,默认使用推荐的集合版本,比如此处是v2.1,然后单击导出:

Step 5 ) 选择你想要保存的地址之后点击保存,这里建议专门新建一个文件夹来存放你的Postman tests。 Step 6 ) 另外还需要导出我们的环境(enviroment)。单击全局环境下拉菜单旁边的eye图标,选择JSON格式下载。选择你想要的位置,然后单击Save。最好将环境放在与Step5 导出的集合相同的文件夹中。

Step 7 ) 导出Environment 到集合文件夹后,现在回到命令行,将目录更改为保存集合和环境的位置。
cd C:\Users\Asus\Desktop\Postman Tests
Step 8 ) 使用下面的命令运行你的测试集合:
newman run PostmanTestCollection.postman_collection.json -e Testing.postman_globals.json
运行的结果应该如下图:

关于Newman的一些基础指导如下: 1、只运行集合(如果没有环境或测试数据文件依赖关系,则可以使用此选项。)
newman run <collection name>
2、运行集合和环境(参数-e 是environment)
newman run <collection name> -e <environment name>
3、使用所需的编号运行集合的迭代。
newman run <collection name> -n <no.of iterations>
4、运行数据文件
newman run <collection name> --data <file name> -n <no.of iterations> -e <environment name>
5、设置延迟时间。(这一点很重要,因为如果由于请求在后台服务器上,完成前一个请求时没有延迟时间直接启动下一个请求,测试可能会失败。)
newman run <collection name> -d <delay time>