IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发测试 -> Postman - Running collections on the command line with Newman -> 正文阅读

[开发测试]Postman - Running collections on the command line with Newman

官方文档

Running collections on the command line with Newman | Postman Learning Center

1.下载Nodejs

根据不同的系统下载对应的Nodejs

Download | Node.js

2.下载Newman

在npm目录下执行下面的命令

$ npm install -g newman

3.准备好对应的postman collection

{
	"info": {
		"_postman_id": "postman_id",
		"name": "APITest,
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "GetList",
			"event": [
				{
					"listen": "test",
					"script": {
						"exec": [
							"pm.test(\"Status code is 200\", function(){",
							"    pm.response.to.have.status(200);",
							"});",
							"var jsonData=JSON.parse(responseBody);",
							"tests[\"Check response status value is 0\"] = jsonData.code===0;",
							"tests[\"Check response msg is success\"] = jsonData.msg===\"success\";"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "email",
						"value": "{{email}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "https://{{server_name}}/v1/report/list",
					"protocol": "https",
					"host": [
						"{{server_name}}"
					],
					"path": [
						"v1",
						"report",
						"list"
					]
				}
			},
			"response": []
		}
	]
}

4.执行postman collection

$ newman run APITest.postman_collection.json

指定data file,json或者csv

$ newman run APITest.postman_collection.json -d postman_value.json
[{
	"server_name":"reports_list",
	"email":"xiaoxiao@mail.com"
}]

指定输出结果 outputfile.json

$ newman run APITest.postman_collection.json -d postman_value.json --reporters cli,json --reporter-json-export outputfile.json

outputfile.json

{
  "collection": {
    "_": {
      "postman_id": "bdb00378"
    },
    "item": [
      {
        "id": "b06fdfgrtr",
        "name": "CustomTemplateList",
        "request": {
          "url": {
            "protocol": "https",
            "path": [
              "v1",
              "report",
              "list",
            ],
            "host": [
              "{{server_name}}"
            ],
            "query": [],
            "variable": []
          },
          "header": [
              "key": "email",
              "value": "{{email}}"
            }
          ],
          "method": "GET"
        },
        "response": [],
        "event": [
          {
            "listen": "test",
            "script": {
              "id": "3hhg67-fxdfg",
              "type": "text/javascript",
              "exec": [
                "pm.test(\"Status code is 200\", function(){",
                "    pm.response.to.have.status(200);",
                "});",
                "var jsonData=JSON.parse(responseBody);",
                "tests[\"Check response status value is 0\"] = jsonData.code===0;",
                "tests[\"Check response msg is success\"] = jsonData.msg===\"success\";"
              ],
              "_lastExecutionId": "608eb6b1-4e5b-4c5d-8e41-8f"
            }
          }
        ]
      },
  "environment": {
    "id": "d981313aeere4d-diodsi",
    "values": []
  },
  "globals": {
    "id": "72diur478-fdkhduf",
    "values": []
  },
  "run": {
    "stats": {
      "iterations": {
        "total": 1,
        "pending": 0,
        "failed": 0
      },
      "items": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "scripts": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "prerequests": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "requests": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "tests": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "assertions": {
        "total": 21,
        "pending": 0,
        "failed": 0
      },
      "testScripts": {
        "total": 7,
        "pending": 0,
        "failed": 0
      },
      "prerequestScripts": {
        "total": 0,
        "pending": 0,
        "failed": 0
      }
    },
    "timings": {
      "responseAverage": 34.142857142857146,
      "responseMin": 19,
      "responseMax": 114,
      "responseSd": 32.669026709139175,
      "dnsAverage": 0,
      "dnsMin": 0,
      "dnsMax": 0,
      "dnsSd": 0,
      "firstByteAverage": 0,
      "firstByteMin": 0,
      "firstByteMax": 0,
      "firstByteSd": 0,
      "started": 1631952565869,
      "completed": 1631952566793
    },
    "executions": [
      ...
    ],
    "transfers": {
      "responseTotal": 17062
    },
    "failures": [],
    "error": null
  }
}

newman其他Options

Utility

OptionDetails
-h,?--helpOutput usage information
-v,?--versionOutput the version number

Basic setup

OptionDetails
--folder [folderName]Specify a single folder to run from a collection.
-e,?--environment [file|URL]Specify a Postman environment as a JSON [file]
-d,?--iteration-data [file]Specify a data file to use either json or csv
-g,?--globals [file]Specify a Postman globals file as JSON [file]
-n,?--iteration-count [number]Define the number of iterations to run

Request options

OptionDetails
--delay-request [number]Specify a delay (in ms) between requests [number]
--timeout-request [number]Specify a request timeout (in ms) for a request

Misc.

OptionDetails
--bailStops the runner when a test case fails
--silentDisable terminal output
--color offDisable colored output (auto|on|off) (default: "auto")
-k,?--insecureDisable strict ssl
-x,?--suppress-exit-codeContinue running tests even after a failure, but exit with?code=0
--ignore-redirectsDisable automatic following of?3XX?responses
--verboseShow detailed information of collection run and each request sent

  开发测试 最新文章
pytest系列——allure之生成测试报告(Wind
某大厂软件测试岗一面笔试题+二面问答题面试
iperf 学习笔记
关于Python中使用selenium八大定位方法
【软件测试】为什么提升不了?8年测试总结再
软件测试复习
PHP笔记-Smarty模板引擎的使用
C++Test使用入门
【Java】单元测试
Net core 3.x 获取客户端地址
上一篇文章      下一篇文章      查看所有文章
加:2021-09-20 16:03:26  更:2021-09-20 16:03:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/18 0:32:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码