通过之前的了解,我们知道postman是基于javascript语言编写的,而导出的json格式的postman脚本也无法直接在服务器运行,它需要在newman中执行(可以把newman看做postman脚本的运行环境)
所以要实现在windows的cmd窗口或者linux系统中直接以命令的方式执行脚本,我们需要安装node.js,然后再在此基础上安装newman
 
一.windows下安装
1.安装node.js
到官网下载最新的windows版node.js,直接安装即可(不用自己去配置环境变量,安装完成后会自动配好)
安装完成后,打开cmd窗口,输入 node -v,如下出现版本号表示安装成功
 
2.安装newman
可以通过npm来安装newman,npm 是 JavaScript 的包管理工具,并且是 Node.js 平台的默认包管理工具。通过 npm 可以安装、共享、分发代码,管理项目依赖关系。
一般安装好node.js后会默认安装好npm的,直接使用即可
打开cmd窗口,执行以下命令
npm -g install newman
安装完成后,输入newman -v,如下出现版本号表示安装成功
 
3.如果想生成html格式的测试报告,还需要安装 newman-reporter-html
npm install -g newman-reporter-html
 
 
二.linux系统下安装
安装node.js
1.下载linux版本安装包,因为后缀为.tar.xz,需要分两步解压
[root@localhost hanmk]# xz -d node-v10.15.1-linux-x64.tar.xz
[root@localhost hanmk]# tar -xvf node-v10.15.1-linux-x64.tar
 
2.在环境变量中添加node.js路径
打开/etc/profile文件,添加如下两行
export NODE_HOME=/hanmk/node-v10.15.1-linux-x64
export PATH=$NODE_HOME/bin:$PATH
更新文件
[root@localhost node-v10.15.1-linux-x64]# source /etc/profile
 
3.查看是否安装成功
[root@localhost node-v10.15.1-linux-x64]# node -v
v10.15.1
 
安装newman
[root@localhost node-v10.15.1-linux-x64]# npm -g install newman
[root@localhost node-v10.15.1-linux-x64]# newman -v
4.3.1
 
安装newman-reporter-html
[root@localhost postman_script]# npm install -g newman-reporter-html
npm WARN newman-reporter-html@1.0.2 requires a peer of newman@4 but none is installed. You must install peer dependencies yourself.
 
+ newman-reporter-html@1.0.2
added 29 packages from 66 contributors in 13.266s
 
newman的常用命令
使用newman run 来执行脚本,先看下有哪些可选参数
[root@localhost bin]# newman run -h
Usage: run <collection> [options] URL or path to a Postman Collection. 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: [])
-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: )
--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: [])
--color <value> Enable/Disable colored output. (auto|on|off) (default: "auto")
--timeout [n] Specify a timeout for collection run (in milliseconds) (default: )
--timeout-request [n] Specify a timeout for requests (in milliseconds). (default: )
--timeout-script [n] Specify a timeout for script (in milliseconds). (default: )
--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).
-h, --help output usage information <collection>是指单个请求或者从postman导出的集合文件(也就是json格式的脚本)
options是一些组合参数,介绍下我用到的几个参数
() -e 指定环境变量,把在postman中设置的环境变量导出,然后再把路径填写到这里即可
() -g 指定全局变量,把在postman中设置的全局变量导出,然后再把路径填写到这里即可
() -n 指定迭代次数,即运行n次脚本
() --timeout-request 指定请求的超时时间
() -r 指定运行报告的格式,可以为json格式、html格式,默认为cli格式,即在命令行展示运行结果
 
实例1:
把接口测试脚本和环境变量脚本导出放到一个目录中,在cmd窗口中切换到该目录,执行如下命令
E:\5.coding\postman>newman run Test.postman_collection.json -n 2 -e base_url.postman_environment.json
Test.postman_collection.json -- 接口测试脚本文件
base_url.postman_environment.json -- 环境变量文件
-n 2表示迭代2次
执行过程如下
执行完成后,会出现一个类似报表的东西,显示整体运行结果

实例2:
E:\5.coding\postman>newman run Test.postman_collection.json -e base_url.postman_environment.json --reporters cli,json,html --reporter-json-export report-json.json --reporter-html-export report-html.html
 
--reporters cli,json,html --reporter-json-export report-json.json --reporter-html-export report-html.html
表示生成json和html格式的报告
html格式的报告长下面这个样子,还是蛮难看的。

postman(八):使用newman来执行postman脚本的更多相关文章

  1. postman—使用newman来执行postman脚本

    我们知道postman是基于javascript语言编写的,而导出的json格式的postman脚本也无法直接在服务器运行,它需要在newman中执行(可以把newman看做postman脚本的运行环 ...

  2. Android系统Recovery工作原理之使用update.zip升级过程分析(八)---解析并执行升级脚本updater-script【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465551  Android系统Recovery工作原理之使用update.zip升级过程分 ...

  3. 第七篇 Postman+Node.js+Newman+Jenkins实现自动化测试

    今天终于不咋忙了,学习整理一下一直想做却没实现的事儿,这事已经折磨团队半年之久了.因为项目是B端业务的测试,测试过程中需要生产大量的测试数据,而且都是跨多个系统的测试,对于后置流程的测试,这些同学往往 ...

  4. postman用法总结+newman持续集成

    一.postman 1.GET 请求:点击Params,输入参数及value,可输入多个显示在URL链接上(GET请求的请求头与请求参数如在接口文档中无特别声明时可以不填) 2.POST请求:在bod ...

  5. postman(一)批量执行接口测试用例

    postman(一)批量执行接口测试用例 学习了:https://blog.csdn.net/github_36032947/article/details/78611405 还可以把collecti ...

  6. Postman+Postman interceptor的安装和使用-解决把chrome浏览器登录状态同步到postman进行有依赖的接口测试 Postman 使用方法详解

    Postman+Postman interceptor的安装和使用-解决把chrome浏览器登录状态同步到postman进行有依赖的接口测试   问题引入:做接口测试时,有依赖关系的接口往往不好测试( ...

  7. 【转】linux 定时执行shell脚本

    在oracle 中可以利用dbms_job包定时执行pl/sql.sql过程,在像备份等需要在操作系统级定时任务只能采用crontab来完成 本文讲述crontab具体用法,以供备忘. 在oracle ...

  8. AngularJs中,如何在render完成之后,执行Js脚本

    AngularJs是Google开源的前端JS框架.使用AngularJs, 我们能够容易地.健壮的开发出类似于Gmail一样的单页Web应用.AngularJs这个新兴的MVC前端框架,具有以下特点 ...

  9. crontab不执行perl脚本分析

    在新装的Linux服务器上部署了一个作业监控磁盘空间并提前告警,在shell脚本里面调用了一个perl脚本发送告警邮件.结果出现了一个很奇怪的现象:如果手工执行该脚本/home/oracle/scri ...

随机推荐

  1. JVM内存布局

    1. 概述 对于从事c和c++程序开发的开发人员来说,在内存管理领域,他们既拥有最高权力的”皇帝“又是从事最基础工作的”劳动人民“---既拥有每个对象的”所有权“,又担负着每个对象开始到终结的维护责任 ...

  2. Codeforces 706C - Hard problem - [DP]

    题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...

  3. Eclipse 02: 安装spring tool suite插件

    在实际项目开发时,如果我们创建了一个spring文件,其实也就是个xml文件,如果没有集成spring的开发工具,创建的就是一个单纯的xml文件.安装spring插件以后创建spring配置文件会方便 ...

  4. python 中的__new__与__init__

    在Python中的class中有两个方法__new__与__init__,有什么区别呢? class TestCls(): """docstring for TestCl ...

  5. MSMQ 跨服务器读写队列的“消息队列系统的访问被拒绝”的解决方案

    转自https://www.cnblogs.com/jyz/articles/4612333.html 最近项目中需要跨服务器对消息队列进行读写,开始在单独开发机器上进行Queue的读写没问题.但是部 ...

  6. AsyncHttpClient使用

    github地址:AsyncHttpClient, API:API 1.X和2.X差别很大,我用的1.X中的最新版 1.9.39. 这是一个异步请求的工具,越简单越好,不喜欢再结合netty使用.As ...

  7. python中的单例

    使用__new__ 因为一个类每一次实例化的时候,都会走它的__new__方法.所以我们可以使用__new__来控制实例的创建过程,代码如下: class Single: instance = Non ...

  8. gzframework demo搭建

    感谢框架作者,这里给出他的博客 http://www.cnblogs.com/GarsonZhang/ 背景:由于作者对代码的持续开发,导致了以前博客中的下载地址和构建方法和目前的项目不对应,这里给出 ...

  9. es6合并数组...

    加了...和不加...是不一样,...会把原来数组拆开

  10. 笔记:Linux(AWS Redhat)开机启动workman进程(/etc/rc.local必须是755权限)

    1.使用which命令查看php的安装路径 [root@ip---- ~]# which php /usr/bin/php 2.使用vim /etc/rc.local将要执行的命令加入/etc/rc. ...