newman使用

简介:

  Newman 是 Postman 推出的一个 nodejs 库,直接来说就是 Postman 的json文件可以在命令行执行的插件。
  Newman 可以方便地运行和测试集合,并用之构造接口自动化测试和持续集成。

安装:

  1.先下载并安装Node.js,下载地址:https://nodejs.org/en/

  2.打开cmd,输入node,显示“>”,说明node安装成功;

  3.安装newman,打开cmd,输入npm install -g newman

  4.通过查看newman版本测试安装是否成功,打开cmd,输入newman -v,出现版本信息即安装成功;

 

newman使用:

 1.newman run 集合名/url地址:运行一个集合,url地址为集合文件导出的url

// newman run 集合名
newman run sample.postman_collection.json
// newman run url地址
newman run https://www.getpostman.com/collections/c1454cb35

 2.-e/-environment 环境文件路径

// newman run 集合名 -e 环境路径
newman run sample.postman_collection_hava_environment.json -e ..\env\正式环境.postman_environment.json
// newman run 集合名 --environment 环境路径
newman run sample.postman_collection_hava_environment.json --environment ..\env\正式环境.postman_environment.json

3.-g/--globals 全局变量路径文件

// newman run 集合名 -e 环境路径文件 -g 全局变量路径文件
newman run sample.postman_collection_hava_environment.json -e ..\env\正式环境.postman_environment.json -g ..\env\my_postman_globals.json
// newman run 集合名 -e 环境路径文件 --globals 全局变量路径文件
newman run sample.postman_collection_hava_environment.json -e ..\env\正式环境.postman_environment.json --globals ..\env\my_postman_globals.json

4.-d/--iteration-data 指定用于迭代的数据源文件路径

// newman run 集合名 -e 环境路径文件 -d 测试数据源文件路径
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv
// newman run 集合名 -e 环境路径文件 --iteration-data 测试源文件路径
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json --iteration-data ..\testdata\test_data.csv

5.-n,--iteration-count 指定迭代次数

// newman run 集合名 -e 环境路径文件 -d 测试源文件路径 -n 迭代次数
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv -n 3
// newman run 集合名 -e 环境路径文件 -d 测试源文件路径 --iteration-count 迭代次数
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv --iteration-count 3

6.--folder 运行集合中指定的文件夹

// newman run 集合名 -e 环境路径文件 -d 测试源文件路径 -n 迭代次数 --folder 集合中指定的文件夹
 newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv --folder test_suit_01

7.--timeout 设置整个集合运行完成执行的时间,单位ms

// newman run 集合名 -e 环境路径文件 -d 测试源文件路径 -n 迭代次数 --folder集合中指定的文件夹 --timeout 整个集合运行完成执行的时间(单位ms)
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv -n 3 --folder test_suit_01 --timeout 5000

8.-r,--reporter 指定用于此次运行的报告类型xml,json,junit,html,htmlextra

  • --reporter-json-export jsonReport.json:生成json格式的测试报告
  • --reporter-junit-export  xmlReport.xml:生成xml格式的次测试报告
  • --reporter-html-export htmlReport.html:生成html格式的测试报告
  • --reporter-htmlextra-export htmlReport.html:生成htmlextra格式的测试报告

 

//newman run 集合名 -e 环境路径文件 -d 测试源文件路径 -r 报告格式 --reporter-junit-export 生成文件路径和文件名
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv -r json --reporter-json-export ..\reports\jsonTestReport.json

如果需要一次性生成多份报告

//newman run 集合名 -e 环境路径文件 -d 测试源文件路径 -r 报告格式,报告格式 --reporter-json-export 生成文件路径和文件名 --reporter-html-export 生成文件路径和文件名
newman run sample.postman_collection_hava_environment_word_data.json -e ..\env\正式环境.postman_environment.json -d ..\testdata\test_data.csv -n 4 -r json,html --reporter-json-export ..\reports\jsonReport.json --reporter-html-export ..\reports\htmlReport.html

 

posted @ 2020-06-05 14:06  Alin。  阅读(442)  评论(0编辑  收藏  举报