
什么是Newman
Newman可以使用Postman导出的collection文件直接在命令行运行,把Postman界面化运行的操作用命令行代替,如果不会Postman接口自动化测试,可以参考
因为是命令行操作,因此可以配合jenkins做接口自动化测试。

如何安装

如何使用
newman run examples/sample-collection.json

newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv

const newman = require('newman'); // require newman in your project
// call newman.run to pass `options` object and wait for callback
collection: require('./sample-collection.json'),
console.log('collection run complete!');
可以使用-r或者--reporters指定输出的类型,支持的类型有cli, json, html, junit, progress和emojitrain
newman run examples/sample-collection.json -r cli,json,html
将输出结果到命令行,并导出一份json和html报告,如下




命令行测试真实接口
我本地导出的colection文件名为课货.postman_collection.json

因为依赖我的接口依赖环境变量{{kehuo}},还需要导出环境变量,我本地生成文件名为local.postman_environment


newman run -e ./local.postman_environment.json -r cli,html ./课货.postman_collection.json
说明:
-e指定了环境变量文件,-r指定输出格式,这里我指定了命令行直接输出,和生成html,最后跟的就是我们collection文件啦



Newman+Jenkins实现自动化测试
如下,我添加了一个autotesting文件夹,分别放了接口文件postman_collection.json和环境变量文件postman_environment.json


这一步选择吴亦凡的freestyle,你看这个面又长又宽,就像这个碗又大又圆~





可以看到,我们的脚本已经启动了,再往后看,有3个接口测试失败了,还给出了原因


链接:https://www.cnblogs.com/chenqionghe/p/12417263.html
本文为51Testing经授权转载,转载文章所包含的文字来源于作者。如因内容或版权等问题,请联系51Testing进行删除
点击阅读☞
点击阅读☞
点击阅读☞
点击阅读☞
点击阅读☞