Newman基本使用

版权声明:文章未经本人许可,不得用于商业用途及传统媒体。网络媒体转载请注明出处,否则属于侵权行为。 https://blog.csdn.net/m0_37618247/article/details/83182795

安装

要运行Newman,请确保您具有Node.js> = v6

安装 npm install -g newman

补充:

如果在生成reporter过程中报错提示

newman: “html” reporter could not be loaded.

run npm install newman-reporter-html

需要加载html模块,可以在命令行中运行以下命令: sudo npm install -g newman-reporter-html

用法

使用Newman run 命令运行指定的集合;您可以从Postman 轻松地将Postman Collection导出为json文件,并使用Newman运行它。

用法:newman run json文件 如:newman run sample-collection.json

Newman提供不同形式的收集测试结果:cli,json,junit,progress、emojitrain、HTML 需要使用这些结果前面必须跟着-r或--reporters选项配置

如:newman run sample-collection.json -r json

  • cli 默认情况下会启用CLI报告器。但是,启用一个或多个其他记者将导致无CLI输出。在这种情况下显式启用CLI选项。
  • json 返回的结果将已JSON的格式输出指定的到json文件

如:newman run sample-collection.json -r json --reporter-json-export test.json

  • junit 生成junit的xml文件;后期可以利用junit相关的命令生成测试报告

如:newman run sample-collection.json -r junit --reporter-junit-export test.xml

  • progress
  • emojitrain
  • HTML 生成Html格式的测试结果报告

如:newman run sample-collection.json -r html --reporter-html-export test.html

如果要一起使用这些参数,就必须遵循以下规则:

newman run TestClass.postman_collection.json -r junit,html --reporter-junit-export junit.xml --reporter-html-export html.html

Newman其他语法

  • -e, --environment <path>

指定环境文件路径或者url ,-e的用法是如果我们的集合设置到环境变量,那么但是运行集合文件是报错的,需要使用-e指定才能运行集合,比如运行测试搜索集合

如:newman run TestClass.postman_collection.json -e TestClass.postman_collection.json

  • -g, --globals <path> 指定全局变量的文件地址或url 用法如-e
  • --folder <path> 运行集合中指定的文件夹
  • -r, --reporters [reporters] 指定用于运行的产生数据结果模型 (默认是: cli)
  • -n, --iteration-count <n> 指定迭代次数;虽然文件中存在3个参数,但是设置迭代次数2,则只迭代2次
  • -d, --iteration-data <path> 指定用于迭代的数据源文件路径 

如: newman run TestClass.postman_collection.json -e TestClass.postman_collection.json -d test.csv

  • --export-environment <path> 导出该运行集合中的环境变量文件 可指定路径和名称

注意:

将该文件导入postman之后还是与导出前的文件名相同,比如此处【测试项目.postman_environment.json】导出前对应的环境变量为【测试项目】,那么test导入之后的命名还是【测试项目】,同样,导出集合也是如此。

  • --export-globals <path> 导出全局环境变量
  • --export-collection <path> 导出集合文件
  • --timeout [n] 设置整个集合运行完成执行的时间 (单位:毫秒)
  • --timeout-request [n] 指定等待请求返回响应的时间(单位:毫秒)
  • --timeout-script [n] 指定等待脚本执行完成的时间 (单位:毫秒)

猜你喜欢

转载自blog.csdn.net/m0_37618247/article/details/83182795
今日推荐