PostMan测试报告

PostMan测试报告

1、安装
  • 安装node
  • 安装newman、newman-reporter-html
npm install -g newman
npm install -g newman-reporter-html
  • newman 参数解析
Options:
  -e, --environment <path>        Specify a URL or Path to a Postman Environment.
  -g, --globals <path>            Specify a URL or Path to a file containing Postman Globals.
  --folder <path>                 Specify folder to run from a collection. Can be specified multiple times to run multiple folders (default: [])
  --working-dir <path>            The path of the directory to be used as the working directory
  --no-insecure-file-read         Prevents reading the files situated outside of the working directory
  -r, --reporters [reporters]     Specify the reporters to use for this run. (default: ["cli"])
  -n, --iteration-count <n>       Define the number of iterations to run.
  -d, --iteration-data <path>     Specify a data file to use for iterations (either json or csv).
  --export-environment <path>     Exports the environment to a file after completing the run.
  --export-globals <path>         Specify an output file to dump Globals before exiting.
  --export-collection <path>      Specify an output file to save the executed collection
  --postman-api-key <apiKey>      API Key used to load the resources from the Postman API.
  --delay-request [n]             Specify the extent of delay between requests (milliseconds) (default: 0)
  --bail [modifiers]              Specify whether or not to gracefully stop a collection run on encountering an errorand whether to end the run with an error based on the optional modifier.
  -x , --suppress-exit-code       Specify whether or not to override the default exit code for the current run.
  --silent                        Prevents newman from showing output to CLI.
  --disable-unicode               Forces unicode compliant symbols to be replaced by their plain text equivalents
  --global-var <value>            Allows the specification of global variables via the command line, in a key=value format (default: [])
  --env-var <value>               Allows the specification of environment variables via the command line, in a key=value format (default: [])
  --color <value>                 Enable/Disable colored output. (auto|on|off) (default: "auto")
  --timeout [n]                   Specify a timeout for collection run (in milliseconds) (default: 0)
  --timeout-request [n]           Specify a timeout for requests (in milliseconds). (default: 0)
  --timeout-script [n]            Specify a timeout for script (in milliseconds). (default: 0)
  --ignore-redirects              If present, Newman will not follow HTTP Redirects.
  -k, --insecure                  Disables SSL validations.
  --ssl-client-cert <path>        Specify the path to the Client SSL certificate. Supports .cert and .pfx files.
  --ssl-client-key <path>         Specify the path to the Client SSL key (not needed for .pfx files)
  --ssl-client-passphrase <path>  Specify the Client SSL passphrase (optional, needed for passphrase protected keys).
  --verbose                       Show detailed information of collection run and each request sent
  -h, --help                      output usage information
  • 使用例子
    newman run 测试脚本 -e 环境变量文件 -g 全局变量文件 -d 测试数据文件 -n 迭代次数 -r html --reporter-html-export report.html
  • run 测试脚本:执行的postman脚本
  • -e 环境变量文件:环境变量的文件
  • -g 全局变量文件:全局变量的文件
  • -d 测试数据的文件:比如参数化用到的文件
  • -n 迭代次数:要执行多少遍
  • -r htm:用来指定生成的数据结果类型,如JSON,html
  • –reporter-html-export source:执行html报告生成的路径,如果指定,则会在当前目录生成一个newman文件夹,文件夹报告生成的HTML报告

2、坑点

当使用命令启动带参数文件时出现的Bug:
例如:

  • data.csv
    在这里插入图片描述
  • postman脚本
    在这里插入图片描述
    命令行运行:newman run test_scripts.postman_collection.json -d data.csv
  • test_scripts.postman_collection.json 导出的测试集如下图
    在这里插入图片描述
  • 运行结果:
    在这里插入图片描述
    分析:发现key1没有解析出来倍感焦虑
  • 解决在data.csv再添加一个额外的列即可如:
    在这里插入图片描述
  • 再次运行结果:newman run test_scripts.postman_collection.json -d data.csv
    在这里插入图片描述
    恭喜恭喜通过😄 😂💢 🐑🐮🐴🐍🐦🐛

3、综合命令使用

  • postman 脚本
    在这里插入图片描述
  • 步骤
    导出测试集:test_scripts.postman_collection.json
    导出环境变量:baidu_environment.postman_environment.json
    导出全局变量globals.postman_globals.json
    data.csv:
    在这里插入图片描述
  • 命令运行
    newman run test_scripts.postman_collection.json -e baidu_environment.postman_environment.json -g globals.postman_globals.json -d data.csv -r html --reporter-html-export report.html
    则在当前文件就会生成report.html报告,迭代默认显示第一次的结果:
    在这里插入图片描述
    命令测试查看:newman run test_scripts.postman_collection.json -e baidu_environment.postman_environment.json -g globals.postman_globals.json -d data.csv
    结果正常:
    在这里插入图片描述
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值