newman
Newman是Postman的一个命令行集合运行者。 它允许您直接从命令行运行和测试Postman集合。 它是以可扩展性为基础构建的,因此您可以轻松将其与持续集成服务器集成并构建系统。
官方简介:https://www.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman
-
安装newman
通过npm安装,使用淘宝镜像。
命令:npm install -g newman --registry=https://registry.npm.taobao.org
-
运行postman中导出的用例
命令:newman run test.postman_collection.json(postman导出的文件名称)
-
也可以将一个集合作为URL来传递(postman中分享的URL)
注:分享URL需要先注册postman
运行命令:newman run https://www.getpostman.com/collections/77272ceeffb136b216a4
注意 :run 后面跟上要执行的json文件或者URL(json 和 URL 都由postman导出生成),后面可加上一些参数,例如环境变量,测试报告,接口请求超时时间等等。一下两个完整的例子做参考
例子1,通过newman 运行postman导出的test1.json文件,并生成多种测试报告(json,junit的xml,html):
newman run c:\test1.json --reporters cli,html,json,junit --reporter-json-export jsonOut.json --reporter-junit-export xmlOut.xml --reporter-html-export htmlOut.html
标红部分修改成需要生成的报告名称:newman run test.postman_collection.json --reporters cli,html --reporter-html-export test.html 此例子中只生成了HTML报告
例子2,运行https://www.getpostman.com/collections/cb0cea0af1467c8008fb(postman生成的 )中的所有api,并使用env.json作为环境变量和globals.json作为全局变量,并使用外部data.csv作为外部数据,最后设置了接口请求超时时间为5S 。
newman run https://www.getpostman.com/collections/77272ceeffb136b216a4 --environment env.json --iteration-data data.csv --globals globals.json --timeout-request 5000
Jenkins集成
-
新建自由风格的任务
-
配置Job,存放路径必须为英文路径,输出html的测试报告
命令:newman run test.postman_collection.json --reporters cli,html --reporter-html-export test.html 标红为用例名称
我这里将测试用例存放在Jenkins的workspace\{创建的job目录下}了
-
构建后操作--设置html文件名称例如:test.html 与生成的html报告名称保持一致
注意:生成HTML报告,将postman导出的用例放在Jenkins的workspace\{创建的job目录下}
如:\workspace\newman_test
-
生成HTML报告
-
生成XML报告
命令:newman run test.postman_collection.json --reporters cli,html,json,junit --reporter-json-export test.json --reporter-junit-export test.xml --reporter-html-export test.html
-
构建后操作--设置 *.xml
-
生成的XML报告
欢迎关注公众号交流