newman
Newman是Postman的一个命令行集合运行者。 它允许您直接从命令行运行和测试Postman集合。 它是以可扩展性为基础构建的,因此您可以轻松将其与持续集成服务器集成并构建系统。
官方简介:https://www.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman
通过npm安装,使用淘宝镜像。
命令:npm install -g newman --registry=https://registry.npm.taobao.org
命令:newman run test.postman_collection.json(postman导出的文件名称)
注:分享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集成
命令:newman run test.postman_collection.json --reporters cli,html --reporter-html-export test.html 标红为用例名称
我这里将测试用例存放在Jenkins的workspace\{创建的job目录下}了
注意:生成HTML报告,将postman导出的用例放在Jenkins的workspace\{创建的job目录下}
如:\workspace\newman_test
命令: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
欢迎关注公众号交流:零基础学自动化测试