newman(postman命令行版)跟Jenkins做持续集成
(2022-04-03 15:13:26)
标签:
newmanjenkins |
分类: 测试 |
在postman中执行测试用例通过后,将postman中的用例导出,并用Newman执行
-e的用法是如果我们的集合设置到环境变量,那么但是运行集合文件是报错的,需要使用-e指定才能运行集合,比如运行测试搜索集合
5、-n,–iteration-count 指定迭代次数
如集合下存在文件(前端接口),使用该命名,则只运行集合中前端接口文件下的接口
1、安装newman
安装node.js
https://nodejs.org/en/
node -v
查看是否安装好了
npm install
--global --production windows-build-tools
npm install -g
newman
newman
-v 查看是否安装好了
npm
install newman-reporter-html
2、执行Newman
导出请求、环境变量
命令行运行collection
cmd进入到collection的json文件的目录下,输入指令
newman run postmanEcho.postman_collection.json
例子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
例子2,运行https://www.getpostman.com/collections/cb0cea0af1467c8008fb(postman生成的
)中的所有api,并使用env.json作为环境变量和globals.json作为全局变量,并使用外部data.csv作为外部数据,最后设置了接口请求超时时间为5S
。
newman run
https://www.getpostman.com/collections/cb0cea0af1467c8008fb
–environment env.json –iteration-data data.csv –globals
globals.json –timeout-request 5000
例子3
newman run C:\11\testpm.postman_collection.json
–reporter-html-export C:\11\htmlOut.html -n
10
迭代10次
1、运行一个集合
newman run 集合名
newman run url地址
2、-e,–environment 指定环境文件路径或者url
newman run d:\test.postman_collection.json -e
d:\test.postman_environment.json
3、-g,–globals 指定全局变量的文件地址或url 用法如-e
4、-d,—-iteration-data 指定用于迭代的数据源文件路径
newman run d:\test.postman_collection.json -e
d:\test.postman_environment.json -d d:\testdata.csv
newman run 集合名 -n 10(迭代次数)
6、–folder 运行集合中指定的文件夹
7、–export-environment 导出该运行集合中的环境变量文件
可指定路径和名称
newman run d:\test.postman_collection.json -e
d:\test.postman_environment.json -d d:\testdata.csv
—-export-environment d:\test
–export -environment d:\test 导入环境变量文件名称为test
存储在d盘下
注意:
将该文件导入postman之后还是与导出前的文件名相同,比如此处【test.postman_environment.json】导出前对应的环境变量为【test】,那么test导入之后的命名还是【test】,同样,导出集合也是如此。
8、–export-globals 导出全局环境变量
9、–export-collection 导出集合文件
10、–timeout (ms) 设置整个集合运行完成执行的时间
11、–timeport-request (ms) 指定等待请求返回响应的时间
12、–timeout-script (ms)指定等待脚本执行完成的时间
3、结合Jenkins
步骤一:在Jenkins 机器上安装Newman
步骤二:搭建Jenkins环境,并新建个自由风格的Job
步骤三:构建选择Execute Windows batch command,并输入newman 运行命令
后一篇:jaraent与jar