使用newman执行接口测试用例

一、安装Newman
npm install -g newman
 
 
二、执行case
newman run case生成的json文件
 
三、参数
npm install -g newman
  • -e <source>, --environment <source>
设置环境变量
  • -g <source>, --globals <source>
设置全局变量
  -r cli
  -r json
生成cli或json格式的报告
 
需要执行命令 npm install -g newman-reporter-html来全局安装支持Newman生成html报告的组件 然后,再次执行命令 newman run Postman_API_test.postman_collection.json -d data.json -r html
一般常用以下命令
newman run 用例集json -e 环境变量json -g 全局变量json
 
四、示例
1、设置environment环境 -e
执行以下命令
newman run test.postman_collection.json -e test.postman_environment.json >d://error.log
执行结果
 
由于接口依赖登录,未设置登录cookie导致请求失败,故需要将cookie设置为全局变量
 
2、设置全局变量 -g
执行以下命令
newman run test.postman_collection.json -e test.postman_environment.json -g C:\Users\test.postman_global.json >d://error1.log
 
 
 

猜你喜欢

转载自www.cnblogs.com/echoqi/p/10264860.html
今日推荐